How do you bypass a WebOperationContext object equal to null in a WCF service method when testing a method using NUnit
I have a unit test project using NUnit to verify the data returned by the WCF method:
public class SampleService { public XmlDocument Init () { WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml"; return _defaultInitializationXMLfile; } }
Then I have a test method as follows
[TextFixture] public class SampleServiceUnitTest { [Test] public void DefaultInitializationUnitTest { SampleService sampleService = new SampleService(); XMLDocument xmlDoc = sampleService.Init(); XMLNode xmlNode = xmlDoc.SelectSingleNode("defaultNode"); Assert.IsNotNull(xmlNode, "the default XML element does not exist."); } }
However, during the test I get an error
SampleServiceUnitTest.DefaultInitializationUnitTest: System.NullReferenceException : Object reference not set to an instance of an object.
relative to WebOperationContext in the SampleService method.
source share