brought in flurl and stated adding tests for the requester

This commit is contained in:
TomPallister
2016-09-13 20:29:00 +01:00
parent 8423199754
commit 0627e9399b
11 changed files with 163 additions and 38 deletions

View File

@ -0,0 +1,90 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Configuration;
using Ocelot.Library.Infrastructure.Responses;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
namespace Ocelot.UnitTests.Configuration
{
public class ConfigurationValidationTests
{
private Library.Infrastructure.Configuration.Configuration _configuration;
private readonly IConfigurationValidator _configurationValidator;
private Response<ConfigurationValidationResult> _result;
public ConfigurationValidationTests()
{
_configurationValidator = new ConfigurationValidator();
}
[Fact]
public void configuration_is_valid_with_one_reroute()
{
this.Given(x => x.GivenAConfiguration(new Library.Infrastructure.Configuration.Configuration()
{
ReRoutes = new List<ReRoute>
{
new ReRoute
{
DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com"
}
}
}))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsValid())
.BDDfy();
}
[Fact]
public void configuration_is_not_valid_with_duplicate_reroutes()
{
this.Given(x => x.GivenAConfiguration(new Library.Infrastructure.Configuration.Configuration()
{
ReRoutes = new List<ReRoute>
{
new ReRoute
{
DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://asdf.com"
},
new ReRoute
{
DownstreamTemplate = "http://www.bbc.co.uk",
UpstreamTemplate = "http://lol.com"
}
}
}))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsNotValid())
.And(x => x.ThenTheErrorIs<DownstreamTemplateAlreadyUsedError>())
.BDDfy();
}
private void GivenAConfiguration(Library.Infrastructure.Configuration.Configuration configuration)
{
_configuration = configuration;
}
private void WhenIValidateTheConfiguration()
{
_result = _configurationValidator.IsValid(_configuration);
}
private void ThenTheResultIsValid()
{
_result.Data.IsError.ShouldBeFalse();
}
private void ThenTheResultIsNotValid()
{
_result.Data.IsError.ShouldBeTrue();
}
private void ThenTheErrorIs<T>()
{
_result.Data.Errors[0].ShouldBeOfType<T>();
}
}
}