Moq中的多个参数回调

Moq中的多个参数回调

本文介绍了Moq中的多个参数回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以看看下面的代码,看看有什么问题吗?

Can someone please look at the code below and see what's wrong?

[TestInitialize]
public void SetupMockRepository()
{
    var memberId = "34345235435354545345";
    var title = "test";
    var url = "dafdsfdsfdsfdsafd";

    _mockPropertySearchRepository = new Mock<IPropertySearchRepository>(MockBehavior.Strict);
    _mockPropertySearchRepository
        .Setup(p => p.SaveSearchURL(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
            .Callback<string,string,string>((id,t,u) =>  )
            .Returns(new SavedSearchReturnResult() );

}

谢谢

推荐答案

我设法自己解决了以下问题

I managed to solve the problem myself as below

[TestInitialize]
public void SetupMockRepository()
{
    var memberId = "34345235435354545345";
    var title = "test";
    var url = "dafdsfdsfdsfdsafd";


    _mockPropertySearchRepository = new Mock<IPropertySearchRepository>(MockBehavior.Strict);
    _mockPropertySearchRepository
        .Setup(p => p.SaveSearchURL(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
        .Callback<string,string,string>(
            (id, t, u) =>
            {
                memberId = id;
                title = t;
                url = u;
            })
        .Returns(new SavedSearchReturnResult());
}

这篇关于Moq中的多个参数回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 01:56