mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-26 11:22:51 +08:00

* feat: update to asp.net core 3.0 preview 9 * fix : AspDotNetLogger unittest * feat: update generic host and useMvc 1、Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing https://github.com/aspnet/AspNetCore/issues/9542 2、 use IHost and IHostBuilder * feat : update .net core 3.0 rc1 * eureka extension * fixed logger formatter error * fixed synchronous operations are disallowed of ReadToEnd method * fix log tests * Flush method of FakeStream should do nothing * Update ContentTests.cs * Fixed ws tests * feat: delelte comment code * feat: update .net core 3.0 RTM * Update OcelotBuilderTests.cs * Update .travis.yml mono 6.0.0 and dotnet 3.0.100 * Update Ocelot.IntegrationTests.csproj update Microsoft.Data.SQLite 3.0.0 * Update .travis.yml * feat: remove FrameworkReference 1、 remove FrameworkReference 2、 update package * add appveyor configuration to use version of VS2019 with dotnet core 3 sdk support * update obsoleted SetCollectionValidator method * Swap out OpenCover for Coverlet * Bump Cake to 0.35.0 * Downgrade coveralls.net to 0.7.0 Fix disposing of PollConsul instance * Remove environment specific path separator * Do not return ReportGenerator on Mac/Linux * Remove direct dependency on IInternalConfiguration * Fix ordering of variable assignment * Fix broken tests * Fix acceptance tests for Consul
102 lines
3.2 KiB
C#
102 lines
3.2 KiB
C#
namespace Ocelot.UnitTests.Administration
|
|
{
|
|
using IdentityServer4.AccessTokenValidation;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Moq;
|
|
using Ocelot.Administration;
|
|
using Ocelot.DependencyInjection;
|
|
using Shouldly;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using TestStack.BDDfy;
|
|
using Xunit;
|
|
|
|
public class OcelotAdministrationBuilderTests
|
|
{
|
|
private readonly IServiceCollection _services;
|
|
private IServiceProvider _serviceProvider;
|
|
private readonly IConfiguration _configRoot;
|
|
private IOcelotBuilder _ocelotBuilder;
|
|
private Exception _ex;
|
|
|
|
public OcelotAdministrationBuilderTests()
|
|
{
|
|
_configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
|
|
_services = new ServiceCollection();
|
|
_services.AddSingleton<IWebHostEnvironment>(GetHostingEnvironment());
|
|
_services.AddSingleton(_configRoot);
|
|
}
|
|
|
|
private IWebHostEnvironment GetHostingEnvironment()
|
|
{
|
|
var environment = new Mock<IWebHostEnvironment>();
|
|
environment
|
|
.Setup(e => e.ApplicationName)
|
|
.Returns(typeof(OcelotAdministrationBuilderTests).GetTypeInfo().Assembly.GetName().Name);
|
|
|
|
return environment.Object;
|
|
}
|
|
|
|
//keep
|
|
[Fact]
|
|
public void should_set_up_administration_with_identity_server_options()
|
|
{
|
|
Action<IdentityServerAuthenticationOptions> options = o => { };
|
|
|
|
this.Given(x => WhenISetUpOcelotServices())
|
|
.When(x => WhenISetUpAdministration(options))
|
|
.Then(x => ThenAnExceptionIsntThrown())
|
|
.Then(x => ThenTheCorrectAdminPathIsRegitered())
|
|
.BDDfy();
|
|
}
|
|
|
|
//keep
|
|
[Fact]
|
|
public void should_set_up_administration()
|
|
{
|
|
this.Given(x => WhenISetUpOcelotServices())
|
|
.When(x => WhenISetUpAdministration())
|
|
.Then(x => ThenAnExceptionIsntThrown())
|
|
.Then(x => ThenTheCorrectAdminPathIsRegitered())
|
|
.BDDfy();
|
|
}
|
|
|
|
private void WhenISetUpAdministration()
|
|
{
|
|
_ocelotBuilder.AddAdministration("/administration", "secret");
|
|
}
|
|
|
|
private void WhenISetUpAdministration(Action<IdentityServerAuthenticationOptions> options)
|
|
{
|
|
_ocelotBuilder.AddAdministration("/administration", options);
|
|
}
|
|
|
|
private void ThenTheCorrectAdminPathIsRegitered()
|
|
{
|
|
_serviceProvider = _services.BuildServiceProvider();
|
|
var path = _serviceProvider.GetService<IAdministrationPath>();
|
|
path.Path.ShouldBe("/administration");
|
|
}
|
|
|
|
private void WhenISetUpOcelotServices()
|
|
{
|
|
try
|
|
{
|
|
_ocelotBuilder = _services.AddOcelot(_configRoot);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
_ex = e;
|
|
}
|
|
}
|
|
|
|
private void ThenAnExceptionIsntThrown()
|
|
{
|
|
_ex.ShouldBeNull();
|
|
}
|
|
}
|
|
}
|