Skip to content

Commit

Permalink
EOL: test/Ocelot.UnitTests/Configuration/RoutesCreatorTests.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Oct 17, 2024
1 parent d97bd85 commit 3f4c137
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions test/Ocelot.UnitTests/Configuration/RoutesCreatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
using Ocelot.Values;
using Ocelot.Configuration;
using Ocelot.Configuration.Builder;
using Ocelot.Configuration.Creator;
using Ocelot.Configuration.File;
using Ocelot.Values;

namespace Ocelot.UnitTests.Configuration
{
Expand All @@ -25,8 +25,8 @@ public class RoutesCreatorTests : UnitTest
private readonly Mock<IRouteKeyCreator> _rrkCreator;
private readonly Mock<ISecurityOptionsCreator> _soCreator;
private readonly Mock<IVersionCreator> _versionCreator;
private readonly Mock<IVersionPolicyCreator> _versionPolicyCreator;
private readonly Mock<IMetadataCreator> _metadataCreator;
private readonly Mock<IVersionPolicyCreator> _versionPolicyCreator;
private readonly Mock<IMetadataCreator> _metadataCreator;
private FileConfiguration _fileConfig;
private RouteOptions _rro;
private string _requestId;
Expand All @@ -42,8 +42,8 @@ public class RoutesCreatorTests : UnitTest
private List<DownstreamHostAndPort> _dhp;
private LoadBalancerOptions _lbo;
private List<Route> _result;
private Version _expectedVersion;
private HttpVersionPolicy _expectedVersionPolicy;
private Version _expectedVersion;
private HttpVersionPolicy _expectedVersionPolicy;
private Dictionary<string, UpstreamHeaderTemplate> _uht;
private Dictionary<string, string> _expectedMetadata;

Expand All @@ -64,9 +64,9 @@ public RoutesCreatorTests()
_rrkCreator = new Mock<IRouteKeyCreator>();
_soCreator = new Mock<ISecurityOptionsCreator>();
_versionCreator = new Mock<IVersionCreator>();
_versionPolicyCreator = new Mock<IVersionPolicyCreator>();
_versionPolicyCreator = new Mock<IVersionPolicyCreator>();
_uhtpCreator = new Mock<IUpstreamHeaderTemplatePatternCreator>();
_metadataCreator = new Mock<IMetadataCreator>();
_metadataCreator = new Mock<IMetadataCreator>();

_creator = new RoutesCreator(
_cthCreator.Object,
Expand All @@ -83,7 +83,7 @@ public RoutesCreatorTests()
_lboCreator.Object,
_rrkCreator.Object,
_soCreator.Object,
_versionCreator.Object,
_versionCreator.Object,
_versionPolicyCreator.Object,
_uhtpCreator.Object,
_metadataCreator.Object);
Expand Down Expand Up @@ -123,7 +123,7 @@ public void Should_return_routes()
{
{ "e","f" },
},
UpstreamHttpMethod = new List<string> { "GET", "POST" },
UpstreamHttpMethod = new List<string> { "GET", "POST" },
Metadata = new Dictionary<string, string>
{
["foo"] = "bar",
Expand All @@ -149,7 +149,7 @@ public void Should_return_routes()
Metadata = new Dictionary<string, string>
{
["foo"] = "baz",
},
},
},
},
};
Expand All @@ -163,29 +163,29 @@ public void Should_return_routes()
}

[Fact]
public void Should_route_timeout()
public void CreateTimeout_RouteTimeoutIsLessThanGlobalOne_CreatedFromRouteValue()
{
// Arrange
var fileRoute = new FileRoute { Timeout = 10 };
var globalConfiguration = new FileGlobalConfiguration { Timeout = 20 };

// Act
var timeout = _creator.CreateTimeout(fileRoute, globalConfiguration);

// Assert
Assert.Equal(fileRoute.Timeout, timeout);
}

[Fact]
public void Should_global_timeout_when_not_route_timeout()
public void CreateTimeout_NoRouteTimeoutAndHasGlobalTimeout_CreatedFromGlobalValue()
{
// Arrange
var fileRoute = new FileRoute();
var globalConfiguration = new FileGlobalConfiguration { Timeout = 20 };

// Act
var timeout = _creator.CreateTimeout(fileRoute, globalConfiguration);

// Assert
Assert.Equal(globalConfiguration.Timeout, timeout);
}
Expand All @@ -199,7 +199,7 @@ private void ThenTheDependenciesAreCalledCorrectly()
private void GivenTheDependenciesAreSetUpCorrectly()
{
_expectedVersion = new Version("1.1");
_expectedVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
_expectedVersionPolicy = HttpVersionPolicy.RequestVersionOrLower;
_rro = new RouteOptions(false, false, false, false, false);
_requestId = "testy";
_rrk = "besty";
Expand All @@ -215,10 +215,10 @@ private void GivenTheDependenciesAreSetUpCorrectly()
_dhp = new List<DownstreamHostAndPort>();
_lbo = new LoadBalancerOptionsBuilder().Build();
_uht = new Dictionary<string, UpstreamHeaderTemplate>();
_expectedMetadata = new Dictionary<string, string>()
{
["foo"] = "bar",
};
_expectedMetadata = new Dictionary<string, string>()
{
["foo"] = "bar",
};

_rroCreator.Setup(x => x.Create(It.IsAny<FileRoute>())).Returns(_rro);
_ridkCreator.Setup(x => x.Create(It.IsAny<FileRoute>(), It.IsAny<FileGlobalConfiguration>())).Returns(_requestId);
Expand All @@ -234,12 +234,12 @@ private void GivenTheDependenciesAreSetUpCorrectly()
_daCreator.Setup(x => x.Create(It.IsAny<FileRoute>())).Returns(_dhp);
_lboCreator.Setup(x => x.Create(It.IsAny<FileLoadBalancerOptions>())).Returns(_lbo);
_versionCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_expectedVersion);
_versionPolicyCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_expectedVersionPolicy);
_versionPolicyCreator.Setup(x => x.Create(It.IsAny<string>())).Returns(_expectedVersionPolicy);
_uhtpCreator.Setup(x => x.Create(It.IsAny<FileRoute>())).Returns(_uht);
_metadataCreator.Setup(x => x.Create(It.IsAny<IDictionary<string, string>>(), It.IsAny<FileGlobalConfiguration>())).Returns(new MetadataOptions(new FileMetadataOptions
{
Metadata = _expectedMetadata,
}));
}));
}

private void ThenTheRoutesAreCreated()
Expand Down Expand Up @@ -268,7 +268,7 @@ private void WhenICreate()
private void ThenTheRouteIsSet(FileRoute expected, int routeIndex)
{
_result[routeIndex].DownstreamRoute[0].DownstreamHttpVersion.ShouldBe(_expectedVersion);
_result[routeIndex].DownstreamRoute[0].DownstreamHttpVersionPolicy.ShouldBe(_expectedVersionPolicy);
_result[routeIndex].DownstreamRoute[0].DownstreamHttpVersionPolicy.ShouldBe(_expectedVersionPolicy);
_result[routeIndex].DownstreamRoute[0].IsAuthenticated.ShouldBe(_rro.IsAuthenticated);
_result[routeIndex].DownstreamRoute[0].IsAuthorized.ShouldBe(_rro.IsAuthorized);
_result[routeIndex].DownstreamRoute[0].IsCached.ShouldBe(_rro.IsCached);
Expand Down Expand Up @@ -299,7 +299,7 @@ private void ThenTheRouteIsSet(FileRoute expected, int routeIndex)
_result[routeIndex].DownstreamRoute[0].RouteClaimsRequirement.ShouldBe(expected.RouteClaimsRequirement);
_result[routeIndex].DownstreamRoute[0].DownstreamPathTemplate.Value.ShouldBe(expected.DownstreamPathTemplate);
_result[routeIndex].DownstreamRoute[0].Key.ShouldBe(expected.Key);
_result[routeIndex].DownstreamRoute[0].MetadataOptions.Metadata.ShouldBe(_expectedMetadata);
_result[routeIndex].DownstreamRoute[0].MetadataOptions.Metadata.ShouldBe(_expectedMetadata);
_result[routeIndex].UpstreamHttpMethod
.Select(x => x.Method)
.ToList()
Expand Down Expand Up @@ -331,7 +331,7 @@ private void ThenTheDepsAreCalledFor(FileRoute fileRoute, FileGlobalConfiguratio
_hfarCreator.Verify(x => x.Create(fileRoute), Times.Once);
_daCreator.Verify(x => x.Create(fileRoute), Times.Once);
_lboCreator.Verify(x => x.Create(fileRoute.LoadBalancerOptions), Times.Once);
_soCreator.Verify(x => x.Create(fileRoute.SecurityOptions), Times.Once);
_soCreator.Verify(x => x.Create(fileRoute.SecurityOptions), Times.Once);
_metadataCreator.Verify(x => x.Create(fileRoute.Metadata, globalConfig), Times.Once);
}
}
Expand Down

0 comments on commit 3f4c137

Please sign in to comment.