mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 09:48:16 +08:00
reorganised project so its a bit more vertical for features
This commit is contained in:
@ -0,0 +1,117 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ocelot.Library.Configuration;
|
||||
using Ocelot.Library.Configuration.Parser;
|
||||
using Ocelot.Library.Errors;
|
||||
using Ocelot.Library.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
public class ConfigurationHeadersExtractorTests
|
||||
{
|
||||
private Dictionary<string, string> _dictionary;
|
||||
private readonly IClaimToHeaderConfigurationParser _claimToHeaderConfigurationParser;
|
||||
private Response<ClaimToHeader> _result;
|
||||
|
||||
public ConfigurationHeadersExtractorTests()
|
||||
{
|
||||
_claimToHeaderConfigurationParser = new ClaimToHeaderConfigurationParser();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void returns_no_instructions_error()
|
||||
{
|
||||
this.Given(x => x.GivenTheDictionaryIs(new Dictionary<string, string>()
|
||||
{
|
||||
{"CustomerId", ""},
|
||||
}))
|
||||
.When(x => x.WhenICallTheExtractor())
|
||||
.Then(
|
||||
x =>
|
||||
x.ThenAnErrorIsReturned(new ErrorResponse<ClaimToHeader>(
|
||||
new List<Error>
|
||||
{
|
||||
new NoInstructionsError(">")
|
||||
})))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void returns_no_instructions_not_for_claims_error()
|
||||
{
|
||||
this.Given(x => x.GivenTheDictionaryIs(new Dictionary<string, string>()
|
||||
{
|
||||
{"CustomerId", "Cheese[CustomerId] > value"},
|
||||
}))
|
||||
.When(x => x.WhenICallTheExtractor())
|
||||
.Then(
|
||||
x =>
|
||||
x.ThenAnErrorIsReturned(new ErrorResponse<ClaimToHeader>(
|
||||
new List<Error>
|
||||
{
|
||||
new InstructionNotForClaimsError()
|
||||
})))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_parse_entry_to_work_out_properties_with_key()
|
||||
{
|
||||
this.Given(x => x.GivenTheDictionaryIs(new Dictionary<string, string>()
|
||||
{
|
||||
{"CustomerId", "Claims[CustomerId] > value"},
|
||||
}))
|
||||
.When(x => x.WhenICallTheExtractor())
|
||||
.Then(
|
||||
x =>
|
||||
x.ThenTheClaimParserPropertiesAreReturned(
|
||||
new OkResponse<ClaimToHeader>(
|
||||
new ClaimToHeader("CustomerId", "CustomerId", "", 0))))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void can_parse_entry_to_work_out_properties_with_key_delimiter_and_index()
|
||||
{
|
||||
this.Given(x => x.GivenTheDictionaryIs(new Dictionary<string, string>()
|
||||
{
|
||||
{"UserId", "Claims[Subject] > value[0] > |"},
|
||||
}))
|
||||
.When(x => x.WhenICallTheExtractor())
|
||||
.Then(
|
||||
x =>
|
||||
x.ThenTheClaimParserPropertiesAreReturned(
|
||||
new OkResponse<ClaimToHeader>(
|
||||
new ClaimToHeader("UserId", "Subject", "|", 0))))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void ThenAnErrorIsReturned(Response<ClaimToHeader> expected)
|
||||
{
|
||||
_result.IsError.ShouldBe(expected.IsError);
|
||||
_result.Errors[0].ShouldBeOfType(expected.Errors[0].GetType());
|
||||
}
|
||||
|
||||
private void ThenTheClaimParserPropertiesAreReturned(Response<ClaimToHeader> expected)
|
||||
{
|
||||
_result.Data.ClaimKey.ShouldBe(expected.Data.ClaimKey);
|
||||
_result.Data.Delimiter.ShouldBe(expected.Data.Delimiter);
|
||||
_result.Data.Index.ShouldBe(expected.Data.Index);
|
||||
_result.IsError.ShouldBe(expected.IsError);
|
||||
}
|
||||
|
||||
private void WhenICallTheExtractor()
|
||||
{
|
||||
var first = _dictionary.First();
|
||||
_result = _claimToHeaderConfigurationParser.Extract(first.Key, first.Value);
|
||||
}
|
||||
|
||||
private void GivenTheDictionaryIs(Dictionary<string, string> dictionary)
|
||||
{
|
||||
_dictionary = dictionary;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Configuration.Validator;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
@ -3,8 +3,10 @@ using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using Ocelot.Library.Configuration.Builder;
|
||||
using Ocelot.Library.Configuration.Creator;
|
||||
using Ocelot.Library.Configuration.Parser;
|
||||
using Ocelot.Library.Configuration.Repository;
|
||||
using Ocelot.Library.Configuration.Validator;
|
||||
using Ocelot.Library.RequestBuilder;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
|
Reference in New Issue
Block a user