【发布时间】:2014-01-03 09:05:07
【问题描述】:
我有一个财产。在我的单元测试中,我想确保不调用该集合。我怎样才能做到这一点?
我可以检查该值是否已设置,但我如何确保它未设置。
public ISomeInterface
{
bool? SomeProperty { get; set; }
}
public SomeClass
{
SomeClass(ISomeInterface someInterface)
{ _someInterface = someInterface; }
public void SomeMethod(bool condition)
{
if (condition)
_someInterface.SomeProperty = true;
}
}
// Test
var moq = new Mock<ISomeInterface>();
var target = new SomeClass(moq.Object);
target.SomeMethod(false);
// Check here that someInterface.SomeProperty set is not called.
moq.VerifySet(i => i.SomePropery = true); // This checks that set is called. But how to check if it is not called?
【问题讨论】:
-
哦,是的,谢谢,结束问题。
标签: c# unit-testing tdd moq