public void OnlySetsRequestMethodCookie() { var responseCookies = new HttpCookieCollection(); var httpContext = Substitute.For<HttpContextBase>(); httpContext.Request.HttpMethod.Returns("GET"); httpContext.Request.Headers.Returns( new NameValueCollection { { "X-XHR-Referer", "http://localhost:61049/Projects/Create" } }); httpContext.Response.Cookies.Returns(responseCookies); var controllerContext = new ControllerContext( httpContext, new RouteData(), Substitute.For<ControllerBase>()); var filterContext = new ActionExecutedContext( controllerContext, Substitute.For<ActionDescriptor>(), false, null); var attribute = new TurbolinksAttribute(); attribute.OnActionExecuted(filterContext); Assert.Equal("GET", responseCookies["request_method"].Value); }
public void DoesNothing() { var responseCookies = new HttpCookieCollection(); var responseHeaders = new NameValueCollection(); var httpContext = Substitute.For<HttpContextBase>(); httpContext.Request.Headers.Returns(new NameValueCollection()); httpContext.Response.Cookies.Returns(responseCookies); httpContext.Response.Headers.Returns(responseHeaders); var controllerContext = new ControllerContext( httpContext, new RouteData(), Substitute.For<ControllerBase>()); var filterContext = new ActionExecutedContext( controllerContext, Substitute.For<ActionDescriptor>(), false, null); var attribute = new TurbolinksAttribute(); attribute.OnActionExecuted(filterContext); Assert.Empty(responseCookies); Assert.Empty(responseHeaders); }
public RedirectToDifferentOrigin() { var httpContext = Substitute.For<HttpContextBase>(); httpContext.Request.HttpMethod.Returns("GET"); httpContext.Request.Headers.Returns( new NameValueCollection { { "X-XHR-Referer", "http://localhost:61049/Projects/Create" } }); responseCookies = new HttpCookieCollection(); httpContext.Response.Cookies.Returns(responseCookies); var controllerContext = new ControllerContext( httpContext, new RouteData(), Substitute.For<ControllerBase>()); filterContext = new ActionExecutedContext( controllerContext, Substitute.For<ActionDescriptor>(), false, null) { Result = new RedirectResult("http://google.com") }; var attribute = new TurbolinksAttribute(); attribute.OnActionExecuted(filterContext); }
public void ThrowsException() { var attribute = new TurbolinksAttribute(); Assert.Throws<ArgumentNullException>(() => attribute.OnActionExecuted(null)); }
public RedirectToRelative() { RouteTable.Routes.MapRoute( Guid.NewGuid().ToString(), "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }); var httpContext = Substitute.For<HttpContextBase>(); httpContext.Request.HttpMethod.Returns("GET"); httpContext.Request.Headers.Returns( new NameValueCollection { { "X-XHR-Referer", "http://localhost:61049/Projects" } }); responseCookies = new HttpCookieCollection(); responseHeaders = new NameValueCollection(); httpContext.Response.Cookies.Returns(responseCookies); httpContext.Response.Headers.Returns(responseHeaders); var controllerContext = new ControllerContext( httpContext, new RouteData(), Substitute.For<ControllerBase>()); var filterContext = new ActionExecutedContext( controllerContext, Substitute.For<ActionDescriptor>(), false, null) { Result = new RedirectToRouteResult( new RouteValueDictionary( new Dictionary<string, object>())) }; var attribute = new TurbolinksAttribute(); attribute.OnActionExecuted(filterContext); }