This is my first foray into using NSubstitute.
I am trying to emulate a routine returning a 409 - Conflict error on a web call.
WebResponse response = Substitute.For<WebResponse>();
((HttpWebResponse)response).StatusCode.Returns(HttpStatusCode.Conflict);
return (response);
The code compiles cleanly, but upon execution the setting of the status code throws this:
Unable to cast object of type Castle.Proxies.WebResponse Proxy to type 'System.Net.HttpWebResponse'
Do I have some sort of syntax issue with my casting?
Thanks.
Bryan Hunt
Right,
HttpWebResponseis a derived class fromWebResponse, so exception is correct. You might do a mock ofHttpWebResponseinstead: