I have achieved a solution to mock test the public virtual method using FakeItEasy Framework. Below I have a Test class with Private method and private method cannot be virtual. So please help me t mock the Private method using FakeItEasy Framework
Class To be tested
public class XYZ
{
public static int nValue = 0;
private void AddInetegers()
{
int i = 3;
int j = i * 100;
int k = j * 30 / 100;
Show(String.Format("Value Here {0}", k.ToString()));
nValue = k;
}
public virtual void Show(string message)
{
MessageBox.Show(message);
}
}
Test Class
[TestMethod]
public void Test_Using_FakeItEasy()
{
var instance = A.Fake<XYZ>();
A.CallTo(() => instance.Show("Hello"));
//A.CallTo(() => instance.AddInetegers(3)).CallsBaseMethod();
A.CallTo(instance).Where(x => x.Method.Name.Contains("AddInetegers")).MustHaveHappened();
Assert.AreEqual(90, XYZ.nValue);
}
Error:
Result Message: Test method PrjMSTest.Test.Test_Using_FakeItEasy threw exception: FakeItEasy.ExpectationException:
Assertion failed for the following call:
Any call made to the fake object.
where x => x.Method.Name.Contains("AddInetegers")
Expected to find it at least once but no calls were made to the fake object.