mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 12:38:15 +08:00
Merge pull request #70 from MarcDenman/feature/updateLogging
Update logging
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
"Logging": {
|
||||
"IncludeScopes": true,
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"Default": "Trace",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Validator;
|
||||
using Ocelot.LoadBalancer.LoadBalancers;
|
||||
using Ocelot.Logging;
|
||||
using Ocelot.Requester.QoS;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
@ -22,7 +23,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
private readonly Mock<IConfigurationValidator> _validator;
|
||||
private Response<IOcelotConfiguration> _config;
|
||||
private FileConfiguration _fileConfiguration;
|
||||
private readonly Mock<ILogger<FileOcelotConfigurationCreator>> _logger;
|
||||
private readonly Mock<IOcelotLoggerFactory> _logger;
|
||||
private readonly FileOcelotConfigurationCreator _ocelotConfigurationCreator;
|
||||
private readonly Mock<ILoadBalancerFactory> _loadBalancerFactory;
|
||||
private readonly Mock<ILoadBalancerHouse> _loadBalancerHouse;
|
||||
@ -44,7 +45,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
_qosProviderFactory = new Mock<IQoSProviderFactory>();
|
||||
_qosProviderHouse = new Mock<IQosProviderHouse>();
|
||||
_qosProvider = new Mock<IQoSProvider>();
|
||||
_logger = new Mock<ILogger<FileOcelotConfigurationCreator>>();
|
||||
_logger = new Mock<IOcelotLoggerFactory>();
|
||||
_validator = new Mock<IConfigurationValidator>();
|
||||
_fileConfig = new Mock<IOptions<FileConfiguration>>();
|
||||
_loadBalancerFactory = new Mock<ILoadBalancerFactory>();
|
||||
|
@ -0,0 +1,73 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using Ocelot.Responses;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Infrastructure
|
||||
{
|
||||
public class HttpDataRepositoryTests
|
||||
{
|
||||
private HttpContext _httpContext;
|
||||
private IHttpContextAccessor _httpContextAccessor;
|
||||
private HttpDataRepository _httpDataRepository;
|
||||
private object _result;
|
||||
|
||||
public HttpDataRepositoryTests()
|
||||
{
|
||||
_httpContext = new DefaultHttpContext();
|
||||
_httpContextAccessor = new HttpContextAccessor{HttpContext = _httpContext};
|
||||
_httpDataRepository = new HttpDataRepository(_httpContextAccessor);
|
||||
}
|
||||
|
||||
//TODO - Additional tests -> Type mistmatch aka Add string, request int
|
||||
//TODO - Additional tests -> HttpContent null. This should never happen
|
||||
|
||||
[Fact]
|
||||
public void Get_returns_correct_key_from_http_context()
|
||||
{
|
||||
|
||||
this.Given(x => x.GivenAHttpContextContaining("key", "string"))
|
||||
.When(x => x.GetIsCalledWithKey<string>("key"))
|
||||
.Then(x => x.ThenTheResultIsAnOkResponse<string>("string"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Get_returns_error_response_if_the_key_is_not_found() //Therefore does not return null
|
||||
{
|
||||
this.Given(x => x.GivenAHttpContextContaining("key", "string"))
|
||||
.When(x => x.GetIsCalledWithKey<string>("keyDoesNotExist"))
|
||||
.Then(x => x.ThenTheResultIsAnErrorReposnse<string>("string1"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenAHttpContextContaining(string key, object o)
|
||||
{
|
||||
_httpContext.Items.Add(key, o);
|
||||
}
|
||||
|
||||
private void GetIsCalledWithKey<T>(string key)
|
||||
{
|
||||
_result = _httpDataRepository.Get<T>(key);
|
||||
}
|
||||
|
||||
private void ThenTheResultIsAnErrorReposnse<T>(object resultValue)
|
||||
{
|
||||
_result.ShouldBeOfType<ErrorResponse<T>>();
|
||||
((ErrorResponse<T>) _result).Data.ShouldBeNull();
|
||||
((ErrorResponse<T>)_result).IsError.ShouldBe(true);
|
||||
((ErrorResponse<T>) _result).Errors.ShouldHaveSingleItem()
|
||||
.ShouldBeOfType<CannotFindDataError>()
|
||||
.Message.ShouldStartWith("Unable to find data for key: ");
|
||||
}
|
||||
|
||||
private void ThenTheResultIsAnOkResponse<T>(object resultValue)
|
||||
{
|
||||
_result.ShouldBeOfType<OkResponse<T>>();
|
||||
((OkResponse<T>)_result).Data.ShouldBe(resultValue);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user