I am testing a class that has a method which is private and is internally called from a public method. I want to be able to fake this test method so that the actual method is never called.
public class Service
{
public int MethodA(int a)
{
SaveToDB(a);
if (validate())
{
return a * 5;
}
else
{
return 0;
}
}
private bool validate(int a)
{
if (a > 100)
return true;
else
return false;
}
private bool SaveToDB()
{
// some logic to save to the database..
return true;
}
}
[FixtureTest]
public ServiceTest
{
//assuming we are using nunit and fakeiteasy..
[Test]
public void MethodA_Should_Return_Zero_when_Provided_100()
{
var fakeService = new Service;
var result = fakeservice.MethodA(101);
// I want to avoid the call SaveToDB() in the test how do I go about doing this..
//if this was a public method I could create a test stub and test like with a statement like
A.call(() => ServiceA.SaveToDB().Return())
// however this is a private function what should I do???
}
}