Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Merge pull request #19579 from hughbe/httplistener-test-fixes
Browse files Browse the repository at this point in the history
Fix failing HttpListener tests
  • Loading branch information
stephentoub authored May 10, 2017
2 parents 327fabf + 3b87a8e commit 02eac65
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ public void Add_PrefixAlreadyRegisteredAndStarted_ThrowsHttpListenerException()

public static IEnumerable<object[]> InvalidPrefix_TestData()
{
yield return new object[] { "http://microsoft.com/" };
// [ActiveIssue(19593, TestPlatforms.OSX)]
if (!PlatformDetection.IsOSX)
{
yield return new object[] { $"http://{Guid.NewGuid().ToString("N")}/" };
}
yield return new object[] { "http://[]/" };
yield return new object[] { "http://[::1%2]/" };
yield return new object[] { "http://[::]/" };
Expand All @@ -252,7 +256,6 @@ public static IEnumerable<object[]> InvalidPrefix_TestData()
yield return new object[] { "http://\\/" };
}

[ActiveIssue(19526)]
[Theory]
[MemberData(nameof(InvalidPrefix_TestData))]
public void Add_InvalidPrefixNotStarted_ThrowsHttpListenerExceptionOnStart(string uriPrefix)
Expand All @@ -265,15 +268,14 @@ public void Add_InvalidPrefixNotStarted_ThrowsHttpListenerExceptionOnStart(strin
Assert.Throws<HttpListenerException>(() => listener.Start());
}

[ActiveIssue(19526)]
[Theory]
[MemberData(nameof(InvalidPrefix_TestData))]
public void Add_InvalidPrefixAlreadyStarted_ThrowsHttpListenerExceptionOnAdd(string uriPrefix)
{
using (var factory = new HttpListenerFactory())
{
HttpListener listener = factory.GetListener();
Assert.Single(listener.Prefixes);
Assert.Single(listener.Prefixes);

Assert.Throws<HttpListenerException>(() => listener.Prefixes.Add(uriPrefix));
}
Expand Down Expand Up @@ -362,7 +364,6 @@ public void Contains_NullPrefix_ThrowsArgumentNullException()
Assert.Throws<ArgumentNullException>("key", () => listener.Prefixes.Contains(null));
}

[ActiveIssue(19526)]
[Fact]
public void Remove_PrefixExistsNotStarted_ReturnsTrue()
{
Expand All @@ -374,9 +375,8 @@ public void Remove_PrefixExistsNotStarted_ReturnsTrue()
Assert.Equal(0, listener.Prefixes.Count);
}

[ActiveIssue(19526)]
[Fact]
public async Task Remove_PrefixExistsStarted_ReturnsTrue()
public void Remove_PrefixExistsStarted_ReturnsTrue()
{
using (var factory = new HttpListenerFactory())
{
Expand All @@ -387,11 +387,8 @@ public async Task Remove_PrefixExistsStarted_ReturnsTrue()
Assert.False(listener.Prefixes.Contains(uriPrefix));
Assert.Equal(0, listener.Prefixes.Count);

// Trying to connect to the HttpListener should now fail.
using (var client = new HttpClient())
{
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetStringAsync(factory.ListeningUrl));
}
// Even though the listener has no prefixes, it should still be listening.
Assert.True(listener.IsListening);
}
}

Expand Down

0 comments on commit 02eac65

Please sign in to comment.