非プリミティブを返すWebサービスを単体テストしようとしています。応答は、要求に応じてxmlまたはjsonのいずれかになります。私のテストでは、コンテンツ本体をオブジェクトの1つに逆シリアル化できれば素晴らしいと思います。ここにいくつかのコードがあります:
[WebGet(UriTemplate = "{arg1}/{arg2}")]
public HttpResponseMessage<MyType> GetSomethingCool(string arg1, long arg2)
{
return new HttpResonseMessage<MyTpe>(new MyType());
}
public class MyType
{
public string Property1 { get; set; }
public long Property2 { get; set; }
public string Property3 { get; set; }
}
そして私のテスト:
[Test]
public void MyTestForTheWebService_ReturnsText()
{
Service1 service = new Service1 (_mockRepository.Object);
HttpResponseMessage<MyType> result = service.GetSomethingCool("Something", **);
Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
MyType resultContent = result.Content.ReadAs<MyType>(); // doesn't work
Assert.AreEqual("expected value", resultContent .Property1);
.....
したがって、基本的には、result.ContentをMyTypeに変換できる必要があり、その方法がわかりません。ありがとう