예제 #1
0
        public void NotEquals_EmptyHostStringAndNonNullHostString()
        {
            // Arrange
            var hostString = new HostString("example.com");

            // Act and Assert
            Assert.NotEqual(hostString, new HostString(string.Empty));
        }
예제 #2
0
        public void NotEquals_DefaultHostStringAndNonNullHostString()
        {
            // Arrange
            var hostString = new HostString("example.com");

            // Act and Assert
            Assert.NotEqual(default(HostString), hostString);
        }
예제 #3
0
        public void Port_ExtractsInvalidPortFromValue(string sourceValue)
        {
            // Arrange
            var hostString = new HostString(sourceValue);

            // Act
            var result = hostString.Port;

            // Assert
            Assert.Null(result);
        }
예제 #4
0
        public void Port_ExtractsPortFromValue(string sourceValue, int?expectedPort)
        {
            // Arrange
            var hostString = new HostString(sourceValue);

            // Act
            var result = hostString.Port;

            // Assert
            Assert.Equal(expectedPort, result);
        }
예제 #5
0
        public void Domain_ExtractsHostFromValue(string sourceValue, string expectedDomain)
        {
            // Arrange
            var hostString = new HostString(sourceValue);

            // Act
            var result = hostString.Host;

            // Assert
            Assert.Equal(expectedDomain, result);
        }
예제 #6
0
        public void Ctor_CreatesFromHostAndPort(string sourceHost, int sourcePort, string expectedHost, int expectedPort)
        {
            // Arrange
            var hostString = new HostString(sourceHost, sourcePort);

            // Act
            var host = hostString.Host;
            var port = hostString.Port;

            // Assert
            Assert.Equal(expectedHost, host);
            Assert.Equal(expectedPort, port);
        }
예제 #7
0
        public void ImplicitStringConverters_WorksWithAdd()
        {
            var scheme = "http";
            var host = new HostString("localhost:80");
            var pathBase = new PathString("/base");
            var path = new PathString("/path");
            var query = new QueryString("?query");
            var fragment = new FragmentString("#frag");

            var result = scheme + "://" + host + pathBase + path + query + fragment;
            Assert.Equal("http://localhost:80/base/path?query#frag", result);

            result = pathBase + path + query + fragment;
            Assert.Equal("/base/path?query#frag", result);

            result = path + "text";
            Assert.Equal("/pathtext", result);
        }
예제 #8
0
 public void HostMatchThrowsForBadPort()
 {
     Assert.Throws <FormatException>(() => HostString.MatchesAny("example.com:1abc", new StringSegment[] { "example.com" }));
 }
예제 #9
0
 [InlineData("::1", "::1")] // Brackets are added to the host before the comparison
 public void HostDoesntMatch(string host, string pattern)
 {
     Assert.False(HostString.MatchesAny(host, new StringSegment[] { pattern }));
 }
예제 #10
0
 public void HostMatches(string host, string pattern)
 {
     Assert.True(HostString.MatchesAny(host, new StringSegment[] { pattern }));
 }