add file configuration fluent validation and change default configura… (#168)

* add file configuration fluent validation and change default configuration validator to fluent validator

* add file validation failed error code

* change authentication schemes check to async

* beautify the code ^_^

* clean file validation and fix test failure.
This commit is contained in:
Eilyyyy
2017-12-05 12:29:44 -06:00
committed by Tom Pallister
parent 31fe6af614
commit 4f27a50503
18 changed files with 160 additions and 298 deletions

View File

@ -15,17 +15,17 @@ using Xunit;
namespace Ocelot.UnitTests.Configuration
{
public class ConfigurationValidationTests
public class ConfigurationFluentValidationTests
{
private readonly IConfigurationValidator _configurationValidator;
private FileConfiguration _fileConfiguration;
private Response<ConfigurationValidationResult> _result;
private Mock<IAuthenticationSchemeProvider> _provider;
public ConfigurationValidationTests()
public ConfigurationFluentValidationTests()
{
_provider = new Mock<IAuthenticationSchemeProvider>();
_configurationValidator = new FileConfigurationValidator(_provider.Object);
_provider = new Mock<IAuthenticationSchemeProvider>();
_configurationValidator = new FileConfigurationFluentValidator(_provider.Object);
}
[Fact]
@ -44,6 +44,7 @@ namespace Ocelot.UnitTests.Configuration
}))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsNotValid())
.Then(x => x.ThenTheErrorIs<FileValidationFailedError>())
.BDDfy();
}
@ -147,7 +148,6 @@ namespace Ocelot.UnitTests.Configuration
}))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsNotValid())
.And(x => x.ThenTheErrorIs<UnsupportedAuthenticationProviderError>())
.BDDfy();
}
@ -172,10 +172,10 @@ namespace Ocelot.UnitTests.Configuration
}))
.When(x => x.WhenIValidateTheConfiguration())
.Then(x => x.ThenTheResultIsNotValid())
.And(x => x.ThenTheErrorIs<DownstreamPathTemplateAlreadyUsedError>())
.BDDfy();
}
private void GivenAConfiguration(FileConfiguration fileConfiguration)
{
_fileConfiguration = fileConfiguration;
@ -225,6 +225,5 @@ namespace Ocelot.UnitTests.Configuration
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(principal, new AuthenticationProperties(), Scheme.Name)));
}
}
}
}
}

View File

@ -503,7 +503,7 @@ namespace Ocelot.UnitTests.Configuration
[Fact]
public void should_return_validation_errors()
{
var errors = new List<Error> {new PathTemplateDoesntStartWithForwardSlash("some message")};
var errors = new List<Error> {new FileValidationFailedError("some message")};
this.Given(x => x.GivenTheConfigIs(new FileConfiguration()))
.And(x => x.GivenTheConfigIsInvalid(errors))

View File

@ -54,6 +54,7 @@ namespace Ocelot.UnitTests.Responder
[InlineData(OcelotErrorCode.DownstreampathTemplateAlreadyUsedError)]
[InlineData(OcelotErrorCode.DownstreamPathTemplateContainsSchemeError)]
[InlineData(OcelotErrorCode.DownstreamSchemeNullOrEmptyError)]
[InlineData(OcelotErrorCode.FileValidationFailedError)]
[InlineData(OcelotErrorCode.InstructionNotForClaimsError)]
[InlineData(OcelotErrorCode.NoInstructionsError)]
[InlineData(OcelotErrorCode.ParsingConfigurationHeaderError)]
@ -120,7 +121,7 @@ namespace Ocelot.UnitTests.Responder
// If this test fails then it's because the number of error codes has changed.
// You should make the appropriate changes to the test cases here to ensure
// they cover all the error codes, and then modify this assertion.
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(31, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(32, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
}
private void ShouldMapErrorToStatusCode(OcelotErrorCode errorCode, HttpStatusCode expectedHttpStatusCode)