From fe9bca7b77811a47b27d94e3e7f12b3c17670138 Mon Sep 17 00:00:00 2001 From: Tom Pallister Date: Sat, 14 Apr 2018 06:32:00 +0100 Subject: [PATCH] removed another pointless abstraction --- src/Ocelot/Cache/OutputCacheController.cs | 8 +- .../Authentication/HashMatcher.cs | 22 ---- .../Authentication/IHashMatcher.cs | 7 -- .../IdentityServerConfigurationCreator.cs | 3 - .../FileConfigurationController.cs | 24 ++-- .../Provider/FileConfigurationProvider.cs | 23 ---- .../Provider/IFileConfigurationProvider.cs | 11 -- ....cs => DiskFileConfigurationRepository.cs} | 108 +++++++++--------- ...InMemoryInternalConfigurationRepository.cs | 3 +- ... => FileAndInternalConfigurationSetter.cs} | 88 +++++++------- .../DependencyInjection/OcelotBuilder.cs | 10 +- .../DownstreamRouteFinderMiddleware.cs | 2 - src/Ocelot/Raft/FilePeersProvider.cs | 3 - src/Ocelot/Raft/HttpPeer.cs | 16 +-- .../FileConfigurationProviderTests.cs | 60 ---------- .../FileConfigurationRepositoryTests.cs | 4 +- .../FileConfigurationSetterTests.cs | 4 +- .../Configuration/HashMatcherTests.cs | 76 ------------ .../FileConfigurationControllerTests.cs | 28 +++-- .../DownstreamRouteFinderTests.cs | 2 - 20 files changed, 138 insertions(+), 364 deletions(-) delete mode 100644 src/Ocelot/Configuration/Authentication/HashMatcher.cs delete mode 100644 src/Ocelot/Configuration/Authentication/IHashMatcher.cs delete mode 100644 src/Ocelot/Configuration/Provider/FileConfigurationProvider.cs delete mode 100644 src/Ocelot/Configuration/Provider/IFileConfigurationProvider.cs rename src/Ocelot/Configuration/Repository/{FileConfigurationRepository.cs => DiskFileConfigurationRepository.cs} (88%) rename src/Ocelot/Configuration/Setter/{FileConfigurationSetter.cs => FileAndInternalConfigurationSetter.cs} (88%) delete mode 100644 test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs delete mode 100644 test/Ocelot.UnitTests/Configuration/HashMatcherTests.cs diff --git a/src/Ocelot/Cache/OutputCacheController.cs b/src/Ocelot/Cache/OutputCacheController.cs index 32b9fa7c..cc33e8aa 100644 --- a/src/Ocelot/Cache/OutputCacheController.cs +++ b/src/Ocelot/Cache/OutputCacheController.cs @@ -1,9 +1,5 @@ -using System.Net.Http; -using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Ocelot.Cache; -using Ocelot.Configuration.Provider; namespace Ocelot.Cache { @@ -11,7 +7,7 @@ namespace Ocelot.Cache [Route("outputcache")] public class OutputCacheController : Controller { - private IOcelotCache _cache; + private readonly IOcelotCache _cache; public OutputCacheController(IOcelotCache cache) { @@ -26,4 +22,4 @@ namespace Ocelot.Cache return new NoContentResult(); } } -} \ No newline at end of file +} diff --git a/src/Ocelot/Configuration/Authentication/HashMatcher.cs b/src/Ocelot/Configuration/Authentication/HashMatcher.cs deleted file mode 100644 index 5f17362f..00000000 --- a/src/Ocelot/Configuration/Authentication/HashMatcher.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using Microsoft.AspNetCore.Cryptography.KeyDerivation; - -namespace Ocelot.Configuration.Authentication -{ - public class HashMatcher : IHashMatcher - { - public bool Match(string password, string salt, string hash) - { - byte[] s = Convert.FromBase64String(salt); - - string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2( - password: password, - salt: s, - prf: KeyDerivationPrf.HMACSHA256, - iterationCount: 10000, - numBytesRequested: 256 / 8)); - - return hashed == hash; - } - } -} \ No newline at end of file diff --git a/src/Ocelot/Configuration/Authentication/IHashMatcher.cs b/src/Ocelot/Configuration/Authentication/IHashMatcher.cs deleted file mode 100644 index 629bf008..00000000 --- a/src/Ocelot/Configuration/Authentication/IHashMatcher.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Ocelot.Configuration.Authentication -{ - public interface IHashMatcher - { - bool Match(string password, string salt, string hash); - } -} \ No newline at end of file diff --git a/src/Ocelot/Configuration/Creator/IdentityServerConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/IdentityServerConfigurationCreator.cs index 5e7fcd37..8569001e 100644 --- a/src/Ocelot/Configuration/Creator/IdentityServerConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/IdentityServerConfigurationCreator.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using IdentityServer4.AccessTokenValidation; -using IdentityServer4.Models; -using Ocelot.Configuration.Provider; namespace Ocelot.Configuration.Creator { diff --git a/src/Ocelot/Configuration/FileConfigurationController.cs b/src/Ocelot/Configuration/FileConfigurationController.cs index 7bdf4926..707eb61d 100644 --- a/src/Ocelot/Configuration/FileConfigurationController.cs +++ b/src/Ocelot/Configuration/FileConfigurationController.cs @@ -2,34 +2,34 @@ using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.DependencyInjection; using Ocelot.Configuration.File; -using Ocelot.Configuration.Provider; using Ocelot.Configuration.Setter; using Ocelot.Raft; using Rafty.Concensus; namespace Ocelot.Configuration { + using Repository; + [Authorize] [Route("configuration")] public class FileConfigurationController : Controller { - private readonly IFileConfigurationProvider _configGetter; - private readonly IFileConfigurationSetter _configSetter; - private readonly IServiceProvider _serviceProvider; + private readonly IFileConfigurationRepository _repo; + private readonly IFileConfigurationSetter _setter; + private readonly IServiceProvider _provider; - public FileConfigurationController(IFileConfigurationProvider getFileConfig, IFileConfigurationSetter configSetter, IServiceProvider serviceProvider) + public FileConfigurationController(IFileConfigurationRepository repo, IFileConfigurationSetter setter, IServiceProvider provider) { - _configGetter = getFileConfig; - _configSetter = configSetter; - _serviceProvider = serviceProvider; + _repo = repo; + _setter = setter; + _provider = provider; } [HttpGet] public async Task Get() { - var response = await _configGetter.Get(); + var response = await _repo.Get(); if(response.IsError) { @@ -43,7 +43,7 @@ namespace Ocelot.Configuration public async Task Post([FromBody]FileConfiguration fileConfiguration) { //todo - this code is a bit shit sort it out.. - var test = _serviceProvider.GetService(typeof(INode)); + var test = _provider.GetService(typeof(INode)); if (test != null) { var node = (INode)test; @@ -56,7 +56,7 @@ namespace Ocelot.Configuration return new OkObjectResult(result.Command.Configuration); } - var response = await _configSetter.Set(fileConfiguration); + var response = await _setter.Set(fileConfiguration); if (response.IsError) { diff --git a/src/Ocelot/Configuration/Provider/FileConfigurationProvider.cs b/src/Ocelot/Configuration/Provider/FileConfigurationProvider.cs deleted file mode 100644 index 2d4cad8b..00000000 --- a/src/Ocelot/Configuration/Provider/FileConfigurationProvider.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Threading.Tasks; -using Ocelot.Configuration.File; -using Ocelot.Configuration.Repository; -using Ocelot.Responses; - -namespace Ocelot.Configuration.Provider -{ - public class FileConfigurationProvider : IFileConfigurationProvider - { - private readonly IFileConfigurationRepository _repo; - - public FileConfigurationProvider(IFileConfigurationRepository repo) - { - _repo = repo; - } - - public async Task> Get() - { - var fileConfig = await _repo.Get(); - return new OkResponse(fileConfig.Data); - } - } -} diff --git a/src/Ocelot/Configuration/Provider/IFileConfigurationProvider.cs b/src/Ocelot/Configuration/Provider/IFileConfigurationProvider.cs deleted file mode 100644 index c2ab51cb..00000000 --- a/src/Ocelot/Configuration/Provider/IFileConfigurationProvider.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Threading.Tasks; -using Ocelot.Configuration.File; -using Ocelot.Responses; - -namespace Ocelot.Configuration.Provider -{ - public interface IFileConfigurationProvider - { - Task> Get(); - } -} \ No newline at end of file diff --git a/src/Ocelot/Configuration/Repository/FileConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs similarity index 88% rename from src/Ocelot/Configuration/Repository/FileConfigurationRepository.cs rename to src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs index 9619984f..5fb871f4 100644 --- a/src/Ocelot/Configuration/Repository/FileConfigurationRepository.cs +++ b/src/Ocelot/Configuration/Repository/DiskFileConfigurationRepository.cs @@ -1,54 +1,54 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Newtonsoft.Json; -using Ocelot.Configuration.File; -using Ocelot.Responses; - -namespace Ocelot.Configuration.Repository -{ - public class FileConfigurationRepository : IFileConfigurationRepository - { - private readonly string _configFilePath; - - private static readonly object _lock = new object(); - - private const string ConfigurationFileName = "ocelot"; - - public FileConfigurationRepository(IHostingEnvironment hostingEnvironment) - { - _configFilePath = $"{AppContext.BaseDirectory}/{ConfigurationFileName}{(string.IsNullOrEmpty(hostingEnvironment.EnvironmentName) ? string.Empty : ".")}{hostingEnvironment.EnvironmentName}.json"; - } - - public Task> Get() - { - string jsonConfiguration; - - lock(_lock) - { - jsonConfiguration = System.IO.File.ReadAllText(_configFilePath); - } - - var fileConfiguration = JsonConvert.DeserializeObject(jsonConfiguration); - - return Task.FromResult>(new OkResponse(fileConfiguration)); - } - - public Task Set(FileConfiguration fileConfiguration) - { - string jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration); - - lock(_lock) - { - if (System.IO.File.Exists(_configFilePath)) - { - System.IO.File.Delete(_configFilePath); - } - - System.IO.File.WriteAllText(_configFilePath, jsonConfiguration); - } - - return Task.FromResult(new OkResponse()); - } - } -} +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Newtonsoft.Json; +using Ocelot.Configuration.File; +using Ocelot.Responses; + +namespace Ocelot.Configuration.Repository +{ + public class DiskFileConfigurationRepository : IFileConfigurationRepository + { + private readonly string _configFilePath; + + private static readonly object _lock = new object(); + + private const string ConfigurationFileName = "ocelot"; + + public DiskFileConfigurationRepository(IHostingEnvironment hostingEnvironment) + { + _configFilePath = $"{AppContext.BaseDirectory}/{ConfigurationFileName}{(string.IsNullOrEmpty(hostingEnvironment.EnvironmentName) ? string.Empty : ".")}{hostingEnvironment.EnvironmentName}.json"; + } + + public Task> Get() + { + string jsonConfiguration; + + lock(_lock) + { + jsonConfiguration = System.IO.File.ReadAllText(_configFilePath); + } + + var fileConfiguration = JsonConvert.DeserializeObject(jsonConfiguration); + + return Task.FromResult>(new OkResponse(fileConfiguration)); + } + + public Task Set(FileConfiguration fileConfiguration) + { + string jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration); + + lock(_lock) + { + if (System.IO.File.Exists(_configFilePath)) + { + System.IO.File.Delete(_configFilePath); + } + + System.IO.File.WriteAllText(_configFilePath, jsonConfiguration); + } + + return Task.FromResult(new OkResponse()); + } + } +} diff --git a/src/Ocelot/Configuration/Repository/InMemoryInternalConfigurationRepository.cs b/src/Ocelot/Configuration/Repository/InMemoryInternalConfigurationRepository.cs index fcb3baa9..2ac954e3 100644 --- a/src/Ocelot/Configuration/Repository/InMemoryInternalConfigurationRepository.cs +++ b/src/Ocelot/Configuration/Repository/InMemoryInternalConfigurationRepository.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using Ocelot.Responses; +using Ocelot.Responses; namespace Ocelot.Configuration.Repository { diff --git a/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs b/src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs similarity index 88% rename from src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs rename to src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs index ba7b5ce9..6821553e 100644 --- a/src/Ocelot/Configuration/Setter/FileConfigurationSetter.cs +++ b/src/Ocelot/Configuration/Setter/FileAndInternalConfigurationSetter.cs @@ -1,44 +1,44 @@ -using System.Threading.Tasks; -using Ocelot.Configuration.Creator; -using Ocelot.Configuration.File; -using Ocelot.Configuration.Repository; -using Ocelot.Responses; - -namespace Ocelot.Configuration.Setter -{ - public class FileConfigurationSetter : IFileConfigurationSetter - { - private readonly IInternalConfigurationRepository _configRepo; - private readonly IInternalConfigurationCreator _configCreator; - private readonly IFileConfigurationRepository _repo; - - public FileConfigurationSetter( - IInternalConfigurationRepository configRepo, - IInternalConfigurationCreator configCreator, - IFileConfigurationRepository repo) - { - _configRepo = configRepo; - _configCreator = configCreator; - _repo = repo; - } - - public async Task Set(FileConfiguration fileConfig) - { - var response = await _repo.Set(fileConfig); - - if(response.IsError) - { - return new ErrorResponse(response.Errors); - } - - var config = await _configCreator.Create(fileConfig); - - if(!config.IsError) - { - _configRepo.AddOrReplace(config.Data); - } - - return new ErrorResponse(config.Errors); - } - } -} +using System.Threading.Tasks; +using Ocelot.Configuration.Creator; +using Ocelot.Configuration.File; +using Ocelot.Configuration.Repository; +using Ocelot.Responses; + +namespace Ocelot.Configuration.Setter +{ + public class FileAndInternalConfigurationSetter : IFileConfigurationSetter + { + private readonly IInternalConfigurationRepository _configRepo; + private readonly IInternalConfigurationCreator _configCreator; + private readonly IFileConfigurationRepository _repo; + + public FileAndInternalConfigurationSetter( + IInternalConfigurationRepository configRepo, + IInternalConfigurationCreator configCreator, + IFileConfigurationRepository repo) + { + _configRepo = configRepo; + _configCreator = configCreator; + _repo = repo; + } + + public async Task Set(FileConfiguration fileConfig) + { + var response = await _repo.Set(fileConfig); + + if(response.IsError) + { + return new ErrorResponse(response.Errors); + } + + var config = await _configCreator.Create(fileConfig); + + if(!config.IsError) + { + _configRepo.AddOrReplace(config.Data); + } + + return new ErrorResponse(config.Errors); + } + } +} diff --git a/src/Ocelot/DependencyInjection/OcelotBuilder.cs b/src/Ocelot/DependencyInjection/OcelotBuilder.cs index cd70b581..5373cc1b 100644 --- a/src/Ocelot/DependencyInjection/OcelotBuilder.cs +++ b/src/Ocelot/DependencyInjection/OcelotBuilder.cs @@ -8,11 +8,9 @@ namespace Ocelot.DependencyInjection using Ocelot.Authorisation; using Ocelot.Cache; using Ocelot.Claims; - using Ocelot.Configuration.Authentication; using Ocelot.Configuration.Creator; using Ocelot.Configuration.File; using Ocelot.Configuration.Parser; - using Ocelot.Configuration.Provider; using Ocelot.Configuration.Repository; using Ocelot.Configuration.Setter; using Ocelot.Configuration.Validator; @@ -40,8 +38,6 @@ namespace Ocelot.DependencyInjection using IdentityServer4.AccessTokenValidation; using Microsoft.AspNetCore.Builder; using Ocelot.Configuration; - using Ocelot.Configuration.Builder; - using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider; using Microsoft.Extensions.DependencyInjection.Extensions; using System.Net.Http; using Butterfly.Client.AspNetCore; @@ -86,9 +82,8 @@ namespace Ocelot.DependencyInjection _services.TryAddSingleton(); _services.TryAddSingleton(); _services.TryAddSingleton(); - _services.TryAddSingleton(); - _services.TryAddSingleton(); - _services.TryAddSingleton(); + _services.TryAddSingleton(); + _services.TryAddSingleton(); _services.TryAddSingleton(); _services.TryAddSingleton(); _services.TryAddSingleton(); @@ -287,7 +282,6 @@ namespace Ocelot.DependencyInjection private void AddIdentityServer(IIdentityServerConfiguration identityServerConfiguration, IAdministrationPath adminPath) { _services.TryAddSingleton(identityServerConfiguration); - _services.TryAddSingleton(); var identityServerBuilder = _services .AddIdentityServer(o => { o.IssuerUri = "Ocelot"; diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs index ab920fef..970636d3 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs @@ -1,7 +1,5 @@ using System.Threading.Tasks; using System.Linq; -using Ocelot.Configuration; -using Ocelot.Configuration.Provider; using Ocelot.Configuration.Repository; using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.Infrastructure.Extensions; diff --git a/src/Ocelot/Raft/FilePeersProvider.cs b/src/Ocelot/Raft/FilePeersProvider.cs index 7852e80a..52b877df 100644 --- a/src/Ocelot/Raft/FilePeersProvider.cs +++ b/src/Ocelot/Raft/FilePeersProvider.cs @@ -1,10 +1,7 @@ -using System; using System.Collections.Generic; using System.Net.Http; -using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Options; using Ocelot.Configuration; -using Ocelot.Configuration.Provider; using Ocelot.Configuration.Repository; using Ocelot.Middleware; using Rafty.Concensus; diff --git a/src/Ocelot/Raft/HttpPeer.cs b/src/Ocelot/Raft/HttpPeer.cs index dfc580d7..fcec77ea 100644 --- a/src/Ocelot/Raft/HttpPeer.cs +++ b/src/Ocelot/Raft/HttpPeer.cs @@ -1,12 +1,8 @@ using System; using System.Collections.Generic; using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; using Newtonsoft.Json; -using Ocelot.Authentication; using Ocelot.Configuration; -using Ocelot.Configuration.Provider; using Ocelot.Middleware; using Rafty.Concensus; using Rafty.FiniteStateMachine; @@ -16,13 +12,13 @@ namespace Ocelot.Raft [ExcludeFromCoverage] public class HttpPeer : IPeer { - private string _hostAndPort; - private HttpClient _httpClient; - private JsonSerializerSettings _jsonSerializerSettings; - private string _baseSchemeUrlAndPort; + private readonly string _hostAndPort; + private readonly HttpClient _httpClient; + private readonly JsonSerializerSettings _jsonSerializerSettings; + private readonly string _baseSchemeUrlAndPort; private BearerToken _token; - private IInternalConfiguration _config; - private IIdentityServerConfiguration _identityServerConfiguration; + private readonly IInternalConfiguration _config; + private readonly IIdentityServerConfiguration _identityServerConfiguration; public HttpPeer(string hostAndPort, HttpClient httpClient, IBaseUrlFinder finder, IInternalConfiguration config, IIdentityServerConfiguration identityServerConfiguration) { diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs deleted file mode 100644 index 506da50c..00000000 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationProviderTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System; -using System.Collections.Generic; -using Moq; -using Ocelot.Configuration; -using Ocelot.Configuration.File; -using Ocelot.Responses; -using Shouldly; -using TestStack.BDDfy; -using Xunit; -using Newtonsoft.Json; -using System.IO; -using Ocelot.Configuration.Provider; -using Ocelot.Configuration.Repository; - -namespace Ocelot.UnitTests.Configuration -{ - public class FileConfigurationProviderTests - { - private readonly IFileConfigurationProvider _provider; - private Mock _repo; - private FileConfiguration _result; - private FileConfiguration _fileConfiguration; - - public FileConfigurationProviderTests() - { - _repo = new Mock(); - _provider = new FileConfigurationProvider(_repo.Object); - } - - [Fact] - public void should_return_file_configuration() - { - var config = new FileConfiguration(); - - this.Given(x => x.GivenTheConfigurationIs(config)) - .When(x => x.WhenIGetTheReRoutes()) - .Then(x => x.ThenTheRepoIsCalledCorrectly()) - .BDDfy(); - } - - private void GivenTheConfigurationIs(FileConfiguration fileConfiguration) - { - _fileConfiguration = fileConfiguration; - _repo - .Setup(x => x.Get()) - .ReturnsAsync(new OkResponse(fileConfiguration)); - } - - private void WhenIGetTheReRoutes() - { - _result = _provider.Get().Result.Data; - } - - private void ThenTheRepoIsCalledCorrectly() - { - _repo - .Verify(x => x.Get(), Times.Once); - } - } -} diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs index b27015e3..c492af44 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationRepositoryTests.cs @@ -23,7 +23,7 @@ namespace Ocelot.UnitTests.Configuration public FileConfigurationRepositoryTests() { _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName); - _repo = new FileConfigurationRepository(_hostingEnvironment.Object); + _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object); } [Fact] @@ -75,7 +75,7 @@ namespace Ocelot.UnitTests.Configuration { _environmentName = null; _hostingEnvironment.Setup(he => he.EnvironmentName).Returns(_environmentName); - _repo = new FileConfigurationRepository(_hostingEnvironment.Object); + _repo = new DiskFileConfigurationRepository(_hostingEnvironment.Object); } private void GivenIHaveAConfiguration(FileConfiguration fileConfiguration) diff --git a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs index 49a52db2..ff33872c 100644 --- a/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs +++ b/test/Ocelot.UnitTests/Configuration/FileConfigurationSetterTests.cs @@ -18,7 +18,7 @@ namespace Ocelot.UnitTests.Configuration public class FileConfigurationSetterTests { private FileConfiguration _fileConfiguration; - private FileConfigurationSetter _configSetter; + private FileAndInternalConfigurationSetter _configSetter; private Mock _configRepo; private Mock _configCreator; private Response _configuration; @@ -30,7 +30,7 @@ namespace Ocelot.UnitTests.Configuration _repo = new Mock(); _configRepo = new Mock(); _configCreator = new Mock(); - _configSetter = new FileConfigurationSetter(_configRepo.Object, _configCreator.Object, _repo.Object); + _configSetter = new FileAndInternalConfigurationSetter(_configRepo.Object, _configCreator.Object, _repo.Object); } [Fact] diff --git a/test/Ocelot.UnitTests/Configuration/HashMatcherTests.cs b/test/Ocelot.UnitTests/Configuration/HashMatcherTests.cs deleted file mode 100644 index 55c5edc9..00000000 --- a/test/Ocelot.UnitTests/Configuration/HashMatcherTests.cs +++ /dev/null @@ -1,76 +0,0 @@ -using Ocelot.Configuration.Authentication; -using Shouldly; -using TestStack.BDDfy; -using Xunit; - -namespace Ocelot.UnitTests.Configuration -{ - public class HashMatcherTests - { - private string _password; - private string _hash; - private string _salt; - private bool _result; - private HashMatcher _hashMatcher; - - public HashMatcherTests() - { - _hashMatcher = new HashMatcher(); - } - - [Fact] - public void should_match_hash() - { - var hash = "kE/mxd1hO9h9Sl2VhGhwJUd9xZEv4NP6qXoN39nIqM4="; - var salt = "zzWITpnDximUNKYLiUam/w=="; - var password = "secret"; - - this.Given(x => GivenThePassword(password)) - .And(x => GivenTheHash(hash)) - .And(x => GivenTheSalt(salt)) - .When(x => WhenIMatch()) - .Then(x => ThenTheResultIs(true)) - .BDDfy(); - } - - [Fact] - public void should_not_match_hash() - { - var hash = "kE/mxd1hO9h9Sl2VhGhwJUd9xZEv4NP6qXoN39nIqM4="; - var salt = "zzWITpnDximUNKYLiUam/w=="; - var password = "secret1"; - - this.Given(x => GivenThePassword(password)) - .And(x => GivenTheHash(hash)) - .And(x => GivenTheSalt(salt)) - .When(x => WhenIMatch()) - .Then(x => ThenTheResultIs(false)) - .BDDfy(); - } - - private void GivenThePassword(string password) - { - _password = password; - } - - private void GivenTheHash(string hash) - { - _hash = hash; - } - - private void GivenTheSalt(string salt) - { - _salt = salt; - } - - private void WhenIMatch() - { - _result = _hashMatcher.Match(_password, _salt, _hash); - } - - private void ThenTheResultIs(bool expected) - { - _result.ShouldBe(expected); - } - } -} \ No newline at end of file diff --git a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs index c0ae8b87..520d8274 100644 --- a/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs +++ b/test/Ocelot.UnitTests/Controllers/FileConfigurationControllerTests.cs @@ -8,32 +8,30 @@ using Ocelot.Responses; using TestStack.BDDfy; using Xunit; using Shouldly; -using Ocelot.Configuration.Provider; -using Microsoft.Extensions.DependencyInjection; using Ocelot.Raft; using Rafty.Concensus; -using Newtonsoft.Json; -using Rafty.FiniteStateMachine; using Ocelot.Configuration; namespace Ocelot.UnitTests.Controllers { + using Ocelot.Configuration.Repository; + public class FileConfigurationControllerTests { - private FileConfigurationController _controller; - private Mock _configGetter; - private Mock _configSetter; + private readonly FileConfigurationController _controller; + private readonly Mock _repo; + private readonly Mock _setter; private IActionResult _result; private FileConfiguration _fileConfiguration; - private Mock _provider; + private readonly Mock _provider; private Mock _node; public FileConfigurationControllerTests() { _provider = new Mock(); - _configGetter = new Mock(); - _configSetter = new Mock(); - _controller = new FileConfigurationController(_configGetter.Object, _configSetter.Object, _provider.Object); + _repo = new Mock(); + _setter = new Mock(); + _controller = new FileConfigurationController(_repo.Object, _setter.Object, _provider.Object); } [Fact] @@ -140,14 +138,14 @@ namespace Ocelot.UnitTests.Controllers private void GivenTheConfigSetterReturns(Response response) { - _configSetter + _setter .Setup(x => x.Set(It.IsAny())) .ReturnsAsync(response); } private void ThenTheConfigrationSetterIsCalledCorrectly() { - _configSetter + _setter .Verify(x => x.Set(_fileConfiguration), Times.Once); } @@ -168,7 +166,7 @@ namespace Ocelot.UnitTests.Controllers private void GivenTheGetConfigurationReturns(Ocelot.Responses.Response fileConfiguration) { - _configGetter + _repo .Setup(x => x.Get()) .ReturnsAsync(fileConfiguration); } @@ -180,7 +178,7 @@ namespace Ocelot.UnitTests.Controllers private void TheTheGetFileConfigurationIsCalledCorrectly() { - _configGetter + _repo .Verify(x => x.Get(), Times.Once); } diff --git a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs index c17b27d7..7406b1c5 100644 --- a/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs +++ b/test/Ocelot.UnitTests/DownstreamRouteFinder/DownstreamRouteFinderTests.cs @@ -2,8 +2,6 @@ using Moq; using Ocelot.Configuration; using Ocelot.Configuration.Builder; -using Ocelot.Configuration.Creator; -using Ocelot.Configuration.Provider; using Ocelot.DownstreamRouteFinder; using Ocelot.DownstreamRouteFinder.Finder; using Ocelot.DownstreamRouteFinder.UrlMatcher;