jeudi 21 mai 2015

How to Stub the XMLDocument in VS 2013 using Microsfot Fakes

I have the below TestMethod I am testing with VS 2013 and I am using Microsoft Fakes.

    [TestMethod]        
    public void ConstructorTestForCMAClass()
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<add name=\"console\" type=\"System.Diagnostics.DefaultTraceCMA\" value=\"Error\"/>");
        XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;
        CMATracer cMATracer = new CMATracer(attrColl);            
    }

For the above TestMethod If i have to use Stub, how should it be modfied and will that be a good practice to use the stub instead of XMLDocument ?

I have tried this but not sure if this is suffice or not.

          StubXmlDocument stubXmlDocument = new StubXmlDocument();
          stubXmlDocument.LoadXml("<add name=\"console\" type=\"System.Diagnostics.DefaultTraceCMA\" value=\"Error\"/>");
          //create a stub attribute collection
          XmlAttributeCollection attrCollection = stubXmlDocument.DocumentElement.Attributes;
          CMATracer cMATracer = new CMATracer(attrColl);  

Aucun commentaire:

Enregistrer un commentaire