Làm thế nào để bạn có được xung quanh WebOperationContext là null trong một phương pháp dịch vụ WCF khi thử nghiệm các phương pháp sử dụng NUnitphương pháp với Nunit nhưng WebOperationContext Testing WCF là null
tôi có một dự án thử nghiệm đơn vị sử dụng NUnit để kiểm tra dữ liệu trả về bởi một WCF Phương pháp:
public class SampleService
{
public XmlDocument Init()
{
WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
return _defaultInitializationXMLfile;
}
}
sau đó, tôi có một phương pháp thử như sau
[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.");
}
}
Tuy nhiên tôi nhận được một lỗi trong quá trình thử nêu
SampleServiceUnitTest.DefaultInitializationUnitTest:
System.NullReferenceException : Object reference not set to an instance of an object.
liên quan đến WebOperationContext trong phương pháp SampleService.
IWebContextResolver là gì? –