Tag: rhino mocks

什么是等效于在Rhino Mocks中使用Ordered()的AAA语法

我无法为我的生活找到使用Rhino中的Fluent / AAA语法来validation操作顺序的正确语法。 我知道如何使用旧的学校记录/播放语法执行此操作: MockRepository repository = new MockRepository(); using (repository.Ordered()) { // set some ordered expectations } using (repository.Playback()) { // test } 任何人都可以告诉我在Rhino Mocks的AAA语法中与此相当的是什么。 如果你能指点我的一些文件,那就更好了。

有没有人在.NET中成功模拟过Socket类?

我试图在C#中模拟出System.net.Sockets.Socket类 – 我尝试使用NUnit模拟但它不能模拟具体的类。 我也尝试过使用Rhino Mocks但它似乎使用了该类的真实版本,因为它在调用Send(byte [])时抛出了SocketException。 有没有人使用任何模拟框架成功创建和使用Socket模拟?

如何使用Rhino Mock模拟扩展方法?

我有扩展IDataReader类型的对象,我需要一些扩展方法。 问题是现在当我尝试模拟IDataReader时,扩展方法不包含在mock中,所以当行Expect.Call(reader.ExtensionMethod()).Return(someValue)到达ExtensionMethod执行哪不是什么我想要! 我希望该调用是记录,当扩展方法从其他地方调用时,我希望它返回someValue 。 有谁知道怎么解决这个问题?

无法让RhinoMocks发出遵循generics类型限制规则的模拟

所以,使用NUnit和RhinoMocks: //Defines basic behavior of all persistable domain objects public interface IDomainObject {…} //defines domain objects specific to the Security DB public interface ISecurityDomainObject : IDomainObject {…} //Defines a basic transactional data Repository; there are multiple implementors //which each close TRest to the interface that defines their DB’s domain classes public interface IRepository : IDisposable […]

我可以在Rhino-Mocks 3.6中使用AAA语法测试方法调用顺序吗?

如果Method1在Rhino-mocks 3.6中调用1st,然后调用After后面的Method2,然后使用AAA语法调用Method3,是否可以测试以下示例? // Assert var mock = MockRepository.GenerateMock(); // Act myObject.Service = mock; // How should I change this part to ensure that Rhino Mocks check the call order as well? mock.AssertWasCalled(m=>m.Method1()); mock.AssertWasCalled(m=>m.Method2()); mock.AssertWasCalled(m=>m.Method3());

Rhino Mocks – 如果调用方法,则设置属性

如果调用方法,有没有办法让Rhino Mocks设置Stub的属性。 这样的事情:(粗体假代码) callMonitor.Expect(X => x.HangUp())。 SetProperty(callMonitor.InACall = false) ; HangUp方法返回void,我无法真正改变它。 但是我希望我的存根知道在调用HangUp时挂断了呼叫。

如何模拟静态单例?

我有一些课程,我被要求添加一些unit testing与Rhino Mocks并有一些问题。 首先,我知道RhinoMocks不允许嘲笑静态成员。 我正在寻找我的选择(除了使用TypeMock)。 我所拥有的类的示例与以下类似: class Example1 : ISomeInterface { private static ISomeInterface _instance; private Example1() { // set properties via private static methods } static Example1() { _instance = new Example1(); } public static ISomeInterface Instance() { get { return _instance; } } // Instance properties // Other Instance Properties that represent objects […]

Rhino Mocks AAA快速入门?

我一直在寻找有关使用Rhino Mocks 3.5+和AAA语法的一些不错的信息。 我发现很多博客都混合了旧的和新的东西,似乎更难以弄清楚如何使用它。 如果有一个像早期版本那样的Rhino Mocks AAA Cheat Sheet,那将会很棒。 您是否需要了解有关旧版Rhino的所有内容才能真正使用新版本? 我敢肯定,如果我是专家,我会喜欢Rhino的所有function,但现在我只是在游泳信息。 任何指针或良好的链接将完全赞赏!

如何改变存根的行为?

我可以在运行时更改存根的行为吗? 就像是: public interface IFoo { string GetBar(); } [TestMethod] public void TestRhino() { var fi = MockRepository.GenerateStub(); fi.Stub(x => x.GetBar()).Return(“A”); Assert.AreEqual(“A”, fi.GetBar()); fi.Stub(x => x.GetBar()).Return(“B”); Assert.AreEqual(“B”, fi.GetBar()); // Currently fails here } 我的代码示例在给定行中仍然失败, fi.GetBar()仍然返回”A” 。 或者是否有另一种技巧来模拟其行为随时间变化的存根? 我宁愿不使用fi.Stub(…).Do(…) 。 啊,可能我只是需要硬拷贝的精美手册让某人用它击中我的头部。 它看起来应该很明显,但我找不到它。

模拟DataReader并获取Rhino.Mocks.Exceptions.ExpectationViolationException:IDisposable.Dispose(); 期望#0,实际#1

我正在尝试模拟一个SqlDataReader SqlDataReader reader = mocks.CreateMock(); Expect.Call(reader.Read()).Return(true).Repeat.Times(1); Expect.Call(reader.Read()).Return(false); Expect.Call(reader.HasRows).Return(true); Expect.Call(reader.Dispose); Expect.Call(reader[“City”]).Return(“Boise”); Expect.Call(reader[“State”]).Return(“State”); Expect.Call(reader[“LAT”]).Return(100); Expect.Call(reader[“LON”]).Return(-100); mocks.ReplayAll(); 但我一直得到一个Rhino.Mocks.Exceptions.ExpectationViolationException:IDisposable.Dispose(); 在我的方法中预期#0,实际#1错误 using (reader) { if (reader.HasRows) { while (reader.Read()) { CityState myCity = new CityState { City = reader[“City”].ToString(), State = reader[“State”].ToString(), Lat = Convert.ToInt32(reader[“LAT”]), Lon = Convert.ToInt32(reader[“LON”]) }; myCities.Add(myCity); } } } 我错过了什么吗?