I'm trying to test a class that contains a method that returns an XmlNode. During my test, I need the mocked class to do it's original behavior, but afterwards I want to verify with which arguments it was called. As such, I do a WhenCalled.CallOriginal (so that Verify can be used afterwards) on the object and then perform the verify. However, since I used CallOriginal, I cannot verify (there's an exception about an abstract class). I have tested using WillReturn (instead of CallOriginal) and that works fine, but in my test case, I need to actually call the original.
Here's a code snippet that can reproduce the error:
[TestClass]
public class TestXmlNodeMethod
{
[TestMethod, Isolated]
public void TestThatSucceeds()
{
// ARRANGE
var expectedNode = this.GetNode();
Isolate.WhenCalled(() => this.GetNode()).WillReturn(expectedNode);
// ACT
var node = this.GetNode();
// ASSERT
Assert.AreEqual("<Root><Child></Root>", node.OuterXml);
Isolate.Verify.WasCalledWithAnyArguments(() => this.GetNode());
}
[TestMethod, Isolated]
public void TestThatFails()
{
// ARRANGE
Isolate.WhenCalled(() => this.GetNode()).CallOriginal();
// ACT
var node = this.GetNode();
// ASSERT
Assert.AreEqual("<Root><Child></Root>", node.OuterXml);
Isolate.Verify.WasCalledWithAnyArguments(() => this.GetNode());
}
public XmlNode GetNode()
{
var doc = new XmlDocument();
doc.LoadXml("<Root><Child></Root>");
return doc.DocumentElement;
}
}