We just started using ASP.Net MVC Release Candidate, and the test project we tested previously tested Ajax requests with MVC beta.
The old code looked something like this:
Mock<HttpRequestBase> request = new Mock<HttpRequestBase>();
Mock<HttpResponseBase> response = new Mock<HttpResponseBase>();
Mock<HttpContextBase> context = new Mock<HttpContextBase>();
context.Expect(c => c.Request).Returns(request.Object);
context.Expect(c => c.Response).Returns(response.Object);
request.Expect(req => req["__MVCASYNCPOST"]).Returns("true");
MyController controller = new MyController();
controller.ControllerContext = new ControllerContext(context.Object, new RouteData(), controller);
ViewResult result = controller.UpdateStatus() as ViewResult;
Then the call to UpdateStatus will use the IsMvcAjaxRequest () method for the request object to determine what needs to be returned to the browser.
A change in the candidate candidate ASP.Net Release MVC to Request.IsMvcAjaxRequest () for the extension method Request.IsAjaxRequest () means that the way we mock request headers changes to:
request.Expect(req => req["X-Requested-With"]).Returns("XMLHttpRequest");
I hope others find this useful.
source
share