multiple parameters call back in Moq

做~自己de王妃 提交于 2019-12-03 05:28:54
user2388013

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());
}
Shaun Luttin

For each parameter that the method takes, pass a type parameter to the Callback method.

someMock
    .Protected()
    .Setup("SomeMethod", ItExpr.IsAny<string>(), ItExpr.IsAny<string>())
    .Callback<string, string>((x, y) => {});

The above works both with Protected and normal callbacks.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!