rhino-mocks

Testing Bus.Send in an application using NServiceBus

I have this code in my app .NET application using NServiceBus: Bus.Send<IServiceStarted>(e => { e.ServiceInfo = ReadServiceInfo(); e.EventTime = DateProvider.Now; }); How would you go about unit-testing such a...

RhinoMocks Types

Folks How to Exposte RhinoMock Objects as properties I am trying following code snippet internal class Mocks { private MockRepository.GenerateMock<IFormsAuthentication> formsAuthentication; } but its now working for me anyone know How to do this with rhinomocks ...

Why does Rhino Mocks error on a stub, but not on the exact same thing as a mock?

I'm fairly new to rhino Mocks, just started using it this project. I am testing some code which calls an external method to get an IEnumerable of 'Project', which I've got an interface for it so that I can stub/mock it out. at the start of my unit test that tests some of the code that iterates over (or calls Count(), both cause the e...

Rhino Mocks Restub function

Sometimes I stub dependencies in test class setup and then want to restub some of them in concrete test. But Rhino mocks remembers only the first stub value and it is a bit inconvenient. someStub.Stub(x => x.SomeMethod(1)).Return(100); var value1 = someStub.SomeMethod(1); someStub.Stub(x => x.SomeMethod(1)).Return(200); var value2 = som...

How do I test an abstract class's protected abstract method?

I've been working on the best way to test an abstract class named TabsActionFilter. I've guranteed that classes that inherit from TabsActionFilter will have a method called GetCustomer. In practice this design seems to work well. Where I've had some issues is figuring out how to test the OnActionExecuted method of the base class. This m...

How to mock extension methods with Rhino Mock?

I have extended objects of type IDataReader with some extension methods that I needed. The problem is now when I try to mock the IDataReader, the extended method is not included in the mock so when the row Expect.Call(reader.ExtensionMethod()).Return(someValue) is reach the ExtensionMethod is executed which is not what I want! I want tha...

How do I Raise an Event using Rhino Mocks that has a ref bool parameter

I am trying to write a test that covers my error handling in a particular class. This class is listening for an Error event with the following signature: OnError(int ErrorNumber, string ErrorText, ref bool retry) The problem is with the ref bool variable at the end. I am using Rhino Mocks to create a mock interface for testing and w...

Reusing a verified Mock

I am doing ordered expectations in rhino mocks as described by ayende in this post. My code looks something like this: using (_mocks.Ordered()) { Expect.Call(() => _myMock.CallA()); Expect.Call(() => _myMock.CallB(40)); Expect.Call(() => _myMock.CallA()); } _mocks.ReplayAll(); _myObjectUnderTest.DoStuff(); _mocks.V...

Rhino Mock OfType<>

Hi, Im trying to test this statement IStudentAssessmentUnitStatus res = student.UnitStatusList.OfType<IStudentAssessmentUnitStatus>(). FirstOrDefault(s => s.ID == unit.ID); Inside the list there could be multiple types hence the OfType. However when testi...

Mocking collections with Rhino Mocks

So this is something I guess many people want to do, mock a collection. In the past with Rhino I have done this with something like: var col_mock = MockRepository.GenerateMock<ICustomCollection>(); // returns ICustom let's say List<ICustom> col_real = new List<ICustom>(); col_real.Add(custom_mock1); col_real.Add(custom_mock2); col_real...