I have the following method:
public void SetHttpStatusCode(HttpStatusCode httpStatusCode) { Response.StatusCode = (int)httpStatusCode; }
And the following test:
[TestMethod] public void SetHttpStatusCode_SetsCorrectStatusCode() {
Also, here is the MakeHttpContext
public static Mock<HttpContextBase> MakeHttpContext(string url) { var mockHttpContext = new Mock<HttpContextBase>(); var mockRequest = new Mock<HttpRequestBase>(); var mockResponse = new Mock<HttpResponseBase>(); var mockSession = new Mock<HttpSessionStateBase>();
When I run the test, I get the following exception:
Test method PA.Tests.Controllers.AppControllerTest.SetHttpStatusCode_SetsCorrectStatusCode threw exception: Moq.MockException: Expected invocation on the mock at least once, but was never performed: x => x.StatusCode = It.IsAny<Int32>() Configured setups: x => x.StatusCode = It.IsAny<Int32>(), Times.Never No invocations performed.
How does Moq expect / require call calls? I was debugging the SetHTTPStatusCode method, the response object is indeed a bullied object, however Moq insists there was no call. Am I missing something?
Thanks!
source share