MoO를 사용하여 단위 테스트 용 WebOperationContext 클래스를 조롱했습니다. 하지만 CreateTextResponse (...) 메소드를 WebOperationContext 클래스에서 Message 생성을위한 조롱 된 컨텍스트에서 실행해야합니다. 그 일을하는 방법을 권해 주시겠습니까?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;
}
}
잘못된 방식으로 자신을 표현한 것으로 보입니다. 그렇지 않으면 응답이 제대로 표시되지 않습니다. 나는 CreateTextResponse (...) 메소드와 WebOperationContextWrapper를 가진 IWebOperationContext 인터페이스를 가지고있다. 나는 WebOperationContext 클래스의 메소드이기 때문에 조롱하는 OperationContext로부터 CreateTextResponse (...)를 실행하고 싶다 (똑같이해야한다). – kazarindn
인터페이스/래퍼 클래스를 사용하는 위치에 대한 샘플 코드를 포함 시키십시오. 작동하지 않는 코드/예제를 포함하십시오. – PatrickSteele
나는 똑같은 문제가있다. 구현 된 대부분의 속성이있는 WebOperationContext 주위에 래퍼가 있지만 실제 WebOperationContext와 비슷하게 동작하도록 CreateTextResponse를 구현하는 방법을 알지 못합니다. – Martin