forked from ThreeMammals/Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpstreamHeaderRoutingOptionsCreatorTests.cs
71 lines (63 loc) · 2.59 KB
/
UpstreamHeaderRoutingOptionsCreatorTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using System.Linq;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration;
using Xunit;
using TestStack.BDDfy;
using Shouldly;
namespace Ocelot.UnitTests.Configuration
{
public class UpstreamHeaderRoutingOptionsCreatorTests
{
private FileUpstreamHeaderRoutingOptions _fileUpstreamHeaderRoutingOptions;
private IUpstreamHeaderRoutingOptionsCreator _creator;
private UpstreamHeaderRoutingOptions _upstreamHeaderRoutingOptions;
public UpstreamHeaderRoutingOptionsCreatorTests()
{
_creator = new UpstreamHeaderRoutingOptionsCreator();
}
[Fact]
public void should_create_upstream_routing_header_options()
{
UpstreamHeaderRoutingOptions expected = new UpstreamHeaderRoutingOptions(
headers: new Dictionary<string, HashSet<string>>()
{
{ "header1", new HashSet<string>() { "value1", "value2" }},
{ "header2", new HashSet<string>() { "value3" }},
},
mode: UpstreamHeaderRoutingCombinationMode.All
);
this.Given(_ => GivenTheseFileUpstreamHeaderRoutingOptions())
.When(_ => WhenICreate())
.Then(_ => ThenTheCreatedMatchesThis(expected))
.BDDfy();
}
private void GivenTheseFileUpstreamHeaderRoutingOptions()
{
_fileUpstreamHeaderRoutingOptions = new FileUpstreamHeaderRoutingOptions()
{
Headers = new Dictionary<string, List<string>>()
{
{ "Header1", new List<string>() { "Value1", "Value2" }},
{ "Header2", new List<string>() { "Value3" }},
},
CombinationMode = "all",
};
}
private void WhenICreate()
{
_upstreamHeaderRoutingOptions = _creator.Create(_fileUpstreamHeaderRoutingOptions);
}
private void ThenTheCreatedMatchesThis(UpstreamHeaderRoutingOptions expected)
{
_upstreamHeaderRoutingOptions.Headers.Headers.Count.ShouldBe(expected.Headers.Headers.Count);
foreach (KeyValuePair<string, HashSet<string>> pair in _upstreamHeaderRoutingOptions.Headers.Headers)
{
expected.Headers.Headers.TryGetValue(pair.Key, out var expectedValue).ShouldBe(true);
expectedValue.SetEquals(pair.Value).ShouldBe(true);
}
_upstreamHeaderRoutingOptions.Mode.ShouldBe(expected.Mode);
}
}
}