使用Pose使用可选参数填充方法的正确语法是什么?

时间:2019-08-08 19:14:47

标签: c# pose

我正在尝试使用https://github.com/tonerdo/pose。我在另一个程序集中有一个看起来像这样的方法(VB.NET):

    Public Class Item Parent
        Public Function GetItems(
            ByVal Optional a As Integer = 0,
            ByVal Optional b As Integer = 0,
            ByVal Optional c As Integer = 0,
            ByVal Optional d As Integer = 0) As List(Of Item)
    ...

我正在尝试找出如何对此进行匀场。这给我错误An expression tree may not contain a call or invocation that uses optional arguments

    var mockItems = new List<Item>();
    Shim.Replace(() => Is.A<ItemParent>().GetItems())
        .With(delegate (ItemParent@this) { return mockItems; });

这给了我Pose.Exceptions.InvalidShimSignatureException: Mismatched instance types

    var mockItems = new List<Item>();
    Shim.Replace(() => Is.A<ItemParent>().GetItems(Is.A<int>(), Is.A<int>(), Is.A<int>(), Is.A<int>()))
        .With(delegate () { return mockItems; });

这些变化给了我Pose.Exceptions.InvalidShimSignatureException: Parameters count do not match

    var mockItems = new List<Item>();
    Shim.Replace(() => Is.A<ItemParent>().GetItems(Is.A<int>(), Is.A<int>(), Is.A<int>(), Is.A<int>()))
        .With(delegate (ItemParent@this) { return mockItems; });

    var mockItems = new List<Item>();
    Shim.Replace(() => Is.A<ItemParent>().GetItems(Is.A<int>(), Is.A<int>(), Is.A<int>(), Is.A<int>()))
        .With(delegate (ItemParent@this, int a, int b, int c, int d) { return mockItems; });

正确的语法是什么?

0 个答案:

没有答案
相关问题