tags:

views:

27

answers:

1

Hi,

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?

+3  A: 

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 of List<customers>.

Expectations setups basically perform an object.Equals operation 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.

Mark Seemann
ok thanks.I decided to split the test into 2 - one an interaction test, method was called.And, another test for the service method
junky_user