public void when_json_is_accepted_then_return_json() { var controller = new ExampleController(); var action = controller.DefaultActionResult(); var context = MockContextFor(controller); var response = new Mock <HttpResponseBase>(); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "application/json" }); context.SetupGet(x => x.HttpContext.Response).Returns(() => response.Object); action.ExecuteResult(context.Object); response.VerifySet(x => x.ContentType = "application/json"); }
public void when_no_providers_are_found_for_values_in_the_accepts_header_then_return_406() { // 415 Unsupported Media Type // http://tools.ietf.org/html/rfc2616#section-10.4.16 var controller = new ExampleController(); var action = controller.DefaultActionResult(); var context = new Mock <ControllerContext>(); var response = new Mock <HttpResponseBase>(); context.SetupGet(x => x.HttpContext.Response).Returns(() => response.Object); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "not a real type" }); action.ExecuteResult(context.Object); response.VerifySet(x => x.StatusCode = 406); }
public void when_json_format_expected_then_returns_json() { var controller = new ExampleController(); var action = controller.DefaultActionResult(); var context = MockContextFor(controller); var response = new Mock <HttpResponseBase>(); var qs = new NameValueCollection(); qs.Add("format", "json"); context.Setup(x => x.HttpContext.Request.QueryString).Returns(qs); context.SetupGet(x => x.HttpContext.Response).Returns(() => response.Object); action.ExecuteResult(context.Object); response.VerifySet(x => x.ContentType = "application/json"); }
public void when_type_contains_additional_data_it_is_still_recognized() { var controller = new ExampleController(); var action = (ContentTypeAwareResult)controller.DefaultActionResult(); var view = new Mock <ViewResult>(); view.Setup(x => x.ExecuteResult(It.IsAny <ControllerContext>())) .Verifiable(); action.WhenHtml = (x, v, t) => view.Object; var context = MockContextFor(controller); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "text/html; q=0.90" }); action.ExecuteResult(context.Object); view.VerifyAll(); }
public void when_everything_is_accepted_then_return_viewresult() { var controller = new ExampleController(); var action = (ContentTypeAwareResult)controller.DefaultActionResult(); var view = new Mock <ViewResult>(); view.Setup(x => x.ExecuteResult(It.IsAny <ControllerContext>())) .Verifiable(); action.WhenHtml = (x, v, t) => view.Object; var context = MockContextFor(controller); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "*/*" }); action.ExecuteResult(context.Object); view.VerifyAll(); }
public void when_no_providers_are_found_for_values_in_the_accepts_header_then_return_406() { // 415 Unsupported Media Type // http://tools.ietf.org/html/rfc2616#section-10.4.16 var controller = new ExampleController(); var action = controller.DefaultActionResult(); var context = new Mock<ControllerContext>(); var response = new Mock<HttpResponseBase>(); context.SetupGet(x => x.HttpContext.Response).Returns(() => response.Object); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "not a real type" }); action.ExecuteResult(context.Object); response.VerifySet(x=>x.StatusCode = 406); }
public void when_json_format_expected_and_accepted_then_returns_json() { var controller = new ExampleController(); var action = controller.DefaultActionResult(); var context = MockContextFor(controller); var response = new Mock<HttpResponseBase>(); var qs = new NameValueCollection(); qs.Add("format", "json"); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "application/json" }); context.Setup(x => x.HttpContext.Request.QueryString).Returns(qs); context.SetupGet(x => x.HttpContext.Response).Returns(() => response.Object); action.ExecuteResult(context.Object); response.VerifySet(x => x.ContentType = "application/json"); }
public void when_type_contains_additional_data_it_is_still_recognized() { var controller = new ExampleController(); var action = (ContentTypeAwareResult)controller.DefaultActionResult(); var view = new Mock<ViewResult>(); view.Setup(x => x.ExecuteResult(It.IsAny<ControllerContext>())) .Verifiable(); action.WhenHtml = (x,v,t) => view.Object; var context = MockContextFor(controller); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "text/html; q=0.90" }); action.ExecuteResult(context.Object); view.VerifyAll(); }
public void when_everything_is_accepted_then_return_viewresult() { var controller = new ExampleController(); var action = (ContentTypeAwareResult)controller.DefaultActionResult(); var view = new Mock<ViewResult>(); view.Setup(x => x.ExecuteResult(It.IsAny<ControllerContext>())) .Verifiable(); action.WhenHtml = (x, v, t) => view.Object; var context = MockContextFor(controller); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "*/*" }); action.ExecuteResult(context.Object); view.VerifyAll(); }
public void when_json_is_accepted_then_return_json() { var controller = new ExampleController(); var action = controller.DefaultActionResult(); var context = MockContextFor(controller); var response = new Mock<HttpResponseBase>(); context.Setup(x => x.HttpContext.Request.AcceptTypes).Returns(new[] { "application/json" }); context.SetupGet(x => x.HttpContext.Response).Returns(() => response.Object); action.ExecuteResult(context.Object); response.VerifySet(x => x.ContentType = "application/json"); }