gpt4 book ai didi

c# - 如何检查是否在 Mock 对象上调用了特定的属性 setter ?

转载 作者:行者123 更新时间:2023-11-30 19:46:54 26 4
gpt4 key购买 nike

对于下面给定的模拟对象,我如何检查 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
}

最佳答案

来自 Here :

mock.AssertWasCalled(x => x.Name ="Bob");

mock.AssertWasCalled(x => x.Name =Arg.Is("Bob"));

mock.AssertWasCalled(x => x.Name =Arg<string>.Is.NotNull);

关于c# - 如何检查是否在 Mock 对象上调用了特定的属性 setter ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7725737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com