moq没有返回我在mock.Setup中定义的内容

时间:2014-12-31 17:46:52

标签: c# moq

我正在使用Moq在c#中模拟一个函数。

 public void Mapper_GetProductMappingTest()
    {
        //Arrange:
        Mapping mapping= new Mapping()
        {
            code = "AB"
        };
        Mapper mapper = new Mapper(new MongoStore());

        CaseProduct caseProduct = new CaseProduct()
        {
            ProductID = "ABC",

        };
        Mock<Mapper> mock = new Mock<Mapper>(new MongoStore());
        mock.Setup(x => x.GetMapping(caseProduct)).Returns(mapping);
        // why does it return the caseproduct not the mapping?!
        var mapped = mock.Object.GetMapping(caseProduct);
        Assert.IsTrue(mapped.code == "AB");

此Assert.IsTrue失败,mock.Object.GetMapping(caseProduct)返回ABC而不是AB。 有人可以帮我吗?

0 个答案:

没有答案