I am writing unit test for WCF web service. I intentionally send the wrong request to the server that issues WebExceptionFault<string>. In unit test, the exception that throws is EndpointNotFoundExceptionwith the standard WebExceptionin the property InnerException. I want to check that the body of the answer corresponds to the line, which, it seems to me, should be there.
I am facing a problem, however, since the property Responsefor WebException(which is System.Net.SyncMemoryStream) is Disposed and cannot be read.
My code is:
Clubs actual;
try
{
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);
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
Assert.AreEqual(sr.ReadToEnd(), "League not allowed for selected club");
}
Is it normal that the InnerException properties are located? Is there any way around this?
source
share