我在单元测试的包装器上模拟 WebOperationContext 类(使用 Moq)。但是我需要在我的模拟上下文中执行来自 WebOperationContext 类的 CreateTextResponse(...) 方法以生成消息。你能给我任何建议吗?
编辑:下面是我用于 WebOperationContext 的当前模拟。但是,我无法实现 CreateTextResponse/CreateStreamResponse。
public IAsyncResult BeginGetData(AsyncCallback asyncCallback, object asyncState)
public Message EndGetData(IAsyncResult asyncResult)
public class OperationContextMock : IOperationContext
{
public HttpCookieCollection Cookies { get; set; }
public Message CreateStreamResponse(Action<System.IO.Stream> streamWriter, string contentType)
{
throw new NotImplementedException();
}
public Message CreateTextResponse(string text, string contentType)
{
// How to mock this method so that it returns a Message object?
}
public string LookupRequestParameter(RequestParameter requestParameter)
{
throw new NotImplementedException();
}
public NameValueCollection QueryParameters { get; set; }
public NameValueCollection RequestHeaders { get; set; }
public Uri RequestUri { get; set; }
public string ResponseContentType { get; set; }
public string ResponseLocation { get; set; }
public HttpStatusCode ResponseStatusCode { get; set; }
public CatalogServiceOperationContextMock()
{
this.ResponseStatusCode = HttpStatusCode.OK;
}
}