mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 22:28:15 +08:00
renamed and removed some stuff that wasnt needed
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user