Hi all,
what I would like to do is that a method of any object returns always true, like in this this minimal code :
public class MyClass
{
public bool Verify()
{
MyClass2 myClass2 = new MyClass2();
return myClass2.Check();
}
}
public interface IMyInterface
{
bool Check();
}
public class MyClass2 : IMyInterface
{
public bool Check()
{
return false;
}
}
class Program
{
static void Main()
{
var fake = Isolate.Fake.Instance<IMyInterface>();
Isolate.WhenCalled(() => fake.Check()).WillReturn(true);
MyClass myClass = new MyClass();
// I would like that Verify() returns true everytime, so how could I fake the Check() method to return always true ?
Assert.AreEqual(true, myClass.Verify());
}
}
But this is not working.
I can't refactor the code to put a IMyInterface in the myclass constructor parameter (or as method parameter).
How should I do ?
Thanks for your help,
Best regards
Edit : I tryed this too :
var fake = Isolate.Fake.Instance<IMyInterface>();
Isolate.WhenCalled(() => fake.Check()).WillReturn(true);
Isolate.Swap.AllInstances<IMyInterface>().With(fake);
but this shouldn't be the good way