Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you shim a method with optional parameters? #53

Open
aeslinger0 opened this issue Aug 8, 2019 · 0 comments
Open

Can you shim a method with optional parameters? #53

aeslinger0 opened this issue Aug 8, 2019 · 0 comments

Comments

@aeslinger0
Copy link

aeslinger0 commented Aug 8, 2019

I have a method in another assembly that looks like this (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)
    ...

I'm trying to figure out how to shim this. This give me the error 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; });

This give me 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; });

And these variations give me 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; });

What is the proper syntax?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant