In a method in presenter,I expect a method of view to be called.This method is also passed data extracted from a service method(which is not mocked).This service method basically gets data from database and returns List(using LINQ to SQL).Now, when I write this in the test
List<customers> cus = expecteddata;
view.AssertWasCalled(v => v.InitializeCustomersForSelectedCity(cus));
Rhino.Mocks.Exceptions.ExpectationViolationException: ICustomerListView.InitializeCustomersForSelectedCity(System.Collections.Generic.List`1[DAL.Customer]); Expected #1, Actual #0.
The code which I am testing in presenter
public void HandleSelectedCity(int City)
{
selectedCity = City ;
_custometListForm.InitializeCustomersForSelectedCity(_CustomerListService.GetActiveCustomersForSelectedCity(selectedCity));
}
When I ignore arguments, test works fine
What could be the issue?
You assertion creates an expectation based on
cus, a variable defined in the unit test. However, when InitializeCustomersForSelectedCity is invoked, it’s being invoked with the result of GetActiveCustomersForSelectedCity – a different instance ofList<customers>.Expectations setups basically perform an
object.Equalsoperation on the expected instance and the actual instance. In your case, they are different, and the expectaction is not satisfied.Either you need to loosen your expectation to accept any
List<customers>, or you need to mock GetActiveCustomersForSelectedCity as well so that you can define the returned result from the unit test.