mardi 29 octobre 2019

Is it possible to mock a local method variable using NSubstitute?

E.g. I have a class with a Process method, in this method I set up a number of things e.g.

public class messageProcessor
{
...
  public string Process(string settings)
  {
    var elementFactory = new ElementFactory();
    var strategyToUse = new legacyStrategy();
    ...
    var resources = new messageResource(
       elementFactory,
       strategyToUse,
       ...);
  }
}

Is it possible for me to create an instance of this class but when I call the Process method, replace (for example) elementFactory to be set to my mocked factory.

Is that possible and how would I do it? Thanks

Aucun commentaire:

Enregistrer un commentaire