forked from ThreeMammals/Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public interface IVersionPolicyCreator | ||
{ | ||
HttpVersionPolicy Create(string downstreamVersionPolicy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Net.Http; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public class VersionPolicyCreator : IVersionPolicyCreator | ||
{ | ||
public HttpVersionPolicy Create(string downstreamVersionPolicy) | ||
{ | ||
return downstreamVersionPolicy switch | ||
{ | ||
"exact" => HttpVersionPolicy.RequestVersionExact, | ||
"upgradeable" => HttpVersionPolicy.RequestVersionOrHigher, | ||
"downgradeable" => HttpVersionPolicy.RequestVersionOrLower, | ||
_ => HttpVersionPolicy.RequestVersionOrLower, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
test/Ocelot.UnitTests/Configuration/VersionPolicyCreatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Ocelot.Configuration.Creator; | ||
using System.Net.Http; | ||
using Shouldly; | ||
using TestStack.BDDfy; | ||
using Xunit; | ||
|
||
namespace Ocelot.UnitTests.Configuration | ||
{ | ||
public class VersionPolicyCreatorTests | ||
{ | ||
private readonly VersionPolicyCreator _creator; | ||
private string _input; | ||
private HttpVersionPolicy _result; | ||
|
||
public VersionPolicyCreatorTests() | ||
{ | ||
_creator = new VersionPolicyCreator(); | ||
} | ||
|
||
[Fact] | ||
public void should_create_version_policy_based_on_input() | ||
{ | ||
this.Given(_ => GivenTheInput("upgradeable")) | ||
.When(_ => WhenICreate()) | ||
.Then(_ => ThenTheResultIs(HttpVersionPolicy.RequestVersionOrHigher)) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void should_default_to_request_version_or_lower() | ||
{ | ||
this.Given(_ => GivenTheInput(string.Empty)) | ||
.When(_ => WhenICreate()) | ||
.Then(_ => ThenTheResultIs(HttpVersionPolicy.RequestVersionOrLower)) | ||
.BDDfy(); | ||
} | ||
|
||
[Fact] | ||
public void should_default_to_request_version_or_lower_when_setting_gibberish() | ||
{ | ||
this.Given(_ => GivenTheInput("string is gibberish")) | ||
.When(_ => WhenICreate()) | ||
.Then(_ => ThenTheResultIs(HttpVersionPolicy.RequestVersionOrLower)) | ||
.BDDfy(); | ||
} | ||
|
||
private void GivenTheInput(string input) | ||
{ | ||
_input = input; | ||
} | ||
|
||
private void WhenICreate() | ||
{ | ||
_result = _creator.Create(_input); | ||
} | ||
|
||
private void ThenTheResultIs(HttpVersionPolicy result) | ||
{ | ||
_result.ShouldBe(result); | ||
} | ||
} | ||
} |