mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-05-02 20:22:50 +08:00

* #212 - hacked websockets proxy together * faffing around * #212 hacking away :( * #212 websockets proxy middleware working * #212 map when for webockets working * #212 some test refactor * #212 temp commit * #212 websockets proxy working, tests passing...need to do some tidying and write docs * #212 more code coverage * #212 docs for websockets * #212 updated readme * #212 tidying up after websockets refactoring * #212 tidying up after websockets refactoring * #212 tidying up after websockets refactoring * changing logging levels and logging like ms reccomends with structured data rather than strings * more faffing * more fafin * #287 ocelot logger now only takes strings as it did take params then just turned them to strings, misleading, unit tests for logger and diagnosticlogger * #287 errors now logged as they happen * #287 more detail for logs requested in issue * #287 tidy up * #287 renamed * #287 always log context id * #287 fixed me being an idiot * #287 removed crap websockets unit test that isnt a unit test * #287 removed crap websockets unit test that isnt a unit test
112 lines
3.9 KiB
C#
112 lines
3.9 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Moq;
|
|
using Ocelot.Configuration;
|
|
using Ocelot.Configuration.Creator;
|
|
using Ocelot.Configuration.Parser;
|
|
using Ocelot.Errors;
|
|
using Ocelot.Logging;
|
|
using Ocelot.Responses;
|
|
using Shouldly;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
namespace Ocelot.UnitTests.Configuration
|
|
{
|
|
public class ClaimsToThingCreatorTests
|
|
{
|
|
private readonly Mock<IClaimToThingConfigurationParser> _configParser;
|
|
private Dictionary<string,string> _claimsToThings;
|
|
private ClaimsToThingCreator _claimsToThingsCreator;
|
|
private Mock<IOcelotLoggerFactory> _loggerFactory;
|
|
private List<ClaimToThing> _result;
|
|
private Mock<IOcelotLogger> _logger;
|
|
|
|
public ClaimsToThingCreatorTests()
|
|
{
|
|
_loggerFactory = new Mock<IOcelotLoggerFactory>();
|
|
_logger = new Mock<IOcelotLogger>();
|
|
_loggerFactory
|
|
.Setup(x => x.CreateLogger<ClaimsToThingCreator>())
|
|
.Returns(_logger.Object);
|
|
_configParser = new Mock<IClaimToThingConfigurationParser>();
|
|
_claimsToThingsCreator = new ClaimsToThingCreator(_configParser.Object, _loggerFactory.Object);
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_claims_to_things()
|
|
{
|
|
var userInput = new Dictionary<string,string>()
|
|
{
|
|
{"CustomerId", "Claims[CustomerId] > value"}
|
|
};
|
|
|
|
var claimsToThing = new OkResponse<ClaimToThing>(new ClaimToThing("CustomerId", "CustomerId", "", 0));
|
|
|
|
this.Given(x => x.GivenTheFollowingDictionary(userInput))
|
|
.And(x => x.GivenTheConfigHeaderExtractorReturns(claimsToThing))
|
|
.When(x => x.WhenIGetTheThings())
|
|
.Then(x => x.ThenTheConfigParserIsCalledCorrectly())
|
|
.And(x => x.ThenClaimsToThingsAreReturned())
|
|
.BDDfy();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_log_error_if_cannot_parse_claim_to_thing()
|
|
{
|
|
var userInput = new Dictionary<string,string>()
|
|
{
|
|
{"CustomerId", "Claims[CustomerId] > value"}
|
|
};
|
|
|
|
var claimsToThing = new ErrorResponse<ClaimToThing>(It.IsAny<Error>());
|
|
|
|
this.Given(x => x.GivenTheFollowingDictionary(userInput))
|
|
.And(x => x.GivenTheConfigHeaderExtractorReturns(claimsToThing))
|
|
.When(x => x.WhenIGetTheThings())
|
|
.Then(x => x.ThenTheConfigParserIsCalledCorrectly())
|
|
.And(x => x.ThenNoClaimsToThingsAreReturned())
|
|
.BDDfy();
|
|
}
|
|
|
|
private void ThenTheLoggerIsCalledCorrectly()
|
|
{
|
|
_logger
|
|
.Verify(x => x.LogDebug(It.IsAny<string>()), Times.Once);
|
|
}
|
|
|
|
private void ThenClaimsToThingsAreReturned()
|
|
{
|
|
_result.Count.ShouldBeGreaterThan(0);
|
|
}
|
|
|
|
private void GivenTheFollowingDictionary(Dictionary<string,string> claimsToThings)
|
|
{
|
|
_claimsToThings = claimsToThings;
|
|
}
|
|
|
|
private void GivenTheConfigHeaderExtractorReturns(Response<ClaimToThing> expected)
|
|
{
|
|
_configParser
|
|
.Setup(x => x.Extract(It.IsAny<string>(), It.IsAny<string>()))
|
|
.Returns(expected);
|
|
}
|
|
|
|
private void ThenNoClaimsToThingsAreReturned()
|
|
{
|
|
_result.Count.ShouldBe(0);
|
|
}
|
|
|
|
private void WhenIGetTheThings()
|
|
{
|
|
_result = _claimsToThingsCreator.Create(_claimsToThings);
|
|
}
|
|
|
|
private void ThenTheConfigParserIsCalledCorrectly()
|
|
{
|
|
_configParser
|
|
.Verify(x => x.Extract(_claimsToThings.First().Key, _claimsToThings.First().Value), Times.Once);
|
|
}
|
|
}
|
|
}
|