mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-18 23:28:14 +08:00
brought in flurl and stated adding tests for the requester
This commit is contained in:
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user