Added a get authentication test, removed the infrastructure name space as it seemed pointless, started thinking about how to pass claims on with the request

This commit is contained in:
tom.pallister
2016-10-17 18:00:36 +01:00
parent ce84ad4fc2
commit 3d60602c7e
97 changed files with 614 additions and 508 deletions

View File

@ -3,21 +3,23 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Moq;
using Ocelot.Library.Infrastructure.Authentication;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Authentication
{
using Library.Authentication;
using Library.Configuration;
using Library.Errors;
using Library.Responses;
public class AuthenticationHandlerFactoryTests
{
private readonly IAuthenticationHandlerFactory _authenticationHandlerFactory;
private readonly Mock<IApplicationBuilder> _app;
private readonly Mock<IAuthenticationHandlerCreator> _creator;
private Library.Infrastructure.Configuration.AuthenticationOptions _authenticationOptions;
private AuthenticationOptions _authenticationOptions;
private Response<AuthenticationHandler> _result;
public AuthenticationHandlerFactoryTests()
@ -30,7 +32,7 @@ namespace Ocelot.UnitTests.Authentication
[Fact]
public void should_return_identity_server_access_token_handler()
{
this.Given(x => x.GivenTheAuthenticationOptionsAre(new Library.Infrastructure.Configuration.AuthenticationOptions("IdentityServer", "","",false, new List<string>(), "")))
this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "","",false, new List<string>(), "")))
.And(x => x.GivenTheCreatorReturns())
.When(x => x.WhenIGetFromTheFactory())
.Then(x => x.ThenTheHandlerIsReturned("IdentityServer"))
@ -40,14 +42,14 @@ namespace Ocelot.UnitTests.Authentication
[Fact]
public void should_return_error_if_cannot_create_handler()
{
this.Given(x => x.GivenTheAuthenticationOptionsAre(new Library.Infrastructure.Configuration.AuthenticationOptions("IdentityServer", "", "", false, new List<string>(), "")))
this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "", "", false, new List<string>(), "")))
.And(x => x.GivenTheCreatorReturnsAnError())
.When(x => x.WhenIGetFromTheFactory())
.Then(x => x.ThenAnErrorResponseIsReturned())
.BDDfy();
}
private void GivenTheAuthenticationOptionsAre(Library.Infrastructure.Configuration.AuthenticationOptions authenticationOptions)
private void GivenTheAuthenticationOptionsAre(AuthenticationOptions authenticationOptions)
{
_authenticationOptions = authenticationOptions;
}
@ -55,7 +57,7 @@ namespace Ocelot.UnitTests.Authentication
private void GivenTheCreatorReturnsAnError()
{
_creator
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<Library.Infrastructure.Configuration.AuthenticationOptions>()))
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<AuthenticationOptions>()))
.Returns(new ErrorResponse<RequestDelegate>(new List<Error>
{
new UnableToCreateAuthenticationHandlerError($"Unable to create authentication handler for xxx")
@ -65,7 +67,7 @@ namespace Ocelot.UnitTests.Authentication
private void GivenTheCreatorReturns()
{
_creator
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<Library.Infrastructure.Configuration.AuthenticationOptions>()))
.Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny<IApplicationBuilder>(), It.IsAny<AuthenticationOptions>()))
.Returns(new OkResponse<RequestDelegate>(x => Task.CompletedTask));
}

View File

@ -1,12 +1,13 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Configuration.Yaml;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Configuration
{
using Library.Configuration.Yaml;
using Library.Responses;
public class ConfigurationValidationTests
{
private YamlConfiguration _yamlConfiguration;

View File

@ -1,16 +1,17 @@
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Moq;
using Ocelot.Library.Infrastructure.Builder;
using Ocelot.Library.Infrastructure.Configuration;
using Ocelot.Library.Infrastructure.Configuration.Yaml;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Configuration
{
using Library.Builder;
using Library.Configuration;
using Library.Configuration.Yaml;
using Library.Responses;
public class OcelotConfigurationTests
{
private readonly Mock<IOptions<YamlConfiguration>> _yamlConfig;

View File

@ -1,16 +1,17 @@
using System.Collections.Generic;
using Moq;
using Ocelot.Library.Infrastructure.Builder;
using Ocelot.Library.Infrastructure.Configuration;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.DownstreamRouteFinder
{
using Library.Builder;
using Library.Configuration;
using Library.DownstreamRouteFinder;
using Library.Responses;
using Library.UrlMatcher;
public class DownstreamRouteFinderTests
{
private readonly IDownstreamRouteFinder _downstreamRouteFinder;
@ -28,7 +29,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
_mockConfig = new Mock<IOcelotConfiguration>();
_mockMatcher = new Mock<IUrlPathToUrlTemplateMatcher>();
_finder = new Mock<ITemplateVariableNameAndValueFinder>();
_downstreamRouteFinder = new Library.Infrastructure.DownstreamRouteFinder.DownstreamRouteFinder(_mockConfig.Object, _mockMatcher.Object, _finder.Object);
_downstreamRouteFinder = new DownstreamRouteFinder(_mockConfig.Object, _mockMatcher.Object, _finder.Object);
}
[Fact]

View File

@ -6,19 +6,18 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Infrastructure.Authentication;
using Ocelot.Library.Infrastructure.Builder;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Middleware
{
using Library.Infrastructure.Configuration;
using Library.Authentication;
using Library.Builder;
using Library.DownstreamRouteFinder;
using Library.Middleware;
using Library.Repository;
using Library.Responses;
using Library.UrlMatcher;
public class AuthenticationMiddlewareTests : IDisposable
{

View File

@ -6,17 +6,18 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Infrastructure.Builder;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Middleware
{
using Library.Builder;
using Library.DownstreamRouteFinder;
using Library.Middleware;
using Library.Repository;
using Library.Responses;
using Library.UrlMatcher;
public class DownstreamRouteFinderMiddlewareTests : IDisposable
{
private readonly Mock<IDownstreamRouteFinder> _downstreamRouteFinder;

View File

@ -1,18 +1,16 @@
using Ocelot.Library.Infrastructure.Builder;
using Ocelot.Library.Infrastructure.Middleware;
namespace Ocelot.UnitTests.Middleware
namespace Ocelot.UnitTests.Middleware
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using Library.Infrastructure.Configuration;
using Library.Infrastructure.DownstreamRouteFinder;
using Library.Infrastructure.Repository;
using Library.Infrastructure.Responses;
using Library.Infrastructure.UrlMatcher;
using Library.Infrastructure.UrlTemplateReplacer;
using Library.Builder;
using Library.DownstreamRouteFinder;
using Library.Middleware;
using Library.Repository;
using Library.Responses;
using Library.UrlMatcher;
using Library.UrlTemplateReplacer;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;

View File

@ -7,15 +7,16 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Responses;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Middleware
{
using Library.Middleware;
using Library.Repository;
using Library.RequestBuilder;
using Library.Responses;
public class HttpRequestBuilderMiddlewareTests : IDisposable
{
private readonly Mock<IRequestBuilder> _requestBuilder;

View File

@ -6,16 +6,17 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Requester;
using Ocelot.Library.Infrastructure.Responses;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Middleware
{
using Library.Middleware;
using Library.Repository;
using Library.RequestBuilder;
using Library.Requester;
using Library.Responses;
public class HttpRequesterMiddlewareTests : IDisposable
{
private readonly Mock<IHttpRequester> _requester;

View File

@ -6,15 +6,16 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.Responder;
using Ocelot.Library.Infrastructure.Responses;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Middleware
{
using Library.Middleware;
using Library.Repository;
using Library.Responder;
using Library.Responses;
public class HttpResponderMiddlewareTests : IDisposable
{
private readonly Mock<IHttpResponder> _responder;

View File

@ -1,12 +1,13 @@
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Repository
{
using Library.Repository;
using Library.Responses;
public class ScopedRequestDataRepositoryTests
{
private IScopedRequestDataRepository _scopedRequestDataRepository;

View File

@ -5,14 +5,15 @@ using System.Net;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.RequestBuilder
{
using Library.RequestBuilder;
using Library.Responses;
public class RequestBuilderTests
{
private string _httpMethod;
@ -28,7 +29,7 @@ namespace Ocelot.UnitTests.RequestBuilder
public RequestBuilderTests()
{
_content = new StringContent(string.Empty);
_requestBuilder = new Library.Infrastructure.RequestBuilder.HttpRequestBuilder();
_requestBuilder = new HttpRequestBuilder();
}
[Fact]

View File

@ -2,16 +2,17 @@
using System.IO;
using System.Net.Http;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Responder;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Responder
{
using Library.Errors;
using Library.Middleware;
using Library.Responder;
using Library.Responses;
public class ErrorsToHttpStatusCodeMapperTests
{
private readonly IErrorsToHttpStatusCodeMapper _codeMapper;

View File

@ -1,11 +1,12 @@
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.UrlMatcher
{
using Library.Responses;
using Library.UrlMatcher;
public class RegExUrlMatcherTests
{
private readonly IUrlPathToUrlTemplateMatcher _urlMatcher;

View File

@ -1,13 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.UrlMatcher
{
using Library.Responses;
using Library.UrlMatcher;
public class UrlPathToUrlTemplateMatcherTests
{
private readonly ITemplateVariableNameAndValueFinder _finder;

View File

@ -1,16 +1,15 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Builder;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.UrlTemplateReplacer
{
using Library.Infrastructure.Configuration;
using Library.Builder;
using Library.DownstreamRouteFinder;
using Library.Responses;
using Library.UrlMatcher;
using Library.UrlTemplateReplacer;
public class UpstreamUrlPathTemplateVariableReplacerTests
{