如何检查 Mock 对象是否调用了特定的属性设置器?
对于下面给定的模拟对象,如何检查 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
}
For 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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自此处:
或
或
From Here:
or
or
在 the_ajp 的链接之后我是如何做到的:
How I managed to do it after the_ajp's link is: