如何扩展Moq以支持模拟具有16个以上参数的方法

时间:2018-06-29 19:59:31

标签: moq

执行以下操作

mock
    .Setup(m => m.CreateMyObject(
        It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
        It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(),
        It.IsAny<string>(), It.IsAny<string>(), It.IsAny<AnEnum>(),
        It.IsAny<DateTimeOffset>(), It.IsAny<DateTimeOffset>(),
        It.IsAny<Logger>(), It.IsAny<HashSet<string>>(),
        It.IsAny<HashSet<string>>(), It.IsAny<bool>(),
        It.IsAny<bool>(), It.IsAny<bool>(),
        It.IsAny<Dictionary<string, string>>(),
        It.IsAny<bool>()))
    .ReturnsAsync(
        (string str1, string str2, string str3, string str4, string str5,
         string str6, string str7, string str8, AnEnum enum1,
         DateTimeOffset dateTime1, DateTimeOffset dateTime2, Logger logger,
         HashSet<string> stringHash1, HashSet<string> stringHash2,
         bool bool1, bool bool2, bool bool3,
         Dictionary<string, string> dict1, bool bool4) =>
         new MyObject() { Str1 = str1}
     );

Cannot convert lambda expression to type 'MyObject' because it is not a delegate type中的结果 经过研究后,您可以模拟的参数数量似乎受到限制(16)。我找到了一些旧文章,这些文章讨论了如何扩展Moq以支持带有更多参数的回调,但是我想返回一个值,而不仅仅是调用回调。我只是勉强了解扩展方法,无法弄清楚如何扩展IReturnsResult或IReturns以支持更多参数。

0 个答案:

没有答案