MessageBox.Show
is a static member, and cannot be faked by FakeItEasy. In these situations, typically the code that accesses the non-fakeable service is isolated and wrapped in an interface.
Here's how I would do it:
interface IAlerter
{
void Alert(string text, string caption);
}
public class XYZ
{
public static int nValue = 0;
private readonly IAlerter _alerter;
public XYZ(IAlerter alerter)
{
_alerter = alerter;
}
public void AddInetegers(int i)
{
int j = i * 100;
int k = j * 30 / 100;
_alerter.Show("Value Here {0}", k.ToString());
nValue = k;
}
}
[TestMethod]
public void Test_Using_FakeItEasy()
{
var alerter = A.Fake<IAlerter>();
// No need to configure alerter.Alert(), since it doesn't return a value
var xyz = new XYZ(alerter);
xyz.AddInetegers(3);
Assert.AreEqual(90, XYZ.nValue);
}