I was trying to figure out how to verify that a method is called within a constructor. So far, I have not been able to get it to work. Here is an example of the code and the unit test:
public class ConfigData
{
public ConfigData(string fileName)
{
XmlDocument document = new XmlDocument();
// document.Load(fileName); - commented out so file not needed
ProcessFile(document);
}
private void ProcessFile(XmlDocument doc)
{
// Code to process XML file
}
}
...
[TestClass]
public class MyTestClass
{
[TestMethod]
public void TestConfigData()
{
ConfigData configBase =
Isolate.Fake.Instance<ConfigData>(Members.MustSpecifyReturnValues,
ConstructorWillBe.Called, "Config.xml");
Isolate.Verify.NonPublic.WasCalled(configBase, "ProcessFile");
}
}
My gut reaction is that this fails because a method cannot be faked without the object first being created. Since the method call I want to verify is in the constructor, the constructor is called prior to the default behavior for members being established. If that is indeed the case, then calling the constructor during creation of a fake object would mean that the original implementations would be used for any methods called from within the constructor. It would make the most sense if the default behavior for members was established prior to calling the constructor.
I am hoping that I am just missing something obvious here.
Thanks,
Brian