I am new to NSubstitute and trying to fake an existing class called OrgDataWS. This class has a method called "GetDataSet":
public XmlElement GetDataSet(int token)
{
string perfLogMessage = string.Format("Org.GetDataSet: {0}", Guid.NewGuid().ToString());
MultiMessagePerformanceCounter performanceCounter = MultiMessagePerformanceCounter.StartNew(perfLogMessage);
XmlElement result = orgDataManager.GetDataSet(token);
performanceCounter.Stop();
return result;
}
Following are my testing methods:
[TestMethod]
public void GetDataSetTest()
{
var dataWSStub = Substitute.For<OrgDataWS>();
var orgManagerStub = Substitute.For<OrgDataManager>();
var document = new XmlDocument();
var xmlElement = document.CreateElement("a");
orgManagerStub.GetDataSet(Arg.Any<int>()).Returns<XmlElement>(xmlElement);
dataWSStub.OrgDataManager = orgManagerStub;
var result = dataWSStub.GetDataSet(99);
}
However, when I run my testing methods, this line is "orgManagerStub.GetDataSet (Arg.Any ()). Returns (xmlElement);" threw an exception. This exception is due to the implementation of the "OrgDataManager" class, from my understanding, this should not happen. The purpose of using this sentence is that I hope that if the orgManagerStub DataDataSet method is called with any Int parameter, just return an xmlElement instance. I did not hope that my code would launch a detailed implementation of OrgDataManager.
? ? !