Skip to content

Commit

Permalink
demonstrate issue ThreeMammals#169
Browse files Browse the repository at this point in the history
  • Loading branch information
rv-alove committed Dec 4, 2017
1 parent 9232766 commit 189471c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/Ocelot.UnitTests/DependencyInjection/OcelotBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
using System.Text;
using CacheManager.Core;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Ocelot.Cache;
using Ocelot.Configuration;
using Ocelot.Configuration.File;
using Ocelot.Configuration.Setter;
using Ocelot.DependencyInjection;
using Ocelot.Logging;
using Shouldly;
using TestStack.BDDfy;
using Xunit;
Expand All @@ -20,6 +23,7 @@ namespace Ocelot.UnitTests.DependencyInjection
public class OcelotBuilderTests
{
private IServiceCollection _services;
private IServiceProvider _serviceProvider;
private IConfigurationRoot _configRoot;
private IOcelotBuilder _ocelotBuilder;
private int _maxRetries;
Expand All @@ -30,6 +34,7 @@ public OcelotBuilderTests()
_configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
_services = new ServiceCollection();
_services.AddSingleton(builder);
_services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
_maxRetries = 100;
}
private Exception _ex;
Expand Down Expand Up @@ -70,6 +75,16 @@ public void should_set_up_consul()
.BDDfy();
}

[Fact]
public void should_use_logger_factory()
{
this.Given(x => WhenISetUpOcelotServices())
.When(x => WhenIValidateScopes())
.When(x => WhenIAccessLoggerFactory())
.Then(x => ThenAnExceptionIsntThrown())
.BDDfy();
}

private void OnlyOneVersionOfEachCacheIsRegistered()
{
var outputCache = _services.Single(x => x.ServiceType == typeof(IOcelotCache<CachedResponse>));
Expand Down Expand Up @@ -127,6 +142,30 @@ private void WhenISetUpCacheManager()
}
}

private void WhenIAccessLoggerFactory()
{
try
{
var logger = _serviceProvider.GetService<IFileConfigurationSetter>();
}
catch (Exception e)
{
_ex = e;
}
}

private void WhenIValidateScopes()
{
try
{
_serviceProvider = _services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true });
}
catch (Exception e)
{
_ex = e;
}
}

private void ThenAnExceptionIsntThrown()
{
_ex.ShouldBeNull();
Expand Down

0 comments on commit 189471c

Please sign in to comment.