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

Treat delegates as substitutes with NSubstitute #1027

Closed
gtbuchanan opened this issue Apr 26, 2018 · 3 comments
Closed

Treat delegates as substitutes with NSubstitute #1027

gtbuchanan opened this issue Apr 26, 2018 · 3 comments
Labels

Comments

@gtbuchanan
Copy link

gtbuchanan commented Apr 26, 2018

NSubstitute supports substituting delegates. However, delegates are not resolved as substitutes when using a fixture with the NSubstitute customization. Therefore, I can't run any NSubstitute assertions on them.

[Test]
public void ActionIsSubstitute()
{
    var fixture = new Fixture().Customize(new AutoNSubstituteCustomization());

    var action = fixture.Create<Action>();

    Assert.That(action.DidNotReceive, Throws.Nothing);
}

Fails with:

Expected: No Exception to be thrown
But was: <NSubstitute.Exceptions.NotASubstituteException: NSubstitute extension methods like .Received() can only be called on objects created using Substitute.For() and related methods.

Similar to #984.

@gtbuchanan
Copy link
Author

I just realized the property GenerateDelegates already exists on AutoNSubstituteCustomization. Setting that to true resolved my issue. My apologies. I'm new to AutoFixture and couldn't find any documentation on this. Should have checked after I saw how it was resolved for the other issue.

@zvirja
Copy link
Member

zvirja commented Apr 26, 2018

Yep, you're completely right in your finding 😊

One day we'll create a nice doc site and you'll be able to find this information there 😅

@Kralizek
Copy link
Contributor

Kralizek commented Apr 26, 2018

One day we'll create a nice doc site and you'll be able to find this information there 😅

Me at the standup meeting at work!

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

No branches or pull requests

3 participants