Hello,
I'm new to JustMock and have been playing with it only for a few hours. I have been able to convert a few of my existing tests from Microsoft Fakes to JustMock. However, there's one test, where I'm having a lot of trouble and I'm hoping someone can help me with it.
I have a class that derives from the System.Web.Http.ApiController and here is a snapshot of it:
public class MyApiController : ApiController {
public HttpResponseMessage Post(EPAQuestionsetLookupRequest lookup) {
try {
if (!ModelState.IsValid) {
return new HttpResponseMessage(HttpStatusCode.NotAcceptable);
}
return new HttpResponseMessage(HttpStatusCode.OK);
} catch {
return new HttpResponseMessage(HttpStatusCode.InternalServerError);
}
}
}
I have a test written as the follows:
[TestMethod]
public void PostNotValidState() {
var controller = Mock.Create<
MyApiController
>();
Mock.Arrange(() => controller.ModelState.IsValid).Returns(false).MustBeCalled();
// Mock.Arrange(() => ((ApiController)controller).ModelState.IsValid).Returns(false).MustBeCalled();
var response = controller.Post(lookup);
Assert.AreEqual(HttpStatusCode.NotAcceptable, response.StatusCode);
Mock.Assert(controller);
}
I've tried it in the above way and also using a Container instead. But, in both cases, it seems like the ModelState.IsValid is continuing to return true (or the method during the test, is actually not using the arrangement I have, which is confirmed by the fact that the Mock.Assert is failing on the MustBeCalled) and is failing my test. What's the best way for me to be able to mock the ModelState.IsValid to return false and for it to be honored?