jeudi 5 mars 2015

Moq stubbing a return with chained methods and a System.xml.Document dependency

Working on stubbing out this return statement, but I have had a few issues with the document object. Getting "Can not instantiate proxy of class: System.Xml.XmlElement.Could not find a parameterless constructor." I've been trying to get around the document part a few different ways. Here is the production code snippet:



public Token getTokenXml()
{
//logic to create SecurityToken object

XmlDocument document = new XmlDocument();

return token.GetXml(document).OuterXml;
}


Test: Here I'm attempting to setup the mock for the chain of calls on the return from above. Putting the document object in the mock does not seem to work, so right around there is where I'm confused as to how I can stub that.



[TestMethod()]
public void generateSAMLTokenTest()
{
TestWebServiceImpl testWebServiceImpl = new TestWebServiceImpl();
SAMLGeneratorService samlGeneratorService = new SAMLGeneratorService(testWebServiceImpl);

var mock = new Mock<SecurityToken>("samlTest");
XmlDocument mockument = new XmlDocument();

//This Setup
mock.Setup(m => m.GetXml(mockument).OuterXml).Returns("test123");

string samlToken = samlGeneratorService.generateSAMLToken();
}

Aucun commentaire:

Enregistrer un commentaire