0

I am new to NSubstitute and have previously worked with Moq. I want to call a function with any arguments and return an object that I create with any constructor args except one that I want to set.

In Moq i can write this:

new TestObject(It.IsAny<string>(), It.IsAny<bool>(), aValueIWantToControle)

In NSubstistute I tried:

var mySubstitute = Substitute.For<IMySubstitute>();

mySubstitute.DoSomething(Arg.Any<bool>(), Arg.Any<string>())
    .Returns(new TestObject(Substitute.For<string>(), Substitute.For<bool>(), aValueIWantToControle));

How can i create an object like this in NSubstitute?

EdwardB
  • 76
  • 1
  • 6

1 Answers1

2

NSubstitute doesn't have any special support for constructor arguments. I think something like the following would work for this case:

var mySubstitute = Substitute.For<IMySubstitute>();

mySubstitute.DoSomething(Arg.Any<bool>(), Arg.Any<string>())
    .Returns(new TestObject(default(string), default(bool), aValueIWantToControle));
David Tchepak
  • 9,826
  • 2
  • 56
  • 68