Exemplo n.º 1
0
        public void GenerateClientUrl_ResolvesRelativePathToSubfolder_WithApplicationPath()
        {
            AppDomainUtils.RunInSeparateAppDomain(() =>
            {
                using (IDisposable _ = Utils.CreateHttpContext("default.aspx", "http://localhost/WebSite1/subfolder1/default.aspx"),
                       __ = Utils.CreateHttpRuntime("/WebSite1/"))
                {
                    // Arrange
                    var vpath    = "~/subfolder1/default.aspx";
                    var href     = "world/test.aspx";
                    var expected = "/WebSite1/subfolder1/world/test.aspx";
                    var context  = new HttpContextWrapper(HttpContext.Current);
                    var page     = new MockPage()
                    {
                        VirtualPath = vpath, Context = context
                    };

                    // Act
                    var actual1 = UrlUtil.GenerateClientUrl(context, vpath, href);
                    var actual2 = page.Href(href);

                    // Assert
                    Assert.Equal(expected, actual1);
                    Assert.Equal(expected, actual2);
                }
            });
        }
Exemplo n.º 2
0
 public void UrlAnonymousObjectTest()
 {
     AppDomainUtils.RunInSeparateAppDomain(
         () =>
     {
         using (
             IDisposable _ = Utils.CreateHttpContext(
                 "default.aspx",
                 "http://localhost/"
                 ),
             __ = Utils.CreateHttpRuntime("/")
             )
         {
             Assert.Equal(
                 "/world/test.cshtml?Prop1=value1",
                 UrlUtil.GenerateClientUrl(
                     new HttpContextWrapper(HttpContext.Current),
                     "~/world/page.cshtml",
                     "test.cshtml",
                     new { Prop1 = "value1" }
                     )
                 );
             Assert.Equal(
                 "/world/test.cshtml?Prop1=value1&Prop2=value2",
                 UrlUtil.GenerateClientUrl(
                     new HttpContextWrapper(HttpContext.Current),
                     "~/world/page.cshtml",
                     "test.cshtml",
                     new { Prop1 = "value1", Prop2 = "value2" }
                     )
                 );
         }
     }
         );
 }
Exemplo n.º 3
0
        public void GenerateClientUrlWithOnlyQueryStringForContentPathReturnsOriginalContentPath()
        {
            // Act
            string returnedUrl = UrlUtil.GenerateClientUrl(null, "?foo=bar");

            // Assert
            Assert.Equal("?foo=bar", returnedUrl);
        }
Exemplo n.º 4
0
        public void GenerateClientUrlWithNullContentPathReturnsNull()
        {
            // Act
            string returnedUrl = UrlUtil.GenerateClientUrl(null, null);

            // Assert
            Assert.Null(returnedUrl);
        }
Exemplo n.º 5
0
        public void GenerateClientUrlWithEmptyContentPathReturnsEmptyString()
        {
            // Act
            string returnedUrl = UrlUtil.GenerateClientUrl(null, "");

            // Assert
            Assert.Equal("", returnedUrl);
        }
Exemplo n.º 6
0
        public void GenerateClientUrlWithAppRelativeContentPathAndRewritingDisabled()
        {
            // Arrange
            Mock <HttpContextBase> mockHttpContext = GetMockHttpContext(includeRewriterServerVar: false);

            // Act
            string returnedUrl = UrlUtil.GenerateClientUrl(mockHttpContext.Object, "~/foo/bar?alpha=bravo");

            // Assert
            Assert.Equal("/myapp/(S(session))/foo/bar?alpha=bravo", returnedUrl);
        }
Exemplo n.º 7
0
        public void GenerateClientUrlWithAbsoluteContentPathAndRewritingDisabled()
        {
            // Arrange
            Mock <HttpContextBase> mockHttpContext = GetMockHttpContext(includeRewriterServerVar: false);

            // Act
            string returnedUrl = UrlUtil.GenerateClientUrl(mockHttpContext.Object, "should remain unchanged");

            // Assert
            Assert.Equal("should remain unchanged", returnedUrl);
        }
Exemplo n.º 8
0
        public void GenerateClientUrlWithAppRelativeContentPathAndRewritingEnabled()
        {
            UrlUtil.ResetUrlRewriterHelper(); // Reset the "is URL rewriting enabled?" cache

            // Arrange
            Mock <HttpContextBase> mockHttpContext = GetMockHttpContext(includeRewriterServerVar: true);

            mockHttpContext.Setup(c => c.Request.RawUrl).Returns("/quux/foo/baz");
            mockHttpContext.Setup(c => c.Request.Path).Returns("/myapp/foo/baz");

            // Act
            string returnedUrl = UrlUtil.GenerateClientUrl(mockHttpContext.Object, "~/foo/bar?alpha=bravo");

            // Assert
            Assert.Equal("/quux/foo/bar?alpha=bravo", returnedUrl);
        }
Exemplo n.º 9
0
        public void GenerateClientUrl_ResolvesVirtualPath_WithUrlRewrite()
        {
            AppDomainUtils.RunInSeparateAppDomain(() =>
            {
                // Arrange
                var vpath       = "~/subfolder1/default.aspx";
                var href        = "world/test.aspx";
                var expected    = "/subfolder1/world/test.aspx";
                var contextMock = GetMockHttpContext(true);
                contextMock.Setup(c => c.Request.RawUrl).Returns("/subfolder1/default.aspx");
                contextMock.Setup(c => c.Request.Path).Returns("/myapp/subfolder1/default.aspx");

                // Act
                var actual1 = UrlUtil.GenerateClientUrl(contextMock.Object, vpath, href);

                // Assert
                Assert.Equal(expected, actual1);
            });
        }