public void RequestWithoutSubfolder_ForAshxFileInDirectory_GetsHandlerInPhysicalDirectory()
        {
            //arrange
            string virtualPath = string.Empty;
            var routeData = new RouteData
                                {
                                    Route = new DirectoryRoute("admin", new Mock<IDependencyResolver>().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<IDependencyResolver>().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);
        }
        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<IDependencyResolver>().Object))
                                };
            var requestContext = new RequestContext(httpContext.Object, routeData);
            IRouteHandler routeHandler = new DirectoryRouteHandler(new Mock<ISubtextPageBuilder>().Object,
                                                                   new Mock<IDependencyResolver>().Object);

            //act, assert
            UnitTestHelper.AssertThrows<InvalidOperationException>(() => routeHandler.GetHttpHandler(requestContext));
        }
        public void RequestWithoutSubfolder_ForDirectoryWithoutFile_AppendsDefaultFileToVirtualPath()
        {
            //arrange
            string virtualPath = string.Empty;
            var routeData = new RouteData();
            routeData.Route = new DirectoryRoute("admin", new Mock<IDependencyResolver>().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<IDependencyResolver>().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);
        }