public void MatchRequestDoesNotSetDisplayModeIfNoMatch() { // Arrange var objectFactory = new HashyBuildManager(new string[] { "~/page.Mobile.aspx" }); var mockContext = new Mock <HttpContextBase>(); mockContext.Setup(context => context.Items).Returns(new Hashtable()); mockContext.Setup(c => c.Request.Browser.IsMobileDevice).Returns(true); mockContext.Setup(c => c.Request.Cookies).Returns(new HttpCookieCollection()); mockContext.Setup(c => c.Response.Cookies).Returns(new HttpCookieCollection()); var displayModeProvider = new DisplayModeProvider(); var displayMode = new Mock <IDisplayMode>(MockBehavior.Strict); displayMode.Setup(d => d.CanHandleContext(mockContext.Object)).Returns(false); displayModeProvider.Modes.Add(displayMode.Object); // Act WebPageMatch smartyMatch = WebPageRoute.MatchRequest( "notThere.aspx", new string[] { "aspx" }, objectFactory.Exists, mockContext.Object, displayModeProvider ); // Assert Assert.Null(DisplayModeProvider.GetDisplayMode(mockContext.Object)); }
public void MatchRequestSetsDisplayModeOfFirstMatchPerContext() { // Arrange var objectFactory = new HashyBuildManager( new string[] { "~/page.Mobile.aspx", "~/nonMobile.aspx" } ); var mockContext = new Mock <HttpContextBase>(); mockContext.Setup(context => context.Items).Returns(new Hashtable()); mockContext.Setup(c => c.Request.Browser.IsMobileDevice).Returns(true); mockContext.Setup(c => c.Request.Cookies).Returns(new HttpCookieCollection()); mockContext.Setup(c => c.Response.Cookies).Returns(new HttpCookieCollection()); var displayModeProvider = new DisplayModeProvider(); // Act WebPageMatch mobileMatch = WebPageRoute.MatchRequest( "page.aspx", new string[] { "aspx" }, objectFactory.Exists, mockContext.Object, displayModeProvider ); // Assert Assert.NotNull(mobileMatch.MatchedPath); Assert.Equal( DisplayModeProvider.MobileDisplayModeId, DisplayModeProvider.GetDisplayMode(mockContext.Object).DisplayModeId ); }
// Helper to test smarty route match, null match string is used for no expected match private static void ConstraintTest(IEnumerable<string> validFiles, IEnumerable<string> supportedExt, string url, string match, string pathInfo, bool mobileDevice = false) { var objectFactory = new HashyBuildManager(validFiles); var mockContext = new Mock<HttpContextBase>(); mockContext.Setup(context => context.Items).Returns(new Hashtable()); mockContext.Setup(c => c.Request.Browser.IsMobileDevice).Returns(mobileDevice); mockContext.Setup(c => c.Request.Cookies).Returns(new HttpCookieCollection()); mockContext.Setup(c => c.Response.Cookies).Returns(new HttpCookieCollection()); var displayModeProvider = new DisplayModeProvider(); WebPageMatch smartyMatch = WebPageRoute.MatchRequest(url, supportedExt, objectFactory, mockContext.Object, displayModeProvider); if (match != null) { Assert.NotNull(smartyMatch); Assert.Equal(match, smartyMatch.MatchedPath); Assert.Equal(pathInfo, smartyMatch.PathInfo); } else { Assert.Null(smartyMatch); } }
// Helper to test smarty route match, null match string is used for no expected match private static void ConstraintTest( IEnumerable <string> validFiles, IEnumerable <string> supportedExt, string url, string match, string pathInfo, bool mobileDevice = false ) { var objectFactory = new HashyBuildManager(validFiles); var mockContext = new Mock <HttpContextBase>(); mockContext.Setup(context => context.Items).Returns(new Hashtable()); mockContext.Setup(c => c.Request.Browser.IsMobileDevice).Returns(mobileDevice); mockContext.Setup(c => c.Request.Cookies).Returns(new HttpCookieCollection()); mockContext.Setup(c => c.Response.Cookies).Returns(new HttpCookieCollection()); var displayModeProvider = new DisplayModeProvider(); WebPageMatch smartyMatch = WebPageRoute.MatchRequest( url, supportedExt.ToArray(), objectFactory.Exists, mockContext.Object, displayModeProvider ); if (match != null) { Assert.NotNull(smartyMatch); Assert.Equal(match, smartyMatch.MatchedPath); Assert.Equal(pathInfo, smartyMatch.PathInfo); } else { Assert.Null(smartyMatch); } }
public void MatchRequestDoesNotSetDisplayModeIfNoMatch() { // Arrange var objectFactory = new HashyBuildManager(new string[] { "~/page.Mobile.aspx" }); var mockContext = new Mock<HttpContextBase>(); mockContext.Setup(context => context.Items).Returns(new Hashtable()); mockContext.Setup(c => c.Request.Browser.IsMobileDevice).Returns(true); mockContext.Setup(c => c.Request.Cookies).Returns(new HttpCookieCollection()); mockContext.Setup(c => c.Response.Cookies).Returns(new HttpCookieCollection()); var displayModeProvider = new DisplayModeProvider(); var displayMode = new Mock<IDisplayMode>(MockBehavior.Strict); displayMode.Setup(d => d.CanHandleContext(mockContext.Object)).Returns(false); displayModeProvider.Modes.Add(displayMode.Object); // Act WebPageMatch smartyMatch = WebPageRoute.MatchRequest("notThere.aspx", new string[] { "aspx" }, objectFactory, mockContext.Object, displayModeProvider); // Assert Assert.Null(DisplayModeProvider.GetDisplayMode(mockContext.Object)); }
public void MatchRequestSetsDisplayModeOfFirstMatchPerContext() { // Arrange var objectFactory = new HashyBuildManager(new string[] { "~/page.Mobile.aspx", "~/nonMobile.aspx" }); var mockContext = new Mock<HttpContextBase>(); mockContext.Setup(context => context.Items).Returns(new Hashtable()); mockContext.Setup(c => c.Request.Browser.IsMobileDevice).Returns(true); mockContext.Setup(c => c.Request.Cookies).Returns(new HttpCookieCollection()); mockContext.Setup(c => c.Response.Cookies).Returns(new HttpCookieCollection()); var displayModeProvider = new DisplayModeProvider(); // Act WebPageMatch mobileMatch = WebPageRoute.MatchRequest("page.aspx", new string[] { "aspx" }, objectFactory, mockContext.Object, displayModeProvider); // Assert Assert.NotNull(mobileMatch.MatchedPath); Assert.Equal(DisplayModeProvider.MobileDisplayModeId, DisplayModeProvider.GetDisplayMode(mockContext.Object).DisplayModeId); }