private static ControllerContext CreateControllerContext(string area = null, string areaFolder = null) { var httpContext = new TestHttpContext(new WebTestContext { AppRelativeCurrentExecutionFilePath = $"~/{area}" }); var route = new Route(area, null) { Defaults = new RouteValueDictionary { { "controller", "Test" }, }, DataTokens = new RouteValueDictionary() }; if (area != null) { route.DataTokens.Add("area", area); } if (areaFolder != null) { route.DataTokens.Add("areaFolder", areaFolder); } return(new ControllerContext(httpContext, route.GetRouteData(httpContext), new TestController())); }
private UrlHelper CreateUrlHelper(string requestPath) { string expectedUrl = "{controller}/{action}/{id}"; RouteValueDictionary expectedDefaults = new RouteValueDictionary() { { RouteConstants.controller, "Home" }, { RouteConstants.action, "Index" }, { RouteConstants.id, UrlParameter.Optional }, }; string[] expectedNamespaces = new[] { "Some.Namespace" }; Assembly assembly = Assembly.GetExecutingAssembly(); string applicationDefaultNamespace = "Some"; var routeCollection = new RouteCollection(); var area = new SomeAreaRegistration(); area.RegisterArea(new AreaRegistrationContext(area.AreaName, routeCollection)); Route route = routeCollection.RegisterDefaultRoutes(expectedUrl, expectedDefaults, expectedNamespaces, assembly, applicationDefaultNamespace); var testHttpContext = new TestHttpContext(new WebTestContext() { AppRelativeCurrentExecutionFilePath = requestPath, }); var routeData = routeCollection.GetRouteData(testHttpContext); var requestContext = new RequestContext(testHttpContext, routeData); return(new UrlHelper(requestContext, routeCollection)); }
public void Should_set_content_type_based_on_extention(string extension, string contentType) { var httpContext = new TestHttpContext(new WebTestContext()); httpContext.Response.SetContentTypeBasedOnExtension(extension); Assert.Equal(contentType, httpContext.Response.ContentType); }
public void Should_throw_exception_from_unknown_extention() { var httpContext = new TestHttpContext(new WebTestContext()); var exception = Assert.Throws <NotSupportedException>(() => httpContext.Response.SetContentTypeBasedOnExtension("unknown")); Assert.Contains("unknown", exception.Message); }
public void Should_not_use_default_resource_folders_as_controllers(string path, string controller) { var testHttpContext = new TestHttpContext(new WebTestContext() { AppRelativeCurrentExecutionFilePath = "~/" + path }); var routeData = sut.GetRouteData(testHttpContext); Assert.Equal(controller, routeData?.Values["controller"] as string); }
private static void CreateSut(string file, bool fileExists, out TestHttpContext httpContext, out TestFileContentProvider testFileContentProvider, out ResourceHandler handler) { httpContext = new TestHttpContext(new WebTestContext { AppRelativeCurrentExecutionFilePath = $"~/Scripts/" + file }); var route = new Route("Scripts/{*path}", null) { Defaults = new RouteValueDictionary(), DataTokens = new RouteValueDictionary() }; var requestContext = new RequestContext(httpContext, route.GetRouteData(httpContext)); testFileContentProvider = new TestFileContentProvider(fileExists); handler = new ResourceHandler(requestContext, testFileContentProvider); }
public void Should_return_expected_handler() { var route = new Route("Scripts/{*path}", null); var testHttpContext = new TestHttpContext(new WebTestContext() { AppRelativeCurrentExecutionFilePath = "~/Scripts/file.js" }); var routeData = route.GetRouteData(testHttpContext); var requestContext = new RequestContext(testHttpContext, routeData); var routeHandler = new TestResourceRouteHandler(); var httpHandler = routeHandler.GetHttpHandler(requestContext); Assert.NotNull(httpHandler); }