Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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
                );
        }
Esempio n. 3
0
        public void WebPageRouteDoesNotPerformMappingIfRootLevelIsExplicitlyDisabled()
        {
            // Arrange
            var webPageRoute = new WebPageRoute {
                IsExplicitlyDisabled = true
            };
            var context = new Mock <HttpContextBase>();

            context
            .Setup(c => c.RemapHandler(It.IsAny <IHttpHandler>()))
            .Throws(new Exception("Smarty route should be disabled."));
            context
            .SetupGet(c => c.Request)
            .Throws(
                new Exception(
                    "We do not need to use the request to identify if the app is disabled."
                    )
                );

            // Act
            webPageRoute.DoPostResolveRequestCache(context.Object);

            // Assert.
            // If we've come this far, neither of the setups threw.
            Assert.True(true);
        }
Esempio n. 4
0
        // Helper to test smarty route match, null match string is used for no expected match
        private void ConstraintTest(IEnumerable <string> validFiles, IEnumerable <string> supportedExt, string url, string match, string pathInfo)
        {
            HashyVPP vpp = new HashyVPP(validFiles);
            var      virtualPathFactoryManager = new VirtualPathFactoryManager(vpp);

            WebPageMatch smartyMatch = WebPageRoute.MatchRequest(url, supportedExt, virtualPathFactoryManager);

            if (match != null)
            {
                Assert.IsNotNull(smartyMatch, "Should have found a match: " + match);
                Assert.AreEqual(match, smartyMatch.MatchedPath);
                Assert.AreEqual(pathInfo, smartyMatch.PathInfo);
            }
            else
            {
                Assert.IsNull(smartyMatch, "unexpected match");
            }
        }
Esempio n. 5
0
        // 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 WebPageRouteDoesNotPerformMappingIfRootLevelIsExplicitlyDisabled()
        {
            // Arrange
            var webPageRoute = new WebPageRoute { IsExplicitlyDisabled = true };
            var context = new Mock<HttpContextBase>();
            context.Setup(c => c.RemapHandler(It.IsAny<IHttpHandler>())).Throws(new Exception("Smarty route should be disabled."));
            context.SetupGet(c => c.Request).Throws(new Exception("We do not need to use the request to identify if the app is disabled."));

            // Act 
            webPageRoute.DoPostResolveRequestCache(context.Object);

            // Assert. 
            // If we've come this far, neither of the setups threw.
            Assert.True(true);
        }