Interface IView
{
List<string> Names {get; set;}
}
public class Presenter
{
public List<string> GetNames(IView view)
{
return view.Names;
}
}
var mockView = MockRepository.GenerateMock<IView>();
var presenter = new Presenter();
var names = new List<string> {"Test", "Test1"};
mockView.Expect(v => v.Names).Return(names);
Assert.AreEqual(names, presenter.GetNames(mockView)) // Here presenter returns null which is incorrect behaviour in my case;
When I use the above code to return the mock list of names ,it doesn't match the expecatation then returns null and fails
thanks for your help
Edit:
I am passing the view as the paramter to presenter's GetNames method.Here the problem is when i return list object from the mocked property it returns null. However when i change the property data type to string/int i.e.premitive type then value is returned correctly
Best Answer
I don't see anywhere where your mockView is getting attached to your presenter. So from the presenter's point of view, the view is null. You might have to do something like:
I just coded this with NUnit and RhinoMocks 3.5 to make sure it works. Here's my two class files. The test passed.
I can only guess you are doing something wrong with the way you've mixed up your code.