more logging, more readme, more refactoring

This commit is contained in:
TomPallister
2016-11-05 11:36:58 +00:00
parent 8582ba45a9
commit af506b079a
37 changed files with 415 additions and 201 deletions

View File

@ -6,9 +6,9 @@ using System.Security.Claims;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Moq;
using Ocelot.Authorisation;
using Ocelot.Cache.Middleware;
using Ocelot.Configuration.Builder;
using Ocelot.DownstreamRouteFinder;
using Ocelot.DownstreamRouteFinder.UrlMatcher;
@ -31,19 +31,18 @@ namespace Ocelot.UnitTests.Authorization
private readonly HttpClient _client;
private HttpResponseMessage _result;
private OkResponse<DownstreamRoute> _downstreamRoute;
private Mock<IOcelotLoggerFactory> _mockLoggerFactory;
public AuthorisationMiddlewareTests()
{
_url = "http://localhost:51879";
_scopedRepository = new Mock<IRequestScopedDataRepository>();
_authService = new Mock<IAuthoriser>();
SetUpLogger();
var builder = new WebHostBuilder()
.ConfigureServices(x =>
{
x.AddSingleton(_mockLoggerFactory.Object);
x.AddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>();
x.AddLogging();
x.AddSingleton(_authService.Object);
x.AddSingleton(_scopedRepository.Object);
})
@ -62,7 +61,7 @@ namespace Ocelot.UnitTests.Authorization
}
[Fact]
public void happy_path()
public void should_call_authorisation_service()
{
this.Given(x => x.GivenTheDownStreamRouteIs(new DownstreamRoute(new List<UrlPathPlaceholderNameAndValue>(), new ReRouteBuilder().WithIsAuthorised(true).Build())))
.And(x => x.GivenTheAuthServiceReturns(new OkResponse<bool>(true)))
@ -71,17 +70,6 @@ namespace Ocelot.UnitTests.Authorization
.BDDfy();
}
private void SetUpLogger()
{
_mockLoggerFactory = new Mock<IOcelotLoggerFactory>();
var logger = new Mock<IOcelotLogger>();
_mockLoggerFactory
.Setup(x => x.CreateLogger<AuthorisationMiddleware>())
.Returns(logger.Object);
}
private void GivenTheAuthServiceReturns(Response<bool> expected)
{
_authService