renamed and removed some stuff that wasnt needed

This commit is contained in:
TomPallister
2016-10-18 16:22:51 +01:00
parent 84256e7bac
commit 707f1d6908
19 changed files with 87 additions and 107 deletions

View File

@ -16,7 +16,7 @@ namespace Ocelot.AcceptanceTests
{
using Library.Configuration.Yaml;
public class OcelotTests : IDisposable
public class RoutingTests : IDisposable
{
private TestServer _server;
private HttpClient _client;
@ -28,7 +28,7 @@ namespace Ocelot.AcceptanceTests
// Sadly we need to change this when we update the netcoreapp version to make the test update the config correctly
private double _netCoreAppVersion = 1.4;
public OcelotTests()
public RoutingTests()
{
_configurationPath = $"./bin/Debug/netcoreapp{_netCoreAppVersion}/configuration.yaml";
}

View File

@ -20,13 +20,13 @@ namespace Ocelot.UnitTests.Configuration
private readonly Mock<IConfigurationValidator> _validator;
private OcelotConfiguration _config;
private YamlConfiguration _yamlConfiguration;
private readonly Mock<IConfigurationHeaderExtrator> _configExtractor;
private readonly Mock<IClaimToHeaderConfigurationParser> _configExtractor;
private readonly Mock<ILogger<OcelotConfiguration>> _logger;
public OcelotConfigurationTests()
{
_logger = new Mock<ILogger<OcelotConfiguration>>();
_configExtractor = new Mock<IConfigurationHeaderExtrator>();
_configExtractor = new Mock<IClaimToHeaderConfigurationParser>();
_validator = new Mock<IConfigurationValidator>();
_yamlConfig = new Mock<IOptions<YamlConfiguration>>();
}
@ -75,9 +75,9 @@ namespace Ocelot.UnitTests.Configuration
.WithRequireHttps(false)
.WithScopeSecret("secret")
.WithAuthenticationProviderScopeName("api")
.WithConfigurationHeaderExtractorProperties(new List<ConfigurationHeaderExtractorProperties>
.WithConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
{
new ConfigurationHeaderExtractorProperties("CustomerId", "CustomerId", "", 0),
new ClaimToHeader("CustomerId", "CustomerId", "", 0),
})
.Build()
};
@ -108,18 +108,18 @@ namespace Ocelot.UnitTests.Configuration
}
}))
.And(x => x.GivenTheYamlConfigIsValid())
.And(x => x.GivenTheConfigHeaderExtractorReturns(new ConfigurationHeaderExtractorProperties("CustomerId", "CustomerId", "", 0)))
.And(x => x.GivenTheConfigHeaderExtractorReturns(new ClaimToHeader("CustomerId", "CustomerId", "", 0)))
.When(x => x.WhenIInstanciateTheOcelotConfig())
.Then(x => x.ThenTheReRoutesAre(expected))
.And(x => x.ThenTheAuthenticationOptionsAre(expected))
.BDDfy();
}
private void GivenTheConfigHeaderExtractorReturns(ConfigurationHeaderExtractorProperties expected)
private void GivenTheConfigHeaderExtractorReturns(ClaimToHeader expected)
{
_configExtractor
.Setup(x => x.Extract(It.IsAny<string>(), It.IsAny<string>()))
.Returns(new OkResponse<ConfigurationHeaderExtractorProperties>(expected));
.Returns(new OkResponse<ClaimToHeader>(expected));
}
[Fact]

View File

@ -8,6 +8,7 @@ using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Builder;
using Ocelot.Library.Configuration;
using Ocelot.Library.DownstreamRouteFinder;
using Ocelot.Library.Middleware;
using Ocelot.Library.Repository;
@ -60,9 +61,9 @@ namespace Ocelot.UnitTests.Middleware
var downstreamRoute = new DownstreamRoute(new List<TemplateVariableNameAndValue>(),
new ReRouteBuilder()
.WithDownstreamTemplate("any old string")
.WithConfigurationHeaderExtractorProperties(new List<ConfigurationHeaderExtractorProperties>
.WithConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
{
new ConfigurationHeaderExtractorProperties("UserId", "Subject", "", 0)
new ClaimToHeader("UserId", "Subject", "", 0)
})
.Build());
@ -76,7 +77,7 @@ namespace Ocelot.UnitTests.Middleware
private void GivenTheAddHeadersToRequestReturns(string claimValue)
{
_addHeaders
.Setup(x => x.SetHeadersOnContext(It.IsAny<List<ConfigurationHeaderExtractorProperties>>(),
.Setup(x => x.SetHeadersOnContext(It.IsAny<List<ClaimToHeader>>(),
It.IsAny<HttpContext>()))
.Returns(new OkResponse());
}
@ -84,7 +85,7 @@ namespace Ocelot.UnitTests.Middleware
private void ThenTheAddHeadersToRequestIsCalledCorrectly()
{
_addHeaders
.Verify(x => x.SetHeadersOnContext(It.IsAny<List<ConfigurationHeaderExtractorProperties>>(),
.Verify(x => x.SetHeadersOnContext(It.IsAny<List<ClaimToHeader>>(),
It.IsAny<HttpContext>()), Times.Once);
}

View File

@ -4,6 +4,7 @@ using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
using Moq;
using Ocelot.Library.Configuration;
using Ocelot.Library.Errors;
using Ocelot.Library.RequestBuilder;
using Ocelot.Library.Responses;
@ -17,7 +18,7 @@ namespace Ocelot.UnitTests.RequestBuilder
{
private readonly AddHeadersToRequest _addHeadersToRequest;
private readonly Mock<IClaimsParser> _parser;
private List<ConfigurationHeaderExtractorProperties> _configuration;
private List<ClaimToHeader> _configuration;
private HttpContext _context;
private Response _result;
private Response<string> _claimValue;
@ -40,9 +41,9 @@ namespace Ocelot.UnitTests.RequestBuilder
};
this.Given(
x => x.GivenConfigurationHeaderExtractorProperties(new List<ConfigurationHeaderExtractorProperties>
x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
{
new ConfigurationHeaderExtractorProperties("header-key", "", "", 0)
new ClaimToHeader("header-key", "", "", 0)
}))
.Given(x => x.GivenHttpContext(context))
.And(x => x.GivenTheClaimParserReturns(new OkResponse<string>("value")))
@ -66,9 +67,9 @@ namespace Ocelot.UnitTests.RequestBuilder
context.Request.Headers.Add("header-key", new StringValues("initial"));
this.Given(
x => x.GivenConfigurationHeaderExtractorProperties(new List<ConfigurationHeaderExtractorProperties>
x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
{
new ConfigurationHeaderExtractorProperties("header-key", "", "", 0)
new ClaimToHeader("header-key", "", "", 0)
}))
.Given(x => x.GivenHttpContext(context))
.And(x => x.GivenTheClaimParserReturns(new OkResponse<string>("value")))
@ -82,9 +83,9 @@ namespace Ocelot.UnitTests.RequestBuilder
public void should_return_error()
{
this.Given(
x => x.GivenConfigurationHeaderExtractorProperties(new List<ConfigurationHeaderExtractorProperties>
x => x.GivenConfigurationHeaderExtractorProperties(new List<ClaimToHeader>
{
new ConfigurationHeaderExtractorProperties("", "", "", 0)
new ClaimToHeader("", "", "", 0)
}))
.Given(x => x.GivenHttpContext(new DefaultHttpContext()))
.And(x => x.GivenTheClaimParserReturns(new ErrorResponse<string>(new List<Error>
@ -102,7 +103,7 @@ namespace Ocelot.UnitTests.RequestBuilder
header.Value.First().ShouldBe(_claimValue.Data);
}
private void GivenConfigurationHeaderExtractorProperties(List<ConfigurationHeaderExtractorProperties> configuration)
private void GivenConfigurationHeaderExtractorProperties(List<ClaimToHeader> configuration)
{
_configuration = configuration;
}

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Ocelot.Library.Configuration;
using Ocelot.Library.Errors;
using Ocelot.Library.RequestBuilder;
using Ocelot.Library.Responses;
@ -12,12 +13,12 @@ namespace Ocelot.UnitTests.RequestBuilder
public class ConfigurationHeadersExtractorTests
{
private Dictionary<string, string> _dictionary;
private readonly IConfigurationHeaderExtrator _configurationHeaderExtrator;
private Response<ConfigurationHeaderExtractorProperties> _result;
private readonly IClaimToHeaderConfigurationParser _claimToHeaderConfigurationParser;
private Response<ClaimToHeader> _result;
public ConfigurationHeadersExtractorTests()
{
_configurationHeaderExtrator = new ConfigurationHeaderExtrator();
_claimToHeaderConfigurationParser = new ClaimToHeaderConfigurationParser();
}
[Fact]
@ -30,7 +31,7 @@ namespace Ocelot.UnitTests.RequestBuilder
.When(x => x.WhenICallTheExtractor())
.Then(
x =>
x.ThenAnErrorIsReturned(new ErrorResponse<ConfigurationHeaderExtractorProperties>(
x.ThenAnErrorIsReturned(new ErrorResponse<ClaimToHeader>(
new List<Error>
{
new NoInstructionsError(">")
@ -48,7 +49,7 @@ namespace Ocelot.UnitTests.RequestBuilder
.When(x => x.WhenICallTheExtractor())
.Then(
x =>
x.ThenAnErrorIsReturned(new ErrorResponse<ConfigurationHeaderExtractorProperties>(
x.ThenAnErrorIsReturned(new ErrorResponse<ClaimToHeader>(
new List<Error>
{
new InstructionNotForClaimsError()
@ -67,8 +68,8 @@ namespace Ocelot.UnitTests.RequestBuilder
.Then(
x =>
x.ThenTheClaimParserPropertiesAreReturned(
new OkResponse<ConfigurationHeaderExtractorProperties>(
new ConfigurationHeaderExtractorProperties("CustomerId", "CustomerId", "", 0))))
new OkResponse<ClaimToHeader>(
new ClaimToHeader("CustomerId", "CustomerId", "", 0))))
.BDDfy();
}
@ -83,18 +84,18 @@ namespace Ocelot.UnitTests.RequestBuilder
.Then(
x =>
x.ThenTheClaimParserPropertiesAreReturned(
new OkResponse<ConfigurationHeaderExtractorProperties>(
new ConfigurationHeaderExtractorProperties("UserId", "Subject", "|", 0))))
new OkResponse<ClaimToHeader>(
new ClaimToHeader("UserId", "Subject", "|", 0))))
.BDDfy();
}
private void ThenAnErrorIsReturned(Response<ConfigurationHeaderExtractorProperties> expected)
private void ThenAnErrorIsReturned(Response<ClaimToHeader> expected)
{
_result.IsError.ShouldBe(expected.IsError);
_result.Errors[0].ShouldBeOfType(expected.Errors[0].GetType());
}
private void ThenTheClaimParserPropertiesAreReturned(Response<ConfigurationHeaderExtractorProperties> expected)
private void ThenTheClaimParserPropertiesAreReturned(Response<ClaimToHeader> expected)
{
_result.Data.ClaimKey.ShouldBe(expected.Data.ClaimKey);
_result.Data.Delimiter.ShouldBe(expected.Data.Delimiter);
@ -105,7 +106,7 @@ namespace Ocelot.UnitTests.RequestBuilder
private void WhenICallTheExtractor()
{
var first = _dictionary.First();
_result = _configurationHeaderExtrator.Extract(first.Key, first.Value);
_result = _claimToHeaderConfigurationParser.Extract(first.Key, first.Value);
}
private void GivenTheDictionaryIs(Dictionary<string, string> dictionary)