rhino-mocks

How to use the real parameters when creating a stub method in RhinoMocks?

◇◆丶佛笑我妖孽 提交于 2021-02-06 11:28:03
问题 I want to create a stub of the following interface: interface IUnitOfWork { void DoInTransaction(Action method); } In the stub object, all I want DoInTransaction to do is run method() . Something like: // pseudo-code unitOfWorkStub.Stub(x => x.DoInTransaction(method)).Do(method()) Is it possible to create this kind of a stub with RhinoMocks? How can this be done? 回答1: use this: unitOfWorkStub.Stub(x => x.DoInTransaction(Arg<Action>.Is.Anything)) .WhenCalled(x => ((Action)x.Arguments[0])());

How to use the real parameters when creating a stub method in RhinoMocks?

泄露秘密 提交于 2021-02-06 11:25:14
问题 I want to create a stub of the following interface: interface IUnitOfWork { void DoInTransaction(Action method); } In the stub object, all I want DoInTransaction to do is run method() . Something like: // pseudo-code unitOfWorkStub.Stub(x => x.DoInTransaction(method)).Do(method()) Is it possible to create this kind of a stub with RhinoMocks? How can this be done? 回答1: use this: unitOfWorkStub.Stub(x => x.DoInTransaction(Arg<Action>.Is.Anything)) .WhenCalled(x => ((Action)x.Arguments[0])());

How to use the real parameters when creating a stub method in RhinoMocks?

时间秒杀一切 提交于 2021-02-06 11:24:42
问题 I want to create a stub of the following interface: interface IUnitOfWork { void DoInTransaction(Action method); } In the stub object, all I want DoInTransaction to do is run method() . Something like: // pseudo-code unitOfWorkStub.Stub(x => x.DoInTransaction(method)).Do(method()) Is it possible to create this kind of a stub with RhinoMocks? How can this be done? 回答1: use this: unitOfWorkStub.Stub(x => x.DoInTransaction(Arg<Action>.Is.Anything)) .WhenCalled(x => ((Action)x.Arguments[0])());

Why I got this error message: Expected #1, Actual #0?

旧时模样 提交于 2021-01-28 20:00:51
问题 Why the following test code using Rhino Mocks raises this exception: Expected #1, Actual #0 ? int PRODUCT_ID = 1; [TestMethod] public void If_Cart_Already_Exists_Then_AddToBasket_Should_Use_It_ByCallingIShoppingCartGetCart() { ShoppingCart cart = new ShoppingCart(); //without UserName as ctor parameter IShoppingCartRepository shoppingCartRepository = MockRepository.GenerateMock<IShoppingCartRepository>(); shoppingCartRepository.Expect(r => r.GetCart()).Return(cart); ShoppingCartController c =

Rhino Mocks Exception Expect #1 Actual #0 : Need assistance

南笙酒味 提交于 2021-01-27 06:58:47
问题 I've have searched on this and it seems to be a catch all, unfortunately everything I've read doesn't help figure it out. Here is the class: public interface IMockInterface { MockClass MockedMethod(); MockClass MockThis(); } public class MockClass : IMockInterface { public virtual MockClass MockedMethod() { MockClass returnValue; returnValue = new MockClass(); returnValue.SomeMessage = "Not mocked"; return returnValue; } public MockClass MockThis() { MockClass mock; MockClass returnValue;

When does a mock object enter the replay state?

家住魔仙堡 提交于 2021-01-27 01:40:32
问题 When executing the second line of this code Rhino Mocks throws an InvalidOperationException with a message "This action is invalid when the mock object is in replay state" var mockScanner = MockRepository.GenerateMock<PortScanner>(null); mockScanner.Expect((scanner => { scanner.Scan(null, null); })); Stepping through the code in a debugger one can see the debugger run the method defined in the class and directly after control leaves this method the exception occurs. This similar code in

When does a mock object enter the replay state?

偶尔善良 提交于 2021-01-27 01:40:08
问题 When executing the second line of this code Rhino Mocks throws an InvalidOperationException with a message "This action is invalid when the mock object is in replay state" var mockScanner = MockRepository.GenerateMock<PortScanner>(null); mockScanner.Expect((scanner => { scanner.Scan(null, null); })); Stepping through the code in a debugger one can see the debugger run the method defined in the class and directly after control leaves this method the exception occurs. This similar code in

Rhino.Mocks produces InvalidCastException when returning polymorphic object

Deadly 提交于 2020-03-26 06:10:08
问题 I'm using Rhino.Mocks 3.6 for the first time. I'm trying to create a stub for an interface that returns an inherited type (B). When I try to do this, it will generate an InvalidCastException trying to convert some proxy object to the base class (A). For example: class A {} class B : A {} interface IMyInterface { A GetA(); } // Create a stub var mocks = new MockRepository(); var stub = mocks.Stub<IMyInterface>(); Expect.Call( stub.GetA() ).Return( new B() ); // This will throw an

Stub return value for all inputs in Rhino Mocks

谁说我不能喝 提交于 2020-01-15 05:53:32
问题 I am stubbing the return value of a method using rhino mocks. However, I want to return the same dummy value for any argument that is passed in. How do I do this without pre-registering every input to return the same output? 回答1: _testHelper is helper class where you are returning a dummy value from GetMethodValue(). you have to write GetMethodValue() in your _testHelper class. SetupResult.For(_Repository.MethodName(null)).IgnoreArguments().Return(_testHelper.GetMethodNameResultValue()); 回答2:

Stub return value for all inputs in Rhino Mocks

南笙酒味 提交于 2020-01-15 05:53:05
问题 I am stubbing the return value of a method using rhino mocks. However, I want to return the same dummy value for any argument that is passed in. How do I do this without pre-registering every input to return the same output? 回答1: _testHelper is helper class where you are returning a dummy value from GetMethodValue(). you have to write GetMethodValue() in your _testHelper class. SetupResult.For(_Repository.MethodName(null)).IgnoreArguments().Return(_testHelper.GetMethodNameResultValue()); 回答2: