vendredi 22 juillet 2016

Nsubstitute: Received checks wrong method

I have a test, where NSubstitute checks the wrong call at a fake class. When I do the test like the following code, the Received(...) method checks, that the value factory.featureClassName is returned once.

[Test]
public void CreateDataController_WhenCalled_CreatesServiceSettings()
{
    var factory = Substitute.ForPartsOf<AbstractDataServiceFactoryFake>("fileName");

    factory.CreateDataController();

    factory.Received(1).CreateServiceSettings("fileName", factory.FeatureClassName);
}

To test (like intended) that the method CreateServiceSettings(...) is called once I have to use the following code:

[Test]
public void CreateDataController_WhenCalled_CreatesServiceSettings()
{
    var factory = Substitute.ForPartsOf<AbstractDataServiceFactoryFake>("fileName");
    var featureClassName = factory.FeatureClassName;

    factory.CreateDataController();

    factory.Received(1).CreateServiceSettings("fileName", featureClassName);
}

It seems, that the Recieved() method is not directly connected to the method given after the call. Can anybody explain me, why this is happening?

Aucun commentaire:

Enregistrer un commentaire