public void GetRouteData_WithNonMatchingSourceRoute_ReturnsNull() { // Arrange var sourceRouteMock = new Mock<RouteBase>(); var targetRoute = new Mock<RouteBase>().Object; sourceRouteMock.Setup(r => r.GetRouteData(It.IsAny<HttpContextBase>())).Returns((RouteData)null); var redirectRoute = new RedirectRoute(sourceRouteMock.Object, targetRoute, permanent: true); // Act var routeData = redirectRoute.GetRouteData(new Mock<HttpContextBase>().Object); // Assert PAssert.IsTrue(() => routeData == null); // These next few asserts are "laziness" asserts. PAssert.IsTrue(() => redirectRoute.Permanent == true); PAssert.IsTrue(() => redirectRoute.SourceRoute == sourceRouteMock.Object); PAssert.IsTrue(() => redirectRoute.TargetRoute == targetRoute); }
public void GetRouteData_WithMatchingSourceRoute_SwapsRouteHandler() { // Arrange var routeData = new RouteData(); var routeHandler = new Mock<IRouteHandler>().Object; routeData.RouteHandler = routeHandler; var sourceRouteMock = new Mock<RouteBase>(); sourceRouteMock.Setup(r => r.GetRouteData(It.IsAny<HttpContextBase>())).Returns(routeData); var redirectRoute = new RedirectRoute(sourceRouteMock.Object, new Mock<RouteBase>().Object, permanent: false); // Act var redirectRouteData = redirectRoute.GetRouteData(new Mock<HttpContextBase>().Object); // Assert PAssert.IsTrue(() => redirectRouteData.RouteHandler != routeHandler); PAssert.IsTrue(() => redirectRouteData.RouteHandler is RedirectRoute); PAssert.IsTrue(() => redirectRouteData == routeData); PAssert.IsTrue(() => redirectRoute.Permanent == false); }