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

tomasaschan picture tomasaschan  路  3Comments

Ephasme picture Ephasme  路  3Comments

Accc99 picture Accc99  路  4Comments

mjfreelancing picture mjfreelancing  路  4Comments

malylemire1 picture malylemire1  路  7Comments