diff --git a/src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandler.cs b/src/Ocelot.Library/Authentication/AuthenticationHandler.cs similarity index 78% rename from src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandler.cs rename to src/Ocelot.Library/Authentication/AuthenticationHandler.cs index 3830e33a..8a2a505e 100644 --- a/src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandler.cs +++ b/src/Ocelot.Library/Authentication/AuthenticationHandler.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Http; - -namespace Ocelot.Library.Infrastructure.Authentication +namespace Ocelot.Library.Authentication { + using Microsoft.AspNetCore.Http; + public class AuthenticationHandler { public AuthenticationHandler(string provider, RequestDelegate handler) diff --git a/src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandlerCreator.cs b/src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandlerCreator.cs rename to src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs index ef0f9722..fd49bf7d 100644 --- a/src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandlerCreator.cs +++ b/src/Ocelot.Library/Authentication/AuthenticationHandlerCreator.cs @@ -1,11 +1,11 @@ -using IdentityServer4.AccessTokenValidation; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Responses; -using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions; - -namespace Ocelot.Library.Infrastructure.Authentication +namespace Ocelot.Library.Authentication { + using IdentityServer4.AccessTokenValidation; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Http; + using Responses; + using AuthenticationOptions = Configuration.AuthenticationOptions; + /// /// Cannot unit test things in this class due to use of extension methods /// diff --git a/src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandlerFactory.cs b/src/Ocelot.Library/Authentication/AuthenticationHandlerFactory.cs similarity index 75% rename from src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandlerFactory.cs rename to src/Ocelot.Library/Authentication/AuthenticationHandlerFactory.cs index 1f606938..109d750e 100644 --- a/src/Ocelot.Library/Infrastructure/Authentication/AuthenticationHandlerFactory.cs +++ b/src/Ocelot.Library/Authentication/AuthenticationHandlerFactory.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Builder; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; -using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions; - -namespace Ocelot.Library.Infrastructure.Authentication +namespace Ocelot.Library.Authentication { + using System.Collections.Generic; + using Errors; + using Microsoft.AspNetCore.Builder; + using Responses; + using AuthenticationOptions = Configuration.AuthenticationOptions; + public class AuthenticationHandlerFactory : IAuthenticationHandlerFactory { private readonly IAuthenticationHandlerCreator _creator; diff --git a/src/Ocelot.Library/Authentication/IAuthenticationHandlerCreator.cs b/src/Ocelot.Library/Authentication/IAuthenticationHandlerCreator.cs new file mode 100644 index 00000000..5789ecf6 --- /dev/null +++ b/src/Ocelot.Library/Authentication/IAuthenticationHandlerCreator.cs @@ -0,0 +1,12 @@ +namespace Ocelot.Library.Authentication +{ + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Http; + using Responses; + using AuthenticationOptions = Configuration.AuthenticationOptions; + + public interface IAuthenticationHandlerCreator + { + Response CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions); + } +} diff --git a/src/Ocelot.Library/Authentication/IAuthenticationHandlerFactory.cs b/src/Ocelot.Library/Authentication/IAuthenticationHandlerFactory.cs new file mode 100644 index 00000000..ea583487 --- /dev/null +++ b/src/Ocelot.Library/Authentication/IAuthenticationHandlerFactory.cs @@ -0,0 +1,11 @@ +namespace Ocelot.Library.Authentication +{ + using Microsoft.AspNetCore.Builder; + using Responses; + using AuthenticationOptions = Configuration.AuthenticationOptions; + + public interface IAuthenticationHandlerFactory + { + Response Get(IApplicationBuilder app, AuthenticationOptions authOptions); + } +} diff --git a/src/Ocelot.Library/Infrastructure/Authentication/SupportAuthenticationProviders.cs b/src/Ocelot.Library/Authentication/SupportAuthenticationProviders.cs similarity index 59% rename from src/Ocelot.Library/Infrastructure/Authentication/SupportAuthenticationProviders.cs rename to src/Ocelot.Library/Authentication/SupportAuthenticationProviders.cs index 01ff98d0..e9eea91b 100644 --- a/src/Ocelot.Library/Infrastructure/Authentication/SupportAuthenticationProviders.cs +++ b/src/Ocelot.Library/Authentication/SupportAuthenticationProviders.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Authentication +namespace Ocelot.Library.Authentication { public enum SupportAuthenticationProviders { diff --git a/src/Ocelot.Library/Infrastructure/Authentication/UnableToCreateAuthenticationHandlerError.cs b/src/Ocelot.Library/Authentication/UnableToCreateAuthenticationHandlerError.cs similarity index 71% rename from src/Ocelot.Library/Infrastructure/Authentication/UnableToCreateAuthenticationHandlerError.cs rename to src/Ocelot.Library/Authentication/UnableToCreateAuthenticationHandlerError.cs index 5637ef73..bcda8ef6 100644 --- a/src/Ocelot.Library/Infrastructure/Authentication/UnableToCreateAuthenticationHandlerError.cs +++ b/src/Ocelot.Library/Authentication/UnableToCreateAuthenticationHandlerError.cs @@ -1,7 +1,7 @@ -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Authentication +namespace Ocelot.Library.Authentication { + using Errors; + public class UnableToCreateAuthenticationHandlerError : Error { public UnableToCreateAuthenticationHandlerError(string message) diff --git a/src/Ocelot.Library/Infrastructure/Builder/ReRouteBuilder.cs b/src/Ocelot.Library/Builder/ReRouteBuilder.cs similarity index 96% rename from src/Ocelot.Library/Infrastructure/Builder/ReRouteBuilder.cs rename to src/Ocelot.Library/Builder/ReRouteBuilder.cs index ee01b7d6..c4ff124a 100644 --- a/src/Ocelot.Library/Infrastructure/Builder/ReRouteBuilder.cs +++ b/src/Ocelot.Library/Builder/ReRouteBuilder.cs @@ -1,7 +1,6 @@ -using System.Collections.Generic; - -namespace Ocelot.Library.Infrastructure.Builder +namespace Ocelot.Library.Builder { + using System.Collections.Generic; using Configuration; public class ReRouteBuilder diff --git a/src/Ocelot.Library/Infrastructure/Configuration/AuthenticationOptions.cs b/src/Ocelot.Library/Configuration/AuthenticationOptions.cs similarity index 90% rename from src/Ocelot.Library/Infrastructure/Configuration/AuthenticationOptions.cs rename to src/Ocelot.Library/Configuration/AuthenticationOptions.cs index 9cda2672..99105c4a 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/AuthenticationOptions.cs +++ b/src/Ocelot.Library/Configuration/AuthenticationOptions.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; - -namespace Ocelot.Library.Infrastructure.Configuration +namespace Ocelot.Library.Configuration { + using System.Collections.Generic; + public class AuthenticationOptions { public AuthenticationOptions(string provider, string providerRootUrl, string scopeName, bool requireHttps, List additionalScopes, string scopeSecret) diff --git a/src/Ocelot.Library/Infrastructure/Configuration/IOcelotConfiguration.cs b/src/Ocelot.Library/Configuration/IOcelotConfiguration.cs similarity index 52% rename from src/Ocelot.Library/Infrastructure/Configuration/IOcelotConfiguration.cs rename to src/Ocelot.Library/Configuration/IOcelotConfiguration.cs index 837edbaf..0e7de3c7 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/IOcelotConfiguration.cs +++ b/src/Ocelot.Library/Configuration/IOcelotConfiguration.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; - -namespace Ocelot.Library.Infrastructure.Configuration +namespace Ocelot.Library.Configuration { + using System.Collections.Generic; + public interface IOcelotConfiguration { List ReRoutes { get; } diff --git a/src/Ocelot.Library/Infrastructure/Configuration/OcelotConfiguration.cs b/src/Ocelot.Library/Configuration/OcelotConfiguration.cs similarity index 95% rename from src/Ocelot.Library/Infrastructure/Configuration/OcelotConfiguration.cs rename to src/Ocelot.Library/Configuration/OcelotConfiguration.cs index afa768d2..b49f193a 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/OcelotConfiguration.cs +++ b/src/Ocelot.Library/Configuration/OcelotConfiguration.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using Microsoft.Extensions.Options; -using Ocelot.Library.Infrastructure.Configuration.Yaml; - -namespace Ocelot.Library.Infrastructure.Configuration +namespace Ocelot.Library.Configuration { + using System.Collections.Generic; + using Microsoft.Extensions.Options; + using Yaml; + public class OcelotConfiguration : IOcelotConfiguration { private readonly IOptions _options; diff --git a/src/Ocelot.Library/Infrastructure/Configuration/ReRoute.cs b/src/Ocelot.Library/Configuration/ReRoute.cs similarity index 94% rename from src/Ocelot.Library/Infrastructure/Configuration/ReRoute.cs rename to src/Ocelot.Library/Configuration/ReRoute.cs index 12dfd1b2..8e73a689 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/ReRoute.cs +++ b/src/Ocelot.Library/Configuration/ReRoute.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Configuration +namespace Ocelot.Library.Configuration { public class ReRoute { diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/ConfigurationValidationResult.cs b/src/Ocelot.Library/Configuration/Yaml/ConfigurationValidationResult.cs similarity index 72% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/ConfigurationValidationResult.cs rename to src/Ocelot.Library/Configuration/Yaml/ConfigurationValidationResult.cs index 577fe18c..31b6e1dc 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/ConfigurationValidationResult.cs +++ b/src/Ocelot.Library/Configuration/Yaml/ConfigurationValidationResult.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using System.Collections.Generic; + using Errors; + public class ConfigurationValidationResult { public ConfigurationValidationResult(bool isError) diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/ConfigurationValidator.cs b/src/Ocelot.Library/Configuration/Yaml/ConfigurationValidator.cs similarity index 91% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/ConfigurationValidator.cs rename to src/Ocelot.Library/Configuration/Yaml/ConfigurationValidator.cs index 6c7aee98..38964f30 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/ConfigurationValidator.cs +++ b/src/Ocelot.Library/Configuration/Yaml/ConfigurationValidator.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Ocelot.Library.Infrastructure.Authentication; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using System; + using System.Collections.Generic; + using System.Linq; + using Authentication; + using Errors; + using Responses; + public class ConfigurationValidator : IConfigurationValidator { public Response IsValid(YamlConfiguration configuration) diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/DownstreamTemplateAlreadyUsedError.cs b/src/Ocelot.Library/Configuration/Yaml/DownstreamTemplateAlreadyUsedError.cs similarity index 60% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/DownstreamTemplateAlreadyUsedError.cs rename to src/Ocelot.Library/Configuration/Yaml/DownstreamTemplateAlreadyUsedError.cs index 533f1bb3..0ee8b6c8 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/DownstreamTemplateAlreadyUsedError.cs +++ b/src/Ocelot.Library/Configuration/Yaml/DownstreamTemplateAlreadyUsedError.cs @@ -1,8 +1,7 @@ -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using Errors; + public class DownstreamTemplateAlreadyUsedError : Error { public DownstreamTemplateAlreadyUsedError(string message) : base(message, OcelotErrorCode.DownstreamTemplateAlreadyUsedError) diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/IConfigurationValidator.cs b/src/Ocelot.Library/Configuration/Yaml/IConfigurationValidator.cs similarity index 58% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/IConfigurationValidator.cs rename to src/Ocelot.Library/Configuration/Yaml/IConfigurationValidator.cs index dd491928..38baf36b 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/IConfigurationValidator.cs +++ b/src/Ocelot.Library/Configuration/Yaml/IConfigurationValidator.cs @@ -1,7 +1,7 @@ -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using Responses; + public interface IConfigurationValidator { Response IsValid(YamlConfiguration configuration); diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/UnsupportedAuthenticationProviderError.cs b/src/Ocelot.Library/Configuration/Yaml/UnsupportedAuthenticationProviderError.cs similarity index 70% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/UnsupportedAuthenticationProviderError.cs rename to src/Ocelot.Library/Configuration/Yaml/UnsupportedAuthenticationProviderError.cs index 1964ef80..9a589ca2 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/UnsupportedAuthenticationProviderError.cs +++ b/src/Ocelot.Library/Configuration/Yaml/UnsupportedAuthenticationProviderError.cs @@ -1,7 +1,7 @@ -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using Errors; + public class UnsupportedAuthenticationProviderError : Error { public UnsupportedAuthenticationProviderError(string message) diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlAuthenticationOptions.cs b/src/Ocelot.Library/Configuration/Yaml/YamlAuthenticationOptions.cs similarity index 78% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlAuthenticationOptions.cs rename to src/Ocelot.Library/Configuration/Yaml/YamlAuthenticationOptions.cs index 463a75f5..2e9e9b27 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlAuthenticationOptions.cs +++ b/src/Ocelot.Library/Configuration/Yaml/YamlAuthenticationOptions.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using System.Collections.Generic; + public class YamlAuthenticationOptions { public string Provider { get; set; } diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlConfiguration.cs b/src/Ocelot.Library/Configuration/Yaml/YamlConfiguration.cs similarity index 68% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlConfiguration.cs rename to src/Ocelot.Library/Configuration/Yaml/YamlConfiguration.cs index 69a7eb7a..dd6fb081 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlConfiguration.cs +++ b/src/Ocelot.Library/Configuration/Yaml/YamlConfiguration.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; - -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { + using System.Collections.Generic; + public class YamlConfiguration { public YamlConfiguration() diff --git a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlReRoute.cs b/src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs similarity index 82% rename from src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlReRoute.cs rename to src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs index 26c1569b..0b7be040 100644 --- a/src/Ocelot.Library/Infrastructure/Configuration/Yaml/YamlReRoute.cs +++ b/src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Configuration.Yaml +namespace Ocelot.Library.Configuration.Yaml { public class YamlReRoute { diff --git a/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs new file mode 100644 index 00000000..ad627355 --- /dev/null +++ b/src/Ocelot.Library/DependencyInjection/ServiceCollectionExtensions.cs @@ -0,0 +1,44 @@ +namespace Ocelot.Library.DependencyInjection +{ + using Authentication; + using Configuration; + using Configuration.Yaml; + using DownstreamRouteFinder; + using Microsoft.AspNetCore.Http; + using Microsoft.Extensions.Configuration; + using Microsoft.Extensions.DependencyInjection; + using Repository; + using RequestBuilder; + using Requester; + using Responder; + using UrlMatcher; + using UrlTemplateReplacer; + + public static class ServiceCollectionExtensions + { + public static IServiceCollection AddOcelot(this IServiceCollection services, IConfigurationRoot configurationRoot) + { + services.Configure(configurationRoot); + + // Add framework services. + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + + // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc + services.AddSingleton(); + services.AddScoped(); + + return services; + } + } +} diff --git a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/DownstreamRoute.cs b/src/Ocelot.Library/DownstreamRouteFinder/DownstreamRoute.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/DownstreamRoute.cs rename to src/Ocelot.Library/DownstreamRouteFinder/DownstreamRoute.cs index 8d8cd074..ca80f270 100644 --- a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/DownstreamRoute.cs +++ b/src/Ocelot.Library/DownstreamRouteFinder/DownstreamRoute.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.UrlMatcher; - -namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder +namespace Ocelot.Library.DownstreamRouteFinder { + using System.Collections.Generic; using Configuration; + using UrlMatcher; public class DownstreamRoute { diff --git a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/DownstreamRouteFinder.cs b/src/Ocelot.Library/DownstreamRouteFinder/DownstreamRouteFinder.cs similarity index 82% rename from src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/DownstreamRouteFinder.cs rename to src/Ocelot.Library/DownstreamRouteFinder/DownstreamRouteFinder.cs index 4d58b549..5962f808 100644 --- a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/DownstreamRouteFinder.cs +++ b/src/Ocelot.Library/DownstreamRouteFinder/DownstreamRouteFinder.cs @@ -1,14 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Extensions.Options; -using Ocelot.Library.Infrastructure.Configuration; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; -using Ocelot.Library.Infrastructure.UrlMatcher; - -namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder +namespace Ocelot.Library.DownstreamRouteFinder { + using System; + using System.Collections.Generic; + using System.Linq; + using Configuration; + using Errors; + using Responses; + using UrlMatcher; + public class DownstreamRouteFinder : IDownstreamRouteFinder { private readonly IOcelotConfiguration _configuration; diff --git a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/IDownstreamRouteFinder.cs b/src/Ocelot.Library/DownstreamRouteFinder/IDownstreamRouteFinder.cs similarity index 59% rename from src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/IDownstreamRouteFinder.cs rename to src/Ocelot.Library/DownstreamRouteFinder/IDownstreamRouteFinder.cs index 4b8f7105..41e2ffe6 100644 --- a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/IDownstreamRouteFinder.cs +++ b/src/Ocelot.Library/DownstreamRouteFinder/IDownstreamRouteFinder.cs @@ -1,7 +1,7 @@ -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder +namespace Ocelot.Library.DownstreamRouteFinder { + using Responses; + public interface IDownstreamRouteFinder { Response FindDownstreamRoute(string upstreamUrlPath, string upstreamHttpMethod); diff --git a/src/Ocelot.Library/DownstreamRouteFinder/UnableToFindDownstreamRouteError.cs b/src/Ocelot.Library/DownstreamRouteFinder/UnableToFindDownstreamRouteError.cs new file mode 100644 index 00000000..e8aacb7b --- /dev/null +++ b/src/Ocelot.Library/DownstreamRouteFinder/UnableToFindDownstreamRouteError.cs @@ -0,0 +1,11 @@ +namespace Ocelot.Library.DownstreamRouteFinder +{ + using Errors; + + public class UnableToFindDownstreamRouteError : Error + { + public UnableToFindDownstreamRouteError() : base("UnableToFindDownstreamRouteError", OcelotErrorCode.UnableToFindDownstreamRouteError) + { + } + } +} diff --git a/src/Ocelot.Library/Infrastructure/Errors/Error.cs b/src/Ocelot.Library/Errors/Error.cs similarity index 86% rename from src/Ocelot.Library/Infrastructure/Errors/Error.cs rename to src/Ocelot.Library/Errors/Error.cs index 50b27354..4c4d96d5 100644 --- a/src/Ocelot.Library/Infrastructure/Errors/Error.cs +++ b/src/Ocelot.Library/Errors/Error.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Errors +namespace Ocelot.Library.Errors { public abstract class Error { diff --git a/src/Ocelot.Library/Infrastructure/Errors/OcelotErrorCode.cs b/src/Ocelot.Library/Errors/OcelotErrorCode.cs similarity index 88% rename from src/Ocelot.Library/Infrastructure/Errors/OcelotErrorCode.cs rename to src/Ocelot.Library/Errors/OcelotErrorCode.cs index 01ddfa39..dbe58dbe 100644 --- a/src/Ocelot.Library/Infrastructure/Errors/OcelotErrorCode.cs +++ b/src/Ocelot.Library/Errors/OcelotErrorCode.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Errors +namespace Ocelot.Library.Errors { public enum OcelotErrorCode { diff --git a/src/Ocelot.Library/Infrastructure/Authentication/IAuthenticationHandlerCreator.cs b/src/Ocelot.Library/Infrastructure/Authentication/IAuthenticationHandlerCreator.cs deleted file mode 100644 index 553386d7..00000000 --- a/src/Ocelot.Library/Infrastructure/Authentication/IAuthenticationHandlerCreator.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Responses; -using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions; - -namespace Ocelot.Library.Infrastructure.Authentication -{ - public interface IAuthenticationHandlerCreator - { - Response CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions); - } -} diff --git a/src/Ocelot.Library/Infrastructure/Authentication/IAuthenticationHandlerFactory.cs b/src/Ocelot.Library/Infrastructure/Authentication/IAuthenticationHandlerFactory.cs deleted file mode 100644 index 87f62346..00000000 --- a/src/Ocelot.Library/Infrastructure/Authentication/IAuthenticationHandlerFactory.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Ocelot.Library.Infrastructure.Responses; -using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions; - -namespace Ocelot.Library.Infrastructure.Authentication -{ - public interface IAuthenticationHandlerFactory - { - Response Get(IApplicationBuilder app, AuthenticationOptions authOptions); - } -} diff --git a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/UnableToFindDownstreamRouteError.cs b/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/UnableToFindDownstreamRouteError.cs deleted file mode 100644 index e0f8d26a..00000000 --- a/src/Ocelot.Library/Infrastructure/DownstreamRouteFinder/UnableToFindDownstreamRouteError.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder -{ - public class UnableToFindDownstreamRouteError : Error - { - public UnableToFindDownstreamRouteError() : base("UnableToFindDownstreamRouteError", OcelotErrorCode.UnableToFindDownstreamRouteError) - { - } - } -} diff --git a/src/Ocelot.Library/Infrastructure/Requester/IHttpRequester.cs b/src/Ocelot.Library/Infrastructure/Requester/IHttpRequester.cs deleted file mode 100644 index eca3875e..00000000 --- a/src/Ocelot.Library/Infrastructure/Requester/IHttpRequester.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Ocelot.Library.Infrastructure.RequestBuilder; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Requester -{ - public interface IHttpRequester - { - Task> GetResponse(Request request); - } -} diff --git a/src/Ocelot.Library/Infrastructure/Responder/IErrorsToHttpStatusCodeMapper.cs b/src/Ocelot.Library/Infrastructure/Responder/IErrorsToHttpStatusCodeMapper.cs deleted file mode 100644 index 21932bdf..00000000 --- a/src/Ocelot.Library/Infrastructure/Responder/IErrorsToHttpStatusCodeMapper.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Responder -{ - public interface IErrorsToHttpStatusCodeMapper - { - Response Map(List errors); - } -} diff --git a/src/Ocelot.Library/Infrastructure/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs b/src/Ocelot.Library/Infrastructure/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs deleted file mode 100644 index 6be56a81..00000000 --- a/src/Ocelot.Library/Infrastructure/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.UrlMatcher -{ - public interface IUrlPathToUrlTemplateMatcher - { - Response Match(string upstreamUrlPath, string upstreamUrlPathTemplate); - } -} \ No newline at end of file diff --git a/src/Ocelot.Library/Infrastructure/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs b/src/Ocelot.Library/Infrastructure/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs deleted file mode 100644 index 3d76671b..00000000 --- a/src/Ocelot.Library/Infrastructure/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Ocelot.Library.Infrastructure.DownstreamRouteFinder; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer -{ - public interface IDownstreamUrlTemplateVariableReplacer - { - Response ReplaceTemplateVariables(DownstreamRoute downstreamRoute); - } -} \ No newline at end of file diff --git a/src/Ocelot.Library/Infrastructure/Middleware/AuthenticationMiddleware.cs b/src/Ocelot.Library/Middleware/AuthenticationMiddleware.cs similarity index 83% rename from src/Ocelot.Library/Infrastructure/Middleware/AuthenticationMiddleware.cs rename to src/Ocelot.Library/Middleware/AuthenticationMiddleware.cs index 89bdd875..4042edca 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/AuthenticationMiddleware.cs +++ b/src/Ocelot.Library/Middleware/AuthenticationMiddleware.cs @@ -1,15 +1,15 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Authentication; -using Ocelot.Library.Infrastructure.Configuration; -using Ocelot.Library.Infrastructure.DownstreamRouteFinder; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Repository; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Collections.Generic; + using System.Threading.Tasks; + using Authentication; + using Configuration; + using DownstreamRouteFinder; + using Errors; + using Microsoft.AspNetCore.Builder; + using Microsoft.AspNetCore.Http; + using Repository; + public class AuthenticationMiddleware : OcelotMiddleware { private readonly RequestDelegate _next; diff --git a/src/Ocelot.Library/Infrastructure/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs rename to src/Ocelot.Library/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs index 43b90856..88b3a678 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs +++ b/src/Ocelot.Library/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Builder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Microsoft.AspNetCore.Builder; + public static class AuthenticationMiddlewareMiddlewareExtensions { public static IApplicationBuilder UseAuthenticationMiddleware(this IApplicationBuilder builder) diff --git a/src/Ocelot.Library/Middleware/ClaimsParserMiddleware.cs b/src/Ocelot.Library/Middleware/ClaimsParserMiddleware.cs new file mode 100644 index 00000000..553b6970 --- /dev/null +++ b/src/Ocelot.Library/Middleware/ClaimsParserMiddleware.cs @@ -0,0 +1,23 @@ +namespace Ocelot.Library.Middleware +{ + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Repository; + + public class ClaimsParserMiddleware : OcelotMiddleware + { + private readonly RequestDelegate _next; + + public ClaimsParserMiddleware(RequestDelegate next, IScopedRequestDataRepository scopedRequestDataRepository) + : base(scopedRequestDataRepository) + { + _next = next; + } + + public async Task Invoke(HttpContext context) + { + + await _next.Invoke(context); + } + } +} diff --git a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs similarity index 85% rename from src/Ocelot.Library/Infrastructure/Middleware/DownstreamRouteFinderMiddleware.cs rename to src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs index 1537ab45..f83e88ce 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddleware.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.DownstreamRouteFinder; -using Ocelot.Library.Infrastructure.Repository; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Threading.Tasks; + using DownstreamRouteFinder; + using Microsoft.AspNetCore.Http; + using Repository; + public class DownstreamRouteFinderMiddleware : OcelotMiddleware { private readonly RequestDelegate _next; diff --git a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs rename to src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs index 7f23d1de..b288d789 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs +++ b/src/Ocelot.Library/Middleware/DownstreamRouteFinderMiddlewareExtensions.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Builder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Microsoft.AspNetCore.Builder; + public static class DownstreamRouteFinderMiddlewareExtensions { public static IApplicationBuilder UseDownstreamRouteFinderMiddleware(this IApplicationBuilder builder) diff --git a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamUrlCreatorMiddleware.cs b/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs similarity index 83% rename from src/Ocelot.Library/Infrastructure/Middleware/DownstreamUrlCreatorMiddleware.cs rename to src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs index 955e983a..64ca55cc 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamUrlCreatorMiddleware.cs +++ b/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddleware.cs @@ -1,11 +1,11 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.DownstreamRouteFinder; -using Ocelot.Library.Infrastructure.Repository; -using Ocelot.Library.Infrastructure.UrlTemplateReplacer; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Threading.Tasks; + using DownstreamRouteFinder; + using Microsoft.AspNetCore.Http; + using Repository; + using UrlTemplateReplacer; + public class DownstreamUrlCreatorMiddleware : OcelotMiddleware { private readonly RequestDelegate _next; diff --git a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs rename to src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs index b0997b7b..19839eb2 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs +++ b/src/Ocelot.Library/Middleware/DownstreamUrlCreatorMiddlewareExtensions.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Builder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Microsoft.AspNetCore.Builder; + public static class DownstreamUrlCreatorMiddlewareExtensions { public static IApplicationBuilder UseDownstreamUrlCreatorMiddleware(this IApplicationBuilder builder) diff --git a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequestBuilderMiddleware.cs b/src/Ocelot.Library/Middleware/HttpRequestBuilderMiddleware.cs similarity index 87% rename from src/Ocelot.Library/Infrastructure/Middleware/HttpRequestBuilderMiddleware.cs rename to src/Ocelot.Library/Middleware/HttpRequestBuilderMiddleware.cs index aa2c4017..f60f72d9 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequestBuilderMiddleware.cs +++ b/src/Ocelot.Library/Middleware/HttpRequestBuilderMiddleware.cs @@ -1,10 +1,10 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Repository; -using Ocelot.Library.Infrastructure.RequestBuilder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Repository; + using RequestBuilder; + public class HttpRequestBuilderMiddleware : OcelotMiddleware { private readonly RequestDelegate _next; diff --git a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequestBuilderMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/HttpRequestBuilderMiddlewareExtensions.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/Middleware/HttpRequestBuilderMiddlewareExtensions.cs rename to src/Ocelot.Library/Middleware/HttpRequestBuilderMiddlewareExtensions.cs index fa36ce01..54877b09 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequestBuilderMiddlewareExtensions.cs +++ b/src/Ocelot.Library/Middleware/HttpRequestBuilderMiddlewareExtensions.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Builder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Microsoft.AspNetCore.Builder; + public static class HttpRequestBuilderMiddlewareExtensions { public static IApplicationBuilder UseHttpRequestBuilderMiddleware(this IApplicationBuilder builder) diff --git a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequesterMiddleware.cs b/src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs similarity index 82% rename from src/Ocelot.Library/Infrastructure/Middleware/HttpRequesterMiddleware.cs rename to src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs index 3cf988e4..f9aac74b 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequesterMiddleware.cs +++ b/src/Ocelot.Library/Middleware/HttpRequesterMiddleware.cs @@ -1,11 +1,11 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Repository; -using Ocelot.Library.Infrastructure.RequestBuilder; -using Ocelot.Library.Infrastructure.Requester; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Repository; + using RequestBuilder; + using Requester; + public class HttpRequesterMiddleware : OcelotMiddleware { private readonly RequestDelegate _next; diff --git a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequesterMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/HttpRequesterMiddlewareExtensions.cs similarity index 75% rename from src/Ocelot.Library/Infrastructure/Middleware/HttpRequesterMiddlewareExtensions.cs rename to src/Ocelot.Library/Middleware/HttpRequesterMiddlewareExtensions.cs index b8b31f40..5ad921f2 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/HttpRequesterMiddlewareExtensions.cs +++ b/src/Ocelot.Library/Middleware/HttpRequesterMiddlewareExtensions.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Builder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Microsoft.AspNetCore.Builder; + public static class HttpRequesterMiddlewareExtensions { public static IApplicationBuilder UseHttpRequesterMiddleware(this IApplicationBuilder builder) diff --git a/src/Ocelot.Library/Infrastructure/Middleware/HttpResponderMiddleware.cs b/src/Ocelot.Library/Middleware/HttpResponderMiddleware.cs similarity index 87% rename from src/Ocelot.Library/Infrastructure/Middleware/HttpResponderMiddleware.cs rename to src/Ocelot.Library/Middleware/HttpResponderMiddleware.cs index 0c8fba3c..7d40e5e6 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/HttpResponderMiddleware.cs +++ b/src/Ocelot.Library/Middleware/HttpResponderMiddleware.cs @@ -1,11 +1,11 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Repository; -using Ocelot.Library.Infrastructure.Responder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Repository; + using Responder; + public class HttpResponderMiddleware : OcelotMiddleware { private readonly RequestDelegate _next; diff --git a/src/Ocelot.Library/Infrastructure/Middleware/HttpResponderMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/HttpResponderMiddlewareExtensions.cs similarity index 75% rename from src/Ocelot.Library/Infrastructure/Middleware/HttpResponderMiddlewareExtensions.cs rename to src/Ocelot.Library/Middleware/HttpResponderMiddlewareExtensions.cs index 30d69ae7..04640d51 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/HttpResponderMiddlewareExtensions.cs +++ b/src/Ocelot.Library/Middleware/HttpResponderMiddlewareExtensions.cs @@ -1,7 +1,7 @@ -using Microsoft.AspNetCore.Builder; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Microsoft.AspNetCore.Builder; + public static class HttpResponderMiddlewareExtensions { public static IApplicationBuilder UseHttpResponderMiddleware(this IApplicationBuilder builder) diff --git a/src/Ocelot.Library/Infrastructure/Middleware/OcelotMiddleware.cs b/src/Ocelot.Library/Middleware/OcelotMiddleware.cs similarity index 80% rename from src/Ocelot.Library/Infrastructure/Middleware/OcelotMiddleware.cs rename to src/Ocelot.Library/Middleware/OcelotMiddleware.cs index 7af593e0..857d8369 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/OcelotMiddleware.cs +++ b/src/Ocelot.Library/Middleware/OcelotMiddleware.cs @@ -1,10 +1,9 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Repository; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using System.Collections.Generic; + using Errors; + using Repository; + public abstract class OcelotMiddleware { private readonly IScopedRequestDataRepository _scopedRequestDataRepository; diff --git a/src/Ocelot.Library/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot.Library/Middleware/OcelotMiddlewareExtensions.cs new file mode 100644 index 00000000..1fc4bbd8 --- /dev/null +++ b/src/Ocelot.Library/Middleware/OcelotMiddlewareExtensions.cs @@ -0,0 +1,24 @@ +namespace Ocelot.Library.Middleware +{ + using Microsoft.AspNetCore.Builder; + + public static class OcelotMiddlewareExtensions + { + public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder) + { + builder.UseHttpResponderMiddleware(); + + builder.UseDownstreamRouteFinderMiddleware(); + + builder.UseAuthenticationMiddleware(); + + builder.UseDownstreamUrlCreatorMiddleware(); + + builder.UseHttpRequestBuilderMiddleware(); + + builder.UseHttpRequesterMiddleware(); + + return builder; + } + } +} diff --git a/src/Ocelot.Library/Infrastructure/Middleware/UnauthenticatedError.cs b/src/Ocelot.Library/Middleware/UnauthenticatedError.cs similarity index 65% rename from src/Ocelot.Library/Infrastructure/Middleware/UnauthenticatedError.cs rename to src/Ocelot.Library/Middleware/UnauthenticatedError.cs index 3a7c3ec6..a8e29033 100644 --- a/src/Ocelot.Library/Infrastructure/Middleware/UnauthenticatedError.cs +++ b/src/Ocelot.Library/Middleware/UnauthenticatedError.cs @@ -1,7 +1,7 @@ -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Middleware +namespace Ocelot.Library.Middleware { + using Errors; + public class UnauthenticatedError : Error { public UnauthenticatedError(string message) : base(message, OcelotErrorCode.UnauthenticatedError) diff --git a/src/Ocelot.Library/Infrastructure/Repository/CannotAddDataError.cs b/src/Ocelot.Library/Repository/CannotAddDataError.cs similarity index 55% rename from src/Ocelot.Library/Infrastructure/Repository/CannotAddDataError.cs rename to src/Ocelot.Library/Repository/CannotAddDataError.cs index 1bc0f26a..f3bd42de 100644 --- a/src/Ocelot.Library/Infrastructure/Repository/CannotAddDataError.cs +++ b/src/Ocelot.Library/Repository/CannotAddDataError.cs @@ -1,8 +1,7 @@ -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Repository +namespace Ocelot.Library.Repository { + using Errors; + public class CannotAddDataError : Error { public CannotAddDataError(string message) : base(message, OcelotErrorCode.CannotAddDataError) diff --git a/src/Ocelot.Library/Infrastructure/Repository/CannotFindDataError.cs b/src/Ocelot.Library/Repository/CannotFindDataError.cs similarity index 56% rename from src/Ocelot.Library/Infrastructure/Repository/CannotFindDataError.cs rename to src/Ocelot.Library/Repository/CannotFindDataError.cs index 08a814f4..b61069b5 100644 --- a/src/Ocelot.Library/Infrastructure/Repository/CannotFindDataError.cs +++ b/src/Ocelot.Library/Repository/CannotFindDataError.cs @@ -1,8 +1,7 @@ -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Repository +namespace Ocelot.Library.Repository { + using Errors; + public class CannotFindDataError : Error { public CannotFindDataError(string message) : base(message, OcelotErrorCode.CannotFindDataError) diff --git a/src/Ocelot.Library/Infrastructure/Repository/IScopedRequestDataRepository.cs b/src/Ocelot.Library/Repository/IScopedRequestDataRepository.cs similarity index 60% rename from src/Ocelot.Library/Infrastructure/Repository/IScopedRequestDataRepository.cs rename to src/Ocelot.Library/Repository/IScopedRequestDataRepository.cs index b88605d6..f8e37133 100644 --- a/src/Ocelot.Library/Infrastructure/Repository/IScopedRequestDataRepository.cs +++ b/src/Ocelot.Library/Repository/IScopedRequestDataRepository.cs @@ -1,7 +1,7 @@ -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Repository +namespace Ocelot.Library.Repository { + using Responses; + public interface IScopedRequestDataRepository { Response Add(string key, T value); diff --git a/src/Ocelot.Library/Infrastructure/Repository/ScopedRequestDataRepository.cs b/src/Ocelot.Library/Repository/ScopedRequestDataRepository.cs similarity index 85% rename from src/Ocelot.Library/Infrastructure/Repository/ScopedRequestDataRepository.cs rename to src/Ocelot.Library/Repository/ScopedRequestDataRepository.cs index 9b41d655..b242617e 100644 --- a/src/Ocelot.Library/Infrastructure/Repository/ScopedRequestDataRepository.cs +++ b/src/Ocelot.Library/Repository/ScopedRequestDataRepository.cs @@ -1,11 +1,11 @@ -using System; -using System.Collections.Generic; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Repository +namespace Ocelot.Library.Repository { + using System; + using System.Collections.Generic; + using Errors; + using Microsoft.AspNetCore.Http; + using Responses; + public class ScopedRequestDataRepository : IScopedRequestDataRepository { private readonly IHttpContextAccessor _httpContextAccessor; diff --git a/src/Ocelot.Library/Infrastructure/RequestBuilder/HttpRequestBuilder.cs b/src/Ocelot.Library/RequestBuilder/HttpRequestBuilder.cs similarity index 88% rename from src/Ocelot.Library/Infrastructure/RequestBuilder/HttpRequestBuilder.cs rename to src/Ocelot.Library/RequestBuilder/HttpRequestBuilder.cs index 2aa6c9e2..d12fec2f 100644 --- a/src/Ocelot.Library/Infrastructure/RequestBuilder/HttpRequestBuilder.cs +++ b/src/Ocelot.Library/RequestBuilder/HttpRequestBuilder.cs @@ -1,14 +1,14 @@ -using System; -using System.IO; -using System.Net; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.RequestBuilder +namespace Ocelot.Library.RequestBuilder { + using System; + using System.IO; + using System.Net; + using System.Net.Http; + using System.Net.Http.Headers; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Responses; + public class HttpRequestBuilder : IRequestBuilder { public async Task> Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers, diff --git a/src/Ocelot.Library/Infrastructure/RequestBuilder/IRequestBuilder.cs b/src/Ocelot.Library/RequestBuilder/IRequestBuilder.cs similarity index 63% rename from src/Ocelot.Library/Infrastructure/RequestBuilder/IRequestBuilder.cs rename to src/Ocelot.Library/RequestBuilder/IRequestBuilder.cs index 296e4442..353d438a 100644 --- a/src/Ocelot.Library/Infrastructure/RequestBuilder/IRequestBuilder.cs +++ b/src/Ocelot.Library/RequestBuilder/IRequestBuilder.cs @@ -1,10 +1,10 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.RequestBuilder +namespace Ocelot.Library.RequestBuilder { + using System.IO; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + using Responses; + public interface IRequestBuilder { Task> Build(string httpMethod, diff --git a/src/Ocelot.Library/Infrastructure/RequestBuilder/Request.cs b/src/Ocelot.Library/RequestBuilder/Request.cs similarity index 80% rename from src/Ocelot.Library/Infrastructure/RequestBuilder/Request.cs rename to src/Ocelot.Library/RequestBuilder/Request.cs index b35abf32..dae1243d 100644 --- a/src/Ocelot.Library/Infrastructure/RequestBuilder/Request.cs +++ b/src/Ocelot.Library/RequestBuilder/Request.cs @@ -1,8 +1,8 @@ -using System.Net; -using System.Net.Http; - -namespace Ocelot.Library.Infrastructure.RequestBuilder +namespace Ocelot.Library.RequestBuilder { + using System.Net; + using System.Net.Http; + public class Request { public Request(HttpRequestMessage httpRequestMessage, CookieContainer cookieContainer) diff --git a/src/Ocelot.Library/Infrastructure/Requester/HttpClientHttpRequester.cs b/src/Ocelot.Library/Requester/HttpClientHttpRequester.cs similarity index 75% rename from src/Ocelot.Library/Infrastructure/Requester/HttpClientHttpRequester.cs rename to src/Ocelot.Library/Requester/HttpClientHttpRequester.cs index 912d7bff..534244b3 100644 --- a/src/Ocelot.Library/Infrastructure/Requester/HttpClientHttpRequester.cs +++ b/src/Ocelot.Library/Requester/HttpClientHttpRequester.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Net.Http; -using System.Threading.Tasks; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.RequestBuilder; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Requester +namespace Ocelot.Library.Requester { + using System; + using System.Collections.Generic; + using System.Net.Http; + using System.Threading.Tasks; + using Errors; + using RequestBuilder; + using Responses; + public class HttpClientHttpRequester : IHttpRequester { public async Task> GetResponse(Request request) diff --git a/src/Ocelot.Library/Requester/IHttpRequester.cs b/src/Ocelot.Library/Requester/IHttpRequester.cs new file mode 100644 index 00000000..8b195fe8 --- /dev/null +++ b/src/Ocelot.Library/Requester/IHttpRequester.cs @@ -0,0 +1,12 @@ +namespace Ocelot.Library.Requester +{ + using System.Net.Http; + using System.Threading.Tasks; + using RequestBuilder; + using Responses; + + public interface IHttpRequester + { + Task> GetResponse(Request request); + } +} diff --git a/src/Ocelot.Library/Infrastructure/Requester/UnableToCompleteRequestError.cs b/src/Ocelot.Library/Requester/UnableToCompleteRequestError.cs similarity index 64% rename from src/Ocelot.Library/Infrastructure/Requester/UnableToCompleteRequestError.cs rename to src/Ocelot.Library/Requester/UnableToCompleteRequestError.cs index 003e84e7..33d3d18e 100644 --- a/src/Ocelot.Library/Infrastructure/Requester/UnableToCompleteRequestError.cs +++ b/src/Ocelot.Library/Requester/UnableToCompleteRequestError.cs @@ -1,9 +1,8 @@ -using System; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Requester +namespace Ocelot.Library.Requester { + using System; + using Errors; + public class UnableToCompleteRequestError : Error { public UnableToCompleteRequestError(Exception exception) diff --git a/src/Ocelot.Library/Infrastructure/Responder/ErrorsToHttpStatusCodeMapper.cs b/src/Ocelot.Library/Responder/ErrorsToHttpStatusCodeMapper.cs similarity index 65% rename from src/Ocelot.Library/Infrastructure/Responder/ErrorsToHttpStatusCodeMapper.cs rename to src/Ocelot.Library/Responder/ErrorsToHttpStatusCodeMapper.cs index 4798343e..902c5ac8 100644 --- a/src/Ocelot.Library/Infrastructure/Responder/ErrorsToHttpStatusCodeMapper.cs +++ b/src/Ocelot.Library/Responder/ErrorsToHttpStatusCodeMapper.cs @@ -1,10 +1,10 @@ -using System.Collections.Generic; -using System.Linq; -using Ocelot.Library.Infrastructure.Errors; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.Responder +namespace Ocelot.Library.Responder { + using System.Collections.Generic; + using System.Linq; + using Errors; + using Responses; + public class ErrorsToHttpStatusCodeMapper : IErrorsToHttpStatusCodeMapper { public Response Map(List errors) diff --git a/src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs b/src/Ocelot.Library/Responder/HttpContextResponder.cs similarity index 88% rename from src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs rename to src/Ocelot.Library/Responder/HttpContextResponder.cs index e5e31fe4..546dd114 100644 --- a/src/Ocelot.Library/Infrastructure/Responder/HttpContextResponder.cs +++ b/src/Ocelot.Library/Responder/HttpContextResponder.cs @@ -1,9 +1,9 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; +namespace Ocelot.Library.Responder +{ + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; -namespace Ocelot.Library.Infrastructure.Responder -{ /// /// Cannot unit test things in this class due to methods not being implemented /// on .net concretes used for testing diff --git a/src/Ocelot.Library/Responder/IErrorsToHttpStatusCodeMapper.cs b/src/Ocelot.Library/Responder/IErrorsToHttpStatusCodeMapper.cs new file mode 100644 index 00000000..507b4b24 --- /dev/null +++ b/src/Ocelot.Library/Responder/IErrorsToHttpStatusCodeMapper.cs @@ -0,0 +1,11 @@ +namespace Ocelot.Library.Responder +{ + using System.Collections.Generic; + using Errors; + using Responses; + + public interface IErrorsToHttpStatusCodeMapper + { + Response Map(List errors); + } +} diff --git a/src/Ocelot.Library/Infrastructure/Responder/IHttpResponder.cs b/src/Ocelot.Library/Responder/IHttpResponder.cs similarity index 62% rename from src/Ocelot.Library/Infrastructure/Responder/IHttpResponder.cs rename to src/Ocelot.Library/Responder/IHttpResponder.cs index 9e18647b..972bb70a 100644 --- a/src/Ocelot.Library/Infrastructure/Responder/IHttpResponder.cs +++ b/src/Ocelot.Library/Responder/IHttpResponder.cs @@ -1,9 +1,9 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; - -namespace Ocelot.Library.Infrastructure.Responder +namespace Ocelot.Library.Responder { + using System.Net.Http; + using System.Threading.Tasks; + using Microsoft.AspNetCore.Http; + public interface IHttpResponder { Task CreateResponse(HttpContext context, HttpResponseMessage response); diff --git a/src/Ocelot.Library/Infrastructure/Responses/ErrorResponse.cs b/src/Ocelot.Library/Responses/ErrorResponse.cs similarity index 52% rename from src/Ocelot.Library/Infrastructure/Responses/ErrorResponse.cs rename to src/Ocelot.Library/Responses/ErrorResponse.cs index 2ceb83a2..b097d961 100644 --- a/src/Ocelot.Library/Infrastructure/Responses/ErrorResponse.cs +++ b/src/Ocelot.Library/Responses/ErrorResponse.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Responses +namespace Ocelot.Library.Responses { + using System.Collections.Generic; + using Errors; + public class ErrorResponse : Response { public ErrorResponse(List errors) : base(errors) diff --git a/src/Ocelot.Library/Infrastructure/Responses/ErrorResponseGeneric.cs b/src/Ocelot.Library/Responses/ErrorResponseGeneric.cs similarity index 53% rename from src/Ocelot.Library/Infrastructure/Responses/ErrorResponseGeneric.cs rename to src/Ocelot.Library/Responses/ErrorResponseGeneric.cs index 86d884c1..c5f8ef0b 100644 --- a/src/Ocelot.Library/Infrastructure/Responses/ErrorResponseGeneric.cs +++ b/src/Ocelot.Library/Responses/ErrorResponseGeneric.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Responses +namespace Ocelot.Library.Responses { + using System.Collections.Generic; + using Errors; + public class ErrorResponse : Response { public ErrorResponse(List errors) : base(errors) diff --git a/src/Ocelot.Library/Infrastructure/Responses/OkResponse.cs b/src/Ocelot.Library/Responses/OkResponse.cs similarity index 67% rename from src/Ocelot.Library/Infrastructure/Responses/OkResponse.cs rename to src/Ocelot.Library/Responses/OkResponse.cs index 0b71f0d0..457afced 100644 --- a/src/Ocelot.Library/Infrastructure/Responses/OkResponse.cs +++ b/src/Ocelot.Library/Responses/OkResponse.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Responses +namespace Ocelot.Library.Responses { public class OkResponse : Response { diff --git a/src/Ocelot.Library/Infrastructure/Responses/OkResponseGeneric.cs b/src/Ocelot.Library/Responses/OkResponseGeneric.cs similarity index 71% rename from src/Ocelot.Library/Infrastructure/Responses/OkResponseGeneric.cs rename to src/Ocelot.Library/Responses/OkResponseGeneric.cs index a18ac11f..d768f62f 100644 --- a/src/Ocelot.Library/Infrastructure/Responses/OkResponseGeneric.cs +++ b/src/Ocelot.Library/Responses/OkResponseGeneric.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.Responses +namespace Ocelot.Library.Responses { public class OkResponse : Response { diff --git a/src/Ocelot.Library/Infrastructure/Responses/Response.cs b/src/Ocelot.Library/Responses/Response.cs similarity index 77% rename from src/Ocelot.Library/Infrastructure/Responses/Response.cs rename to src/Ocelot.Library/Responses/Response.cs index 9818df78..c5628ac4 100644 --- a/src/Ocelot.Library/Infrastructure/Responses/Response.cs +++ b/src/Ocelot.Library/Responses/Response.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Responses +namespace Ocelot.Library.Responses { + using System.Collections.Generic; + using Errors; + public abstract class Response { protected Response() diff --git a/src/Ocelot.Library/Infrastructure/Responses/ResponseGeneric.cs b/src/Ocelot.Library/Responses/ResponseGeneric.cs similarity index 68% rename from src/Ocelot.Library/Infrastructure/Responses/ResponseGeneric.cs rename to src/Ocelot.Library/Responses/ResponseGeneric.cs index 790fe5c1..bcebf865 100644 --- a/src/Ocelot.Library/Infrastructure/Responses/ResponseGeneric.cs +++ b/src/Ocelot.Library/Responses/ResponseGeneric.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Errors; - -namespace Ocelot.Library.Infrastructure.Responses +namespace Ocelot.Library.Responses { + using System.Collections.Generic; + using Errors; + public abstract class Response : Response { protected Response(T data) diff --git a/src/Ocelot.Library/Infrastructure/UrlMatcher/ITemplateVariableNameAndValueFinder.cs b/src/Ocelot.Library/UrlMatcher/ITemplateVariableNameAndValueFinder.cs similarity index 58% rename from src/Ocelot.Library/Infrastructure/UrlMatcher/ITemplateVariableNameAndValueFinder.cs rename to src/Ocelot.Library/UrlMatcher/ITemplateVariableNameAndValueFinder.cs index 3cadce39..ff8bb862 100644 --- a/src/Ocelot.Library/Infrastructure/UrlMatcher/ITemplateVariableNameAndValueFinder.cs +++ b/src/Ocelot.Library/UrlMatcher/ITemplateVariableNameAndValueFinder.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.UrlMatcher +namespace Ocelot.Library.UrlMatcher { + using System.Collections.Generic; + using Responses; + public interface ITemplateVariableNameAndValueFinder { Response> Find(string upstreamUrlPath, string upstreamUrlPathTemplate); diff --git a/src/Ocelot.Library/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs b/src/Ocelot.Library/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs new file mode 100644 index 00000000..996df64c --- /dev/null +++ b/src/Ocelot.Library/UrlMatcher/IUrlPathToUrlTemplateMatcher.cs @@ -0,0 +1,9 @@ +namespace Ocelot.Library.UrlMatcher +{ + using Responses; + + public interface IUrlPathToUrlTemplateMatcher + { + Response Match(string upstreamUrlPath, string upstreamUrlPathTemplate); + } +} \ No newline at end of file diff --git a/src/Ocelot.Library/Infrastructure/UrlMatcher/RegExUrlMatcher.cs b/src/Ocelot.Library/UrlMatcher/RegExUrlMatcher.cs similarity index 75% rename from src/Ocelot.Library/Infrastructure/UrlMatcher/RegExUrlMatcher.cs rename to src/Ocelot.Library/UrlMatcher/RegExUrlMatcher.cs index 55855eca..cfcd209d 100644 --- a/src/Ocelot.Library/Infrastructure/UrlMatcher/RegExUrlMatcher.cs +++ b/src/Ocelot.Library/UrlMatcher/RegExUrlMatcher.cs @@ -1,8 +1,8 @@ -using System.Text.RegularExpressions; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.UrlMatcher +namespace Ocelot.Library.UrlMatcher { + using System.Text.RegularExpressions; + using Responses; + public class RegExUrlMatcher : IUrlPathToUrlTemplateMatcher { public Response Match(string upstreamUrlPath, string upstreamUrlPathTemplate) diff --git a/src/Ocelot.Library/Infrastructure/UrlMatcher/TemplateVariableNameAndValue.cs b/src/Ocelot.Library/UrlMatcher/TemplateVariableNameAndValue.cs similarity index 89% rename from src/Ocelot.Library/Infrastructure/UrlMatcher/TemplateVariableNameAndValue.cs rename to src/Ocelot.Library/UrlMatcher/TemplateVariableNameAndValue.cs index 07935d08..ba81b4fd 100644 --- a/src/Ocelot.Library/Infrastructure/UrlMatcher/TemplateVariableNameAndValue.cs +++ b/src/Ocelot.Library/UrlMatcher/TemplateVariableNameAndValue.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.UrlMatcher +namespace Ocelot.Library.UrlMatcher { public class TemplateVariableNameAndValue { diff --git a/src/Ocelot.Library/Infrastructure/UrlMatcher/TemplateVariableNameAndValueFinder.cs b/src/Ocelot.Library/UrlMatcher/TemplateVariableNameAndValueFinder.cs similarity index 93% rename from src/Ocelot.Library/Infrastructure/UrlMatcher/TemplateVariableNameAndValueFinder.cs rename to src/Ocelot.Library/UrlMatcher/TemplateVariableNameAndValueFinder.cs index 30658afc..34f66095 100644 --- a/src/Ocelot.Library/Infrastructure/UrlMatcher/TemplateVariableNameAndValueFinder.cs +++ b/src/Ocelot.Library/UrlMatcher/TemplateVariableNameAndValueFinder.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.UrlMatcher +namespace Ocelot.Library.UrlMatcher { - public class TemplateVariableNameAndValueFinder : ITemplateVariableNameAndValueFinder + using System.Collections.Generic; + using Responses; + + public class TemplateVariableNameAndValueFinder : ITemplateVariableNameAndValueFinder { public Response> Find(string upstreamUrlPath, string upstreamUrlPathTemplate) { diff --git a/src/Ocelot.Library/Infrastructure/UrlMatcher/UrlMatch.cs b/src/Ocelot.Library/UrlMatcher/UrlMatch.cs similarity index 76% rename from src/Ocelot.Library/Infrastructure/UrlMatcher/UrlMatch.cs rename to src/Ocelot.Library/UrlMatcher/UrlMatch.cs index db569d4a..123b5091 100644 --- a/src/Ocelot.Library/Infrastructure/UrlMatcher/UrlMatch.cs +++ b/src/Ocelot.Library/UrlMatcher/UrlMatch.cs @@ -1,4 +1,4 @@ -namespace Ocelot.Library.Infrastructure.UrlMatcher +namespace Ocelot.Library.UrlMatcher { public class UrlMatch { diff --git a/src/Ocelot.Library/Infrastructure/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs b/src/Ocelot.Library/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs similarity index 78% rename from src/Ocelot.Library/Infrastructure/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs rename to src/Ocelot.Library/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs index 65f8a759..94f1ab24 100644 --- a/src/Ocelot.Library/Infrastructure/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs +++ b/src/Ocelot.Library/UrlTemplateReplacer/DownstreamUrlTemplateVariableReplacer.cs @@ -1,9 +1,9 @@ -using System.Text; -using Ocelot.Library.Infrastructure.DownstreamRouteFinder; -using Ocelot.Library.Infrastructure.Responses; - -namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer +namespace Ocelot.Library.UrlTemplateReplacer { + using System.Text; + using DownstreamRouteFinder; + using Responses; + public class DownstreamUrlTemplateVariableReplacer : IDownstreamUrlTemplateVariableReplacer { public Response ReplaceTemplateVariables(DownstreamRoute downstreamRoute) diff --git a/src/Ocelot.Library/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs b/src/Ocelot.Library/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs new file mode 100644 index 00000000..31c50726 --- /dev/null +++ b/src/Ocelot.Library/UrlTemplateReplacer/IDownstreamUrlPathTemplateVariableReplacer.cs @@ -0,0 +1,10 @@ +namespace Ocelot.Library.UrlTemplateReplacer +{ + using DownstreamRouteFinder; + using Responses; + + public interface IDownstreamUrlTemplateVariableReplacer + { + Response ReplaceTemplateVariables(DownstreamRoute downstreamRoute); + } +} \ No newline at end of file diff --git a/src/Ocelot/Startup.cs b/src/Ocelot/Startup.cs index 1ea234e3..6b7d7973 100644 --- a/src/Ocelot/Startup.cs +++ b/src/Ocelot/Startup.cs @@ -1,26 +1,14 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Configuration.Memory; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Ocelot.Library.Infrastructure.Authentication; -using Ocelot.Library.Infrastructure.Configuration; -using Ocelot.Library.Infrastructure.Configuration.Yaml; -using Ocelot.Library.Infrastructure.DownstreamRouteFinder; -using Ocelot.Library.Infrastructure.Middleware; -using Ocelot.Library.Infrastructure.Repository; -using Ocelot.Library.Infrastructure.RequestBuilder; -using Ocelot.Library.Infrastructure.Requester; -using Ocelot.Library.Infrastructure.Responder; -using Ocelot.Library.Infrastructure.UrlMatcher; -using Ocelot.Library.Infrastructure.UrlTemplateReplacer; namespace Ocelot { + using Library.DependencyInjection; + using Library.Middleware; + public class Startup { public Startup(IHostingEnvironment env) @@ -45,26 +33,7 @@ namespace Ocelot services.AddMvcCore().AddAuthorization().AddJsonFormatters(); services.AddAuthentication(); services.AddLogging(); - - services.Configure(Configuration); - - // Add framework services. - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - - // see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc - services.AddSingleton(); - services.AddScoped(); + services.AddOcelot(Configuration); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -74,17 +43,7 @@ namespace Ocelot loggerFactory.AddDebug(); - app.UseHttpResponderMiddleware(); - - app.UseDownstreamRouteFinderMiddleware(); - - app.UseAuthenticationMiddleware(); - - app.UseDownstreamUrlCreatorMiddleware(); - - app.UseHttpRequestBuilderMiddleware(); - - app.UseHttpRequesterMiddleware(); + app.UseOcelot(); } } } diff --git a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs index b38b70a7..8994e77c 100644 --- a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs @@ -13,7 +13,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.TestHost; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; -using Ocelot.Library.Infrastructure.Configuration.Yaml; using Shouldly; using TestStack.BDDfy; using Xunit; @@ -21,6 +20,9 @@ using YamlDotNet.Serialization; namespace Ocelot.AcceptanceTests { + using System.Security.Claims; + using Library.Configuration.Yaml; + public class AuthenticationTests : IDisposable { private TestServer _ocelotServer; @@ -28,7 +30,7 @@ namespace Ocelot.AcceptanceTests private HttpResponseMessage _response; private readonly string _configurationPath; private StringContent _postContent; - private IWebHost _ocelotBbuilder; + private IWebHost _servicebuilder; // Sadly we need to change this when we update the netcoreapp version to make the test update the config correctly private double _netCoreAppVersion = 1.4; @@ -106,6 +108,42 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } + [Fact] + public void should_return_response_200_using_identity_server() + { + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura")) + .And(x => x.GivenIHaveAToken("http://localhost:51888")) + .And(x => x.GivenThereIsAConfiguration(new YamlConfiguration + { + ReRoutes = new List + { + new YamlReRoute + { + DownstreamTemplate = "http://localhost:51876/", + UpstreamTemplate = "/", + UpstreamHttpMethod = "Get", + AuthenticationOptions = new YamlAuthenticationOptions + { + AdditionalScopes = new List(), + Provider = "IdentityServer", + ProviderRootUrl = "http://localhost:51888", + RequireHttps = false, + ScopeName = "api", + ScopeSecret = "secret" + } + } + } + })) + .And(x => x.GivenTheApiGatewayIsRunning()) + .And(x => x.GivenIHaveAddedATokenToMyRequest()) + .When(x => x.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura")) + .BDDfy(); + } + [Fact] public void should_return_201_using_identity_server_access_token() { @@ -176,6 +214,21 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } + private void WhenIGetUrlOnTheApiGateway(string url) + { + _response = _ocelotClient.GetAsync(url).Result; + } + + private void WhenIPostUrlOnTheApiGateway(string url) + { + _response = _ocelotClient.PostAsync(url, _postContent).Result; + } + + private void ThenTheResponseBodyShouldBe(string expectedBody) + { + _response.Content.ReadAsStringAsync().Result.ShouldBe(expectedBody); + } + private void GivenThePostHasContent(string postcontent) { _postContent = new StringContent(postcontent); @@ -209,7 +262,7 @@ namespace Ocelot.AcceptanceTests private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody) { - _ocelotBbuilder = new WebHostBuilder() + _servicebuilder = new WebHostBuilder() .UseUrls(url) .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) @@ -225,7 +278,7 @@ namespace Ocelot.AcceptanceTests }) .Build(); - _ocelotBbuilder.Start(); + _servicebuilder.Start(); } private void GivenThereIsAnIdentityServerOn(string url, string scopeName, AccessTokenType tokenType) @@ -240,41 +293,52 @@ namespace Ocelot.AcceptanceTests { services.AddLogging(); services.AddDeveloperIdentityServer() - .AddInMemoryScopes(new List { new Scope - { - Name = scopeName, - Description = "My API", - Enabled = true, - AllowUnrestrictedIntrospection = true, - ScopeSecrets = new List() + .AddInMemoryScopes(new List { - new Secret + new Scope { - Value = "secret".Sha256() + Name = scopeName, + Description = "My API", + Enabled = true, + AllowUnrestrictedIntrospection = true, + ScopeSecrets = new List() + { + new Secret + { + Value = "secret".Sha256() + } + } + }, + + StandardScopes.OpenId, + StandardScopes.OfflineAccess + }) + .AddInMemoryClients(new List + { + new Client + { + ClientId = "client", + AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, + ClientSecrets = new List {new Secret("secret".Sha256())}, + AllowedScopes = new List { scopeName, "openid", "offline_access" }, + AccessTokenType = tokenType, + Enabled = true, + RequireClientSecret = false } - } - }}) - .AddInMemoryClients(new List { - new Client - { - ClientId = "client", - AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, - ClientSecrets = new List { new Secret("secret".Sha256()) }, - AllowedScopes = new List { scopeName }, - AccessTokenType = tokenType, - Enabled = true, - RequireClientSecret = false - } }) - .AddInMemoryUsers(new List { new InMemoryUser - { - Username = "test", - Password = "test", - Enabled = true, - Subject = "asdads" - }}); + }) + .AddInMemoryUsers(new List + { + new InMemoryUser + { + Username = "test", + Password = "test", + Enabled = true, + Subject = "asdads" + } + }); }) .Configure(app => - { + { app.UseIdentityServer(); }) .Build(); @@ -322,11 +386,6 @@ namespace Ocelot.AcceptanceTests _ocelotClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken); } - private void WhenIPostUrlOnTheApiGateway(string url) - { - _response = _ocelotClient.PostAsync(url, _postContent).Result; - } - private void ThenTheStatusCodeShouldBe(HttpStatusCode expectedHttpStatusCode) { _response.StatusCode.ShouldBe(expectedHttpStatusCode); @@ -334,7 +393,7 @@ namespace Ocelot.AcceptanceTests public void Dispose() { - _ocelotBbuilder?.Dispose(); + _servicebuilder?.Dispose(); _ocelotClient?.Dispose(); _ocelotServer?.Dispose(); _identityServerBuilder?.Dispose(); diff --git a/test/Ocelot.AcceptanceTests/OcelotTests.cs b/test/Ocelot.AcceptanceTests/OcelotTests.cs index 2f4fb53b..8caf3e17 100644 --- a/test/Ocelot.AcceptanceTests/OcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/OcelotTests.cs @@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.TestHost; -using Ocelot.Library.Infrastructure.Configuration.Yaml; using Shouldly; using TestStack.BDDfy; using Xunit; @@ -15,6 +14,8 @@ using YamlDotNet.Serialization; namespace Ocelot.AcceptanceTests { + using Library.Configuration.Yaml; + public class OcelotTests : IDisposable { private TestServer _server; diff --git a/test/Ocelot.UnitTests/Authentication/AuthenticationHandlerFactoryTests.cs b/test/Ocelot.UnitTests/Authentication/AuthenticationHandlerFactoryTests.cs index 1e2f6d42..fb6311c6 100644 --- a/test/Ocelot.UnitTests/Authentication/AuthenticationHandlerFactoryTests.cs +++ b/test/Ocelot.UnitTests/Authentication/AuthenticationHandlerFactoryTests.cs @@ -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 _app; private readonly Mock _creator; - private Library.Infrastructure.Configuration.AuthenticationOptions _authenticationOptions; + private AuthenticationOptions _authenticationOptions; private Response _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(), ""))) + this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "","",false, new List(), ""))) .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(), ""))) + this.Given(x => x.GivenTheAuthenticationOptionsAre(new AuthenticationOptions("IdentityServer", "", "", false, new List(), ""))) .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(), It.IsAny())) + .Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny(), It.IsAny())) .Returns(new ErrorResponse(new List { 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(), It.IsAny())) + .Setup(x => x.CreateIdentityServerAuthenticationHandler(It.IsAny(), It.IsAny())) .Returns(new OkResponse(x => Task.CompletedTask)); } diff --git a/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs b/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs index b797a9bf..a9650451 100644 --- a/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs +++ b/test/Ocelot.UnitTests/Configuration/ConfigurationValidationTests.cs @@ -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; diff --git a/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs b/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs index bfbeee98..f1601a41 100644 --- a/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs +++ b/test/Ocelot.UnitTests/Configuration/OcelotConfigurationTests.cs @@ -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> _yamlConfig; diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index 5a2a73cd..0f979b18 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -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(); _mockMatcher = new Mock(); _finder = new Mock(); - _downstreamRouteFinder = new Library.Infrastructure.DownstreamRouteFinder.DownstreamRouteFinder(_mockConfig.Object, _mockMatcher.Object, _finder.Object); + _downstreamRouteFinder = new DownstreamRouteFinder(_mockConfig.Object, _mockMatcher.Object, _finder.Object); } [Fact] diff --git a/test/Ocelot.UnitTests/Middleware/AuthenticationMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/AuthenticationMiddlewareTests.cs index 3adf0c61..b9350cce 100644 --- a/test/Ocelot.UnitTests/Middleware/AuthenticationMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/AuthenticationMiddlewareTests.cs @@ -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 { diff --git a/test/Ocelot.UnitTests/Middleware/DownstreamRouteFinderMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/DownstreamRouteFinderMiddlewareTests.cs index 07ca69e4..894852d8 100644 --- a/test/Ocelot.UnitTests/Middleware/DownstreamRouteFinderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/DownstreamRouteFinderMiddlewareTests.cs @@ -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 _downstreamRouteFinder; diff --git a/test/Ocelot.UnitTests/Middleware/DownstreamUrlCreatorMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/DownstreamUrlCreatorMiddlewareTests.cs index b1d165ba..f97766d9 100644 --- a/test/Ocelot.UnitTests/Middleware/DownstreamUrlCreatorMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/DownstreamUrlCreatorMiddlewareTests.cs @@ -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; diff --git a/test/Ocelot.UnitTests/Middleware/HttpRequestBuilderMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/HttpRequestBuilderMiddlewareTests.cs index 2a483330..9704fc6b 100644 --- a/test/Ocelot.UnitTests/Middleware/HttpRequestBuilderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/HttpRequestBuilderMiddlewareTests.cs @@ -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 _requestBuilder; diff --git a/test/Ocelot.UnitTests/Middleware/HttpRequesterMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/HttpRequesterMiddlewareTests.cs index a2e24133..99cf1691 100644 --- a/test/Ocelot.UnitTests/Middleware/HttpRequesterMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/HttpRequesterMiddlewareTests.cs @@ -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 _requester; diff --git a/test/Ocelot.UnitTests/Middleware/HttpResponderMiddlewareTests.cs b/test/Ocelot.UnitTests/Middleware/HttpResponderMiddlewareTests.cs index e8f6ef10..f4648700 100644 --- a/test/Ocelot.UnitTests/Middleware/HttpResponderMiddlewareTests.cs +++ b/test/Ocelot.UnitTests/Middleware/HttpResponderMiddlewareTests.cs @@ -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 _responder; diff --git a/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs b/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs index 3236521d..9e688a30 100644 --- a/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Repository/ScopedRequestDataRepositoryTests.cs @@ -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; diff --git a/test/Ocelot.UnitTests/RequestBuilder/RequestBuilderTests.cs b/test/Ocelot.UnitTests/RequestBuilder/RequestBuilderTests.cs index ad11ae2a..80740e97 100644 --- a/test/Ocelot.UnitTests/RequestBuilder/RequestBuilderTests.cs +++ b/test/Ocelot.UnitTests/RequestBuilder/RequestBuilderTests.cs @@ -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] diff --git a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs index cc976b6d..fdd48842 100644 --- a/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs +++ b/test/Ocelot.UnitTests/Responder/ErrorsToHttpStatusCodeMapperTests.cs @@ -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; diff --git a/test/Ocelot.UnitTests/UrlMatcher/RegExUrlMatcherTests.cs b/test/Ocelot.UnitTests/UrlMatcher/RegExUrlMatcherTests.cs index 5774c573..392df6e2 100644 --- a/test/Ocelot.UnitTests/UrlMatcher/RegExUrlMatcherTests.cs +++ b/test/Ocelot.UnitTests/UrlMatcher/RegExUrlMatcherTests.cs @@ -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; diff --git a/test/Ocelot.UnitTests/UrlMatcher/TemplateVariableNameAndValueFinderTests.cs b/test/Ocelot.UnitTests/UrlMatcher/TemplateVariableNameAndValueFinderTests.cs index 6f7f4d7f..3bb3b428 100644 --- a/test/Ocelot.UnitTests/UrlMatcher/TemplateVariableNameAndValueFinderTests.cs +++ b/test/Ocelot.UnitTests/UrlMatcher/TemplateVariableNameAndValueFinderTests.cs @@ -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; diff --git a/test/Ocelot.UnitTests/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs b/test/Ocelot.UnitTests/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs index 961341c9..85f65d48 100644 --- a/test/Ocelot.UnitTests/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs +++ b/test/Ocelot.UnitTests/UrlTemplateReplacer/UpstreamUrlPathTemplateVariableReplacerTests.cs @@ -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 {