How can I check if a particular property setter is called on a Mock object?
F开发者_C百科or the given mock object below, how can I check if the WashCar(ICar car) method is setting the TiresWashed property?
public interface ICar
{
string Model {get;set;}
bool TiresWashed {get; set;}
bool WindowsWashed {get; set; }
}
[TestMethod]
public vouid MyUnitTest()
{
ICar mockCar = MockRepository.GenerateMock<ICar>();
CarServiceUtility.WashCar(mockCar);
//Assert if PrepareCar method is called: (this is why I had mock)
mockCar.AssertWasCalled(c=>c.PrepareCar());
//TODO
// Assert if mockCar.TiresWashed is set with any value
}
From Here:
mock.AssertWasCalled(x => x.Name ="Bob");
or
mock.AssertWasCalled(x => x.Name =Arg.Is("Bob"));
or
mock.AssertWasCalled(x => x.Name =Arg<string>.Is.NotNull);
How I managed to do it after the_ajp's link is:
mockCar.AssertWasCalled(car => { var dummy = car.TiresWashed; }, options
=> options.SetPropertyWithArgument(Arg<object>.Is.Anything));
精彩评论