Autofixture: Treat delegates as substitutes with NSubstitute

Created on 26 Apr 2018  ·  3Comments  ·  Source: AutoFixture/AutoFixture

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: () and related methods.

Similar to #984.

question

Most helpful comment

Yep, you're completely right in your finding :blush:

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

All 3 comments

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.

Yep, you're completely right in your finding :blush:

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

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Eldar1205 picture Eldar1205  ·  5Comments

JoshKeegan picture JoshKeegan  ·  6Comments

Ridermansb picture Ridermansb  ·  4Comments

josh-degraw picture josh-degraw  ·  4Comments

DeafLight picture DeafLight  ·  5Comments