Exemple #1
0
 /// <summary>
 /// Convert a string into a URL object
 /// </summary>
 public static object ToSql(URL input)
 {
     if (input == null)
         return DBNull.Value;
     else
         return input.ToSql();
 }
Exemple #2
0
 public static URL GetSiteRoot(URL urlSrc)
 {
     var uri = urlSrc.ToUri();
     var rootURL = uri.OriginalString.Replace(uri.LocalPath, "").Replace(uri.Query,"").Replace(uri.Fragment,"");
     return new URL(rootURL);
 }
Exemple #3
0
        public void TestURL()
        {
            URL url = new URL("https://test.where.com/Test.html?name=value#top");
            bool valid = url.Valid; //True
            string urlValue = url.Value; //https://test.where.com/Test.html?name=value#top
            string domain = url.Domain; //where.com
            URL siteRoot = url.GetSiteRoot(); //https://test.where.com
            string urlToString = url.ToString(); //https://test.where.com/Test.html?name=value#top
            string urlStringImplicit = (string)url; //https://test.where.com/Test.html?name=value#top
            string link = url.ToLink("Click Here", "_blank", "LinkCssClass"); //<a href=\"https://test.where.com/Test.html?name=value#top\" target=\"_blank\" class=\"LinkCssClass\">Click Here</a>
            object sqlObj = url.ToSql(); //https://test.where.com/Test.html?name=value#top or DBNull.Value when empty
            URL.URLCheckExistsResult exists = url.CheckExists(); //URL.URLCheckExistsResult.DoesNotExist

            Assert.IsTrue(valid);
            Assert.AreEqual(urlValue, "https://test.where.com/Test.html?name=value#top");
            Assert.AreEqual(domain, "test.where.com");
            Assert.AreEqual(siteRoot, (URL) "https://test.where.com");
            Assert.AreEqual(urlToString, "https://test.where.com/Test.html?name=value#top");
            Assert.AreEqual(urlStringImplicit, "https://test.where.com/Test.html?name=value#top");
            Assert.AreEqual(link, "<a href=\"https://test.where.com/Test.html?name=value#top\" target=\"_blank\" class=\"LinkCssClass\">Click Here</a>");
            Assert.AreEqual(sqlObj, "https://test.where.com/Test.html?name=value#top");
            Assert.AreEqual(exists, URL.URLCheckExistsResult.DoesNotExist);

            URL url2 = "https://google.com";
            URL.URLCheckRedirectResult redirected = url2.CheckRedirect(); //URL.URLCheckRedirectResult.PermanentRedirect

            URL url3 = "http://google.com/notreallyapage";
            URL.URLCheck404Result enu404Result = url3.CheckFor404(); //URL.URLCheck404Result.NotFound404

            Assert.AreEqual(redirected, URL.URLCheckRedirectResult.PermanentRedirect);
            Assert.AreEqual(enu404Result, URL.URLCheck404Result.NotFound404);
        }