예제 #1
0
        public void MatchURIs()
        {
            var uris = new[] {
                "https://[email protected]:123/forum/questions/?tag=networking&order=newest#top",
                "ldap://[2001:db8::7]/c=GB?objectClass?one",
                "news:comp.infosystems.www.servers.unix",
                "tel:+1-816-555-1212",
                "telnet://192.0.2.16:80/",
                "urn:oasis:names:specification:docbook:dtd:xml:4.1.2"
            };

            foreach (var uri in uris)
            {
                var realUri = new Uri(uri);
                var bytes   = Encoding.UTF8.GetBytes(uri);

                Assert.True(URI.Execute(bytes, out var match, out var status));
                Assert.NotEqual(OperationStatus.InvalidData, status);
                Assert.NotEqual(OperationStatus.DestinationTooSmall, status);

                Assert.Equal(realUri.Scheme, match.GetString(URIParts.Scheme));
                Assert.Equal(realUri.UserInfo, match.GetString(URIParts.Userinfo, true));
                Assert.Equal(realUri.Host, match.GetString(URIParts.Host, true));

                // Assert.Equal(realUri.Authority, match.GetString(URIParts.Authority)); // ! CLR Authority is not as per RFC 3986 3.2., it should contain userinfo
            }
        }