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