Exemple #1
0
        public void RequestWithoutSubfolder_ForAshxFileInDirectory_GetsHandlerInPhysicalDirectory()
        {
            //arrange
            string virtualPath = string.Empty;
            var    routeData   = new RouteData
            {
                Route = new DirectoryRoute("admin", new Mock <IServiceLocator>().Object)
            };

            ;
            routeData.Values.Add("pathinfo", "foo.ashx");
            var pageBuilder = new Mock <ISubtextPageBuilder>();
            var httpHandler = new Mock <IHttpHandler>();

            pageBuilder.Setup(b => b.CreateInstanceFromVirtualPath(It.IsAny <string>(), It.IsAny <Type>())).Returns(
                httpHandler.Object).Callback <string, Type>((vpath, type) => virtualPath = vpath);
            IRouteHandler routeHandler = new DirectoryRouteHandler(pageBuilder.Object, new Mock <IServiceLocator>().Object);
            var           httpContext  = new Mock <HttpContextBase>();

            httpContext.FakeRequest("~/admin/foo.ashx");
            var requestContext = new RequestContext(httpContext.Object, routeData);

            //act
            IHttpHandler handler = routeHandler.GetHttpHandler(requestContext);

            //assert
            Assert.AreEqual("~/aspx/admin/foo.ashx", virtualPath);
        }
Exemple #2
0
        public void RequestWithoutSubfolder_ForDirectoryWithoutFileAndWithouEndingSlash_AppendsDefaultFileToVirtualPath()
        {
            //arrange
            string virtualPath = string.Empty;
            var    routeData   = new RouteData
            {
                Route = new DirectoryRoute("admin", new Mock <IServiceLocator>().Object)
            };

            ;
            routeData.Values.Add("pathinfo", "posts");
            var pageBuilder = new Mock <ISubtextPageBuilder>();
            var httpHandler = new Mock <IHttpHandler>();

            pageBuilder.Setup(b => b.CreateInstanceFromVirtualPath(It.IsAny <string>(), It.IsAny <Type>())).Returns(
                httpHandler.Object).Callback <string, Type>((vpath, type) => virtualPath = vpath);
            IRouteHandler routeHandler = new DirectoryRouteHandler(pageBuilder.Object, new Mock <IServiceLocator>().Object);
            var           httpContext  = new Mock <HttpContextBase>();

            httpContext.FakeRequest("~/admin/posts");
            var requestContext = new RequestContext(httpContext.Object, routeData);

            //act
            routeHandler.GetHttpHandler(requestContext);

            //assert
            Assert.AreEqual("~/aspx/admin/posts/Default.aspx", virtualPath);
        }
Exemple #3
0
        public void RequestContext_WithNonDirectoryRoute_CausesInvalidOperationException()
        {
            //arrange
            var httpContext = new Mock <HttpContextBase>();
            var routeData   = new RouteData
            {
                Route = new Route("url",
                                  new DirectoryRouteHandler(new Mock <ISubtextPageBuilder>().Object,
                                                            new Mock <IServiceLocator>().Object))
            };
            var           requestContext = new RequestContext(httpContext.Object, routeData);
            IRouteHandler routeHandler   = new DirectoryRouteHandler(new Mock <ISubtextPageBuilder>().Object,
                                                                     new Mock <IServiceLocator>().Object);

            //act, assert
            UnitTestHelper.AssertThrows <InvalidOperationException>(() => routeHandler.GetHttpHandler(requestContext));
        }