Skip to content

Commit

Permalink
Add unit test for custom port handling
Browse files Browse the repository at this point in the history
Add a unit test to verify custom handling of ports and schemes works as intended.
  • Loading branch information
martincostello committed Mar 11, 2018
1 parent 54c1018 commit 8348da1
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,54 @@ public static async Task Using_The_Same_Builder_For_Multiple_Registrations_On_Th
await HttpAssert.GetAsync(options, "https://api.github.com:443/orgs/justeat");
}

[Fact]
public static async Task Using_The_Same_Builder_For_Multiple_Registrations_With_Custom_Ports()
{
// Arrange
var options = new HttpClientInterceptorOptions()
{
ThrowOnMissingRegistration = true
};

var builder = new HttpRequestInterceptionBuilder()
.ForPort(123)
.ForHttps()
.ForHost("api.github.com")
.ForPath("orgs/justeat")
.RegisterWith(options);

// Change to a different scheme without changing the port
builder = builder
.ForHttp()
.RegisterWith(options);

// Change the port and not the scheme
builder = builder
.ForPort(456)
.RegisterWith(options);

// Change the scheme and use an explicit port
builder = builder
.ForHttps()
.ForPort(443)
.RegisterWith(options);

// Restore default scheme and port
builder = builder
.ForHttp()
.ForPort(-1)
.RegisterWith(options);

// Act and Assert
await HttpAssert.GetAsync(options, "https://api.github.com:123/orgs/justeat");
await HttpAssert.GetAsync(options, "http://api.github.com:123/orgs/justeat");
await HttpAssert.GetAsync(options, "http://api.github.com:456/orgs/justeat");
await HttpAssert.GetAsync(options, "https://api.github.com/orgs/justeat");
await HttpAssert.GetAsync(options, "https://api.github.com:443/orgs/justeat");
await HttpAssert.GetAsync(options, "http://api.github.com/orgs/justeat");
await HttpAssert.GetAsync(options, "http://api.github.com:80/orgs/justeat");
}

private sealed class CustomObject
{
internal enum Color
Expand Down

0 comments on commit 8348da1

Please sign in to comment.