public void RoundTripFormatting(string expectedUrl, string scheme, string userInfo, string host, string port, IEnumerable <string> path, string query, string fragment) { var uri = CreateUri(path, scheme: scheme, userInfo: userInfo, host: host, port: port, query: query, fragment: fragment); Assert.Equal(expectedUrl, uri.ToString()); var parsed = GenericUniformResourceIdentifier.Parse(uri.ToString()); Assert.Equal(scheme, parsed.Scheme); Assert.Equal(userInfo, parsed.UserInfo); Assert.Equal(host, parsed.Host); Assert.Equal(port, parsed.Port); Assert.Equal(path, parsed.PathSegments); Assert.Equal(query, parsed.Query); Assert.Equal(fragment, parsed.Fragment); var deconstructed = new GenericUniformResourceIdentifierBuilder(uri).Build(); Assert.Equal(scheme, deconstructed.Scheme); Assert.Equal(userInfo, deconstructed.UserInfo); Assert.Equal(host, deconstructed.Host); Assert.Equal(port, deconstructed.Port); Assert.Equal(path, deconstructed.PathSegments); Assert.Equal(query, deconstructed.Query); Assert.Equal(fragment, deconstructed.Fragment); if (expectedUrl != "foo://info.example.com?fred") // Bug in System.Uri will translate this to "foo://info.example.com/?fred" { var systemUri = uri.ToUri(); Assert.True(systemUri.IsAbsoluteUri); Assert.Equal(uri.ToString(), systemUri.ToString()); } }
[InlineData("HTTP://www.EXAMPLE.com/", "http://www.example.com/")] // See 6.2.2.1 public void ComparisonExamples(string first, string second) { var uri1 = GenericUniformResourceIdentifier.Parse(first); var uri2 = GenericUniformResourceIdentifier.Parse(second); Assert.True(uri1.Equals(uri2)); Assert.Equal(0, uri1.CompareTo(uri2)); }
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()); }
[InlineData("scheme:/b", "scheme", null, null, null, new[] { "", "a", "..", "..", ".", "b" }, null, null)] // Paths normalized without host (unusual but legal) public void UriFormattingExamples(string expectedUrl, string scheme, string userInfo, string host, string port, IEnumerable <string> path, string query, string fragment) { var uri = new GenericUniformResourceIdentifier(scheme, userInfo, host, port, path, query, fragment); Assert.Equal(expectedUrl, uri.ToString()); }