开发者

How can I check if a particular property setter is called on a Mock object?

开发者 https://www.devze.com 2023-04-12 09:54 出处:网络
F开发者_C百科or the given mock object below, how can I check if the WashCar(ICar car) method is setting the TiresWashed property?

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));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号