I need some assistance with writing a unit test for the following class using Rhino Mocks 3.5. The following overrided method in my class:
public override void Initialize(params object[] messages)
{
var data = new ViewData
{
Name = this.GetName()
};
this.Notify(data);
}
I want to be write a test to validate that when the Initialize method is called, the method calls the Notify method and has a parameter of type ViewData. Also I want to check that the GetName method which is a private method is called within this method. I use an accessor to access the GetName private method.
Any help would be great with this as I am new to writing tests and need assistance.
What you want is called a partial mock.
[Test]
public void UsingPartialMocks()
{
MockRepository mocks = new MockRepository();
YourClass partialMock = mocks.PartialMock<YourClass>();
Expect.Call(partialMock.Notify(null)).IgnoreArguments();
mocks.ReplayAll();
partialMock.Initialize(null);
mocks.VerifyAll();
}