WCF Web サービスの単体テストを作成しています。をスローするサーバーに意図的に無効なリクエストを送信していますWebExceptionFault<string>
。単体テストでキャッチされる例外は、プロパティEndpointNotFoundException
に標準で付いています。応答の本文が、そこにあるはずの文字列と一致することを確認したいと思います。WebException
InnerException
ただし、 (である)のResponse
プロパティが Disposed であり、読み取ることができないため、問題に遭遇しています。WebException
System.Net.SyncMemoryStream
私のコード:
Clubs actual;
try
{
//"201" is an invalid argument for the first parameter
actual = new Clubs(channel.GetClubs("201", "123"));
}
catch (EndpointNotFoundException e)
{
WebException w = e.InnerException as WebException;
Assert.IsNotNull(w);
HttpWebResponse resp = w.Response as HttpWebResponse;
Assert.IsNotNull(resp);
Assert.AreEqual(resp.StatusCode, HttpStatusCode.NotFound);
//Next line throws an ArgumentException saying Stream not readable
//Investigation shows it has been disposed
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
Assert.AreEqual(sr.ReadToEnd(), "League not allowed for selected club");
}
InnerException のプロパティが破棄されるのは正常ですか? これを回避する方法はありますか?