Ejemplo n.º 1
0
 /// <summary>
 /// System.Uri is just awful at parsing URIs. Using Nito.UniformResourceIdentifiers
 /// </summary>
 /// <param name="uriString"></param>
 /// <param name="uri"></param>
 /// <returns></returns>
 private static bool TryCreateUri(string uriString, out IUniformResourceIdentifierReference uri)
 {
     try
     {
         uri = UniformResourceIdentifierReference.Parse(uriString);
         return(true);
     }
     catch
     {
         uri = null;
         return(false);
     }
 }
Ejemplo n.º 2
0
        public void ReferenceResolutionNormalExamples(string expectedUrl, string expectedReferenceUrl, string host, IEnumerable <string> path, string query, string fragment)
        {
            // See 5.4.1
            var referenceUri = new RelativeReferenceBuilder().WithHost(host).WithPrefixlessPathSegments(path).WithQuery(query).WithFragment(fragment).Build();

            Assert.Equal(expectedReferenceUrl, referenceUri.ToString());

            var baseUri = GenericUniformResourceIdentifier.Parse("http://a/b/c/d;p?q");
            var result  = baseUri.Resolve(referenceUri);

            Assert.Equal(expectedUrl, result.ToString());

            var abstractResult = ((IUniformResourceIdentifier)baseUri).Resolve(referenceUri);

            Assert.IsType <GenericUniformResourceIdentifier>(abstractResult);
            Assert.Equal(expectedUrl, abstractResult.ToString());

            var abstractReferenceResult = baseUri.Resolve(UniformResourceIdentifierReference.Parse(expectedReferenceUrl));

            Assert.Equal(expectedUrl, abstractReferenceResult.ToString());
        }
        public void Parse_ResultsInCorrectType(string uri, Type expectedType)
        {
            var result = UniformResourceIdentifierReference.Parse(uri);

            Assert.IsType(expectedType, result);
        }