相关疑难解决方法(0)

Moq调用未在模拟上执行

试图理解verifySet等的使用......但除非我做一个解决方法,否则我无法让它工作.

public interface IProduct
{
    int  Id { get; set; }
    string Name { get; set; }
}


public void Can_do_something()
{
    var newProduct = new Mock<IProduct>();
    newProduct.SetupGet(p => p.Id).Returns(1);
    newProduct.SetupGet(p => p.Name).Returns("Jo");

    //This fails!! why is it because I have not invoked it
    newProduct.VerifySet(p => p.Name, Times.AtLeastOnce());

    //if I do this it works
    newProduct.Object.Name = "Jo";
    newProduct.VerifySet(p => p.Name, Times.AtLeastOnce());
 }
Run Code Online (Sandbox Code Playgroud)

有人可以澄清我应该如何在属性上使用VerifySet和Verify和VerifyGet?我很困惑.

unit-testing moq mocking

5
推荐指数
1
解决办法
3220
查看次数

标签 统计

mocking ×1

moq ×1

unit-testing ×1