removed another pointless abstraction

This commit is contained in:
Tom Pallister
2018-04-14 06:32:00 +01:00
parent fe5662f954
commit fe9bca7b77
20 changed files with 138 additions and 364 deletions

View File

@ -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<IFileConfigurationRepository> _repo;
private FileConfiguration _result;
private FileConfiguration _fileConfiguration;
public FileConfigurationProviderTests()
{
_repo = new Mock<IFileConfigurationRepository>();
_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>(fileConfiguration));
}
private void WhenIGetTheReRoutes()
{
_result = _provider.Get().Result.Data;
}
private void ThenTheRepoIsCalledCorrectly()
{
_repo
.Verify(x => x.Get(), Times.Once);
}
}
}

View File

@ -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)

View File

@ -18,7 +18,7 @@ namespace Ocelot.UnitTests.Configuration
public class FileConfigurationSetterTests
{
private FileConfiguration _fileConfiguration;
private FileConfigurationSetter _configSetter;
private FileAndInternalConfigurationSetter _configSetter;
private Mock<IInternalConfigurationRepository> _configRepo;
private Mock<IInternalConfigurationCreator> _configCreator;
private Response<IInternalConfiguration> _configuration;
@ -30,7 +30,7 @@ namespace Ocelot.UnitTests.Configuration
_repo = new Mock<IFileConfigurationRepository>();
_configRepo = new Mock<IInternalConfigurationRepository>();
_configCreator = new Mock<IInternalConfigurationCreator>();
_configSetter = new FileConfigurationSetter(_configRepo.Object, _configCreator.Object, _repo.Object);
_configSetter = new FileAndInternalConfigurationSetter(_configRepo.Object, _configCreator.Object, _repo.Object);
}
[Fact]

View File

@ -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);
}
}
}

View File

@ -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<IFileConfigurationProvider> _configGetter;
private Mock<IFileConfigurationSetter> _configSetter;
private readonly FileConfigurationController _controller;
private readonly Mock<IFileConfigurationRepository> _repo;
private readonly Mock<IFileConfigurationSetter> _setter;
private IActionResult _result;
private FileConfiguration _fileConfiguration;
private Mock<IServiceProvider> _provider;
private readonly Mock<IServiceProvider> _provider;
private Mock<INode> _node;
public FileConfigurationControllerTests()
{
_provider = new Mock<IServiceProvider>();
_configGetter = new Mock<IFileConfigurationProvider>();
_configSetter = new Mock<IFileConfigurationSetter>();
_controller = new FileConfigurationController(_configGetter.Object, _configSetter.Object, _provider.Object);
_repo = new Mock<IFileConfigurationRepository>();
_setter = new Mock<IFileConfigurationSetter>();
_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<FileConfiguration>()))
.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> 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);
}

View File

@ -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;