public GetVirtualPath ( System.Web.Routing.RequestContext requestContext, RouteValueDictionary values ) : System.Web.Routing.VirtualPathData | ||
requestContext | System.Web.Routing.RequestContext | |
values | RouteValueDictionary | |
return | System.Web.Routing.VirtualPathData |
public void GetVirtualPath_Puts_ModuleRoute_And_ModuleId_Into_New_RVD_And_Reroutes_Using_RouteTable() { // Arrange RequestContext requestContext = new RequestContext(Mockery.CreateMockHttpContext("http://localhost/Foo/Bar"), new RouteData()); RouteValueDictionary values = new RouteValueDictionary(); PortalRequestContext portalRequestContext = requestContext.HttpContext.GetPortalContext(); portalRequestContext.ActiveModuleRequest = new ModuleRequestResult { Module = new Module {Id = 42} }; var mockRoute1 = new Mock<RouteBase>(); mockRoute1.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>())) .Returns(new VirtualPathData(mockRoute1.Object, "Foo/Bar/Baz")); RouteValueDictionary providedValues = null; var mockRoute2 = new Mock<RouteBase>(); mockRoute2.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>())) .Callback<RequestContext, RouteValueDictionary>((c, v) => providedValues = v) .Returns(new VirtualPathData(mockRoute2.Object, "Zoop/Zork/Zoink")); ModuleRouteRewriter rewriter = new ModuleRouteRewriter { ModuleRoutes = new RouteCollection { mockRoute1.Object }, RouteCollection = new RouteCollection { mockRoute2.Object } }; // Act VirtualPathData pathData = rewriter.GetVirtualPath(requestContext, values); // Assert Assert.AreEqual(42, providedValues["moduleId"]); Assert.AreEqual("Foo/Bar/Baz", providedValues["moduleRoute"]); Assert.AreSame(rewriter, pathData.Route); Assert.AreEqual("Zoop/Zork/Zoink", pathData.VirtualPath); }
public void GetVirtualPath_Returns_Null_If_Module_Cant_Route_Request() { // Arrange RequestContext requestContext = new RequestContext(Mockery.CreateMockHttpContext("http://localhost/Foo/Bar"), new RouteData()); RouteValueDictionary values = new RouteValueDictionary(); var mockRoute1 = new Mock<RouteBase>(); mockRoute1.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>())) .Returns(() => null); ModuleRouteRewriter rewriter = new ModuleRouteRewriter { ModuleRoutes = new RouteCollection { mockRoute1.Object } }; // Act VirtualPathData pathData = rewriter.GetVirtualPath(requestContext, values); // Assert Assert.IsNull(pathData); }
public void GetVirtualPath_Routes_Request_Through_ModuleRoutes() { // Arrange RequestContext requestContext = new RequestContext(Mockery.CreateMockHttpContext("http://localhost/Foo/Bar"), new RouteData()); RouteValueDictionary values = new RouteValueDictionary(); var mockRoute1 = new Mock<RouteBase>(); mockRoute1.Setup(r => r.GetVirtualPath(It.IsAny<RequestContext>(), It.IsAny<RouteValueDictionary>())) .Returns(new VirtualPathData(mockRoute1.Object, "Foo")); ModuleRouteRewriter rewriter = new ModuleRouteRewriter { ModuleRoutes = new RouteCollection { mockRoute1.Object } }; // Act rewriter.GetVirtualPath(requestContext, values); // Assert mockRoute1.Verify(r => r.GetVirtualPath(requestContext, values)); }