对于下面给出的模拟对象,如何检查WashCar(ICar car)方法是否设置了TiresWashed属性?
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
}
答案 0 :(得分:8)
来自Here:
mock.AssertWasCalled(x => x.Name ="Bob");
或
mock.AssertWasCalled(x => x.Name =Arg.Is("Bob"));
或
mock.AssertWasCalled(x => x.Name =Arg<string>.Is.NotNull);
答案 1 :(得分:0)
在the_ajp的链接为:
后,我是如何设法完成的mockCar.AssertWasCalled(car => { var dummy = car.TiresWashed; }, options
=> options.SetPropertyWithArgument(Arg<object>.Is.Anything));