0

我只是在做一个起订量单元测试,如下所示。

由于设置无效,测试失败。

谁能告诉我为什么设置错误?

    [TestInitialize]
    public void SetupMockRepository()
    {
        _mockPropertySearchRepository = new Mock<IPropertySearchRepository>(MockBehavior.Strict);
        var linkIdHash = new PropertyIdLinkIdHash() { CountryCode = "AU", LinkIdHash = "4567890", PropertyId = "5234526" };
        //Get details
        _mockPropertySearchRepository.Setup(mq => mq.GetPropertyDetails(It.Is<PropertyIdLinkIdHash>(p => p == linkIdHash))).Returns(new Roots());

        this.MockPropertySearchRepository = _mockPropertySearchRepository.Object;

    }

    /// <summary>
    /// Testing object pattern
    /// </summary>
    [TestMethod]
    public void Can_Get_Property_Details_AU()
    {
        var linkIdHash = new PropertyIdLinkIdHash() { CountryCode = "AU", LinkIdHash = "4567890", PropertyId = "5234526" };
        var result = MockContext.GetPropertyDetails(linkIdHash);

        Assert.IsNotNull(result);      
    }
}

谢谢

4

1 回答 1

0

我自己解决了如下。

   [TestInitialize]
    public void SetupMockRepository()
    {
        var linkIdHash = new PropertyIdLinkIdHash() { CountryCode = "AU", LinkIdHash = "4567890", PropertyId = "5234526" };
        var root = GetPropertyDetails();
        _mockPropertySearchRepository = new Mock<IPropertySearchRepository>(MockBehavior.Strict);
        _mockPropertySearchRepository.Setup(c => c.GetPropertyDetails(It.IsAny<PropertyIdLinkIdHash>()))
                .Callback<PropertyIdLinkIdHash>((obj) => linkIdHash = obj)
                .Returns(new Roots()
                {

                }

                );

        this.MockPropertySearchRepository = _mockPropertySearchRepository.Object;
    }
于 2013-09-05T02:03:21.067 回答