I wish to mock a "B" method that is called inside the method "A"
Here is an example
In the below example I want MapPath
to always return some "text" whenever it's being called.
Both are in different classes
public class TestTest
{
public virtual string Test1()
{
ServerPath IFilePath = new ServerPath();
string path = IFilePath.MapPath("folder", "filepath");
return path;
}
}
public class ServerPath
{
public virtual string MapPath(string folder, string filepath)
{
Console.WriteLine("ServerPath");
return (System.Web.Hosting.HostingEnvironment.MapPath(folder + filepath));
}
}
I want to mock in such a way that when there is call to MapPath
it should always returns "test25"
(Whether I should implement an interface?)
My TestCode:
//I am using FakeitEasy
TestTest TestClass = new TestTest();
var FakeServerPath = A.Fake<ServerPath>();
var FakeTestTest = A.Fake<TestTest>();
A.CallTo(() => FakeServerPath.MapPath(A<string>.Ignored, A<string>.Ignored)).Returns("test25");
//Should I call FakeTestTest.Test1() or TestClass.Test1() ?
Console.WriteLine(TestClass.Test1());