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

Constructor with params array triggers NS2002 and NS2004 on For and ForPartsOf #162

Closed
lonix1 opened this issue Aug 16, 2021 · 2 comments · Fixed by #167
Closed

Constructor with params array triggers NS2002 and NS2004 on For and ForPartsOf #162

lonix1 opened this issue Aug 16, 2021 · 2 comments · Fixed by #167
Labels
bug Something isn't working
Milestone

Comments

@lonix1
Copy link

lonix1 commented Aug 16, 2021

Both For<>() and ForPartsOf<>() choke when a type's constructor contains a params array.

public class Foo {
  public Foo(string s, params object[] args) { }
}

public class FooTests {
  [Fact]
  public void TestConstructor() {
    Substitute.For<Foo>("hello");                     // NS2002
    Substitute.For<Foo>("hello", 10, true);           // NS2002
    Substitute.ForPartsOf<Foo>("hello");              // NS2002
    Substitute.ForPartsOf<Foo>("hello", 10, true);    // NS2002

    Substitute.For<Foo>("hello", 10);                 // NS2004
    Substitute.ForPartsOf<Foo>("hello", 10);          // NS2004
  }
}

NS2002:

The number of arguments passed to NSubstitute.Substitute.For do not match the number of constructor arguments for Foo. Check the constructors for Foo and make sure you have passed the required number of arguments. [MyProject.Tests]csharp(NS2002)

NS2004:

Arguments passed to NSubstitute.Substitute.ForPartsOf do not match the constructor arguments for Foo. Check the constructors for Foo and make sure you have passed the required arguments and argument types. [MyProject.Tests]csharp(NS2004)

@tpodolak tpodolak added the bug Something isn't working label Aug 27, 2021
@lonix1
Copy link
Author

lonix1 commented Sep 5, 2021

Hey @tpodolak / @dtchepak thanks for fixing this!

I noticed that the last release was almost a year ago. Any plans to push this to nuget?

@tpodolak
Copy link
Member

tpodolak commented Sep 5, 2021

Yes, we will release new version as soon as #160 and #159 is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants