System.ArgumentException: Invalid setup on a non-overridable member:
w => w.StatusCode
I know this is due to StatusCode not being a virtual method. Now the
million dollar question, how can I correctly moq a response? I can't
find anything on the web, and it's getting difficult to wire
everything up to test properly without this mocking.
Below is my code
Mock<HttpWebResponse> webResponse = new Mock<HttpWebResponse>();
//return our wrapped memory stream on the mock object
webResponse.Setup(w => w.GetResponseStream()).Returns(new
MemoryStream(Encoding.Unicode.GetBytes(GetMockXML(ErrorResponse))));
//return 400 of our error code so that the message is properly parsed
webResponse.Setup(w =>
w.StatusCode).Returns(HttpStatusCode.BadRequest);
WebException webException = new WebException("Excception", new
Exception("Failed to connect"), WebExceptionStatus.UnknownError,
webResponse.Object);
Mock<IXeroRequest> mock = new Mock<IXeroRequest>();
//throw our web exception from above. We should get an admin message
that an error 400 has occured
mock.Setup(m => m.MakeRequest(It.IsAny<XElement>(),
It.IsAny<XeroApi>(), XeroRequestType.Put,
It.IsAny<XeroAuth>())).Callback((XElement e, XeroApi xApi,
XeroRequestType xrt, XeroAuth a) =>
SetXElement(e)).Throws(webException);
ServiceLocator.Register(typeof(IXeroRequest), mock.Object);
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com