mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-24 05:52:49 +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
83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
namespace Ocelot.UnitTests.Consul
|
|
{
|
|
using Moq;
|
|
using Ocelot.Infrastructure;
|
|
using Ocelot.Logging;
|
|
using Ocelot.ServiceDiscovery.Providers;
|
|
using Provider.Consul;
|
|
using Shouldly;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TestStack.BDDfy;
|
|
using Values;
|
|
using Xunit;
|
|
|
|
public class PollingConsulServiceDiscoveryProviderTests
|
|
{
|
|
private readonly int _delay;
|
|
private readonly List<Service> _services;
|
|
private readonly Mock<IOcelotLoggerFactory> _factory;
|
|
private readonly Mock<IOcelotLogger> _logger;
|
|
private readonly Mock<IServiceDiscoveryProvider> _consulServiceDiscoveryProvider;
|
|
private List<Service> _result;
|
|
|
|
public PollingConsulServiceDiscoveryProviderTests()
|
|
{
|
|
_services = new List<Service>();
|
|
_delay = 1;
|
|
_factory = new Mock<IOcelotLoggerFactory>();
|
|
_logger = new Mock<IOcelotLogger>();
|
|
_factory.Setup(x => x.CreateLogger<PollConsul>()).Returns(_logger.Object);
|
|
_consulServiceDiscoveryProvider = new Mock<IServiceDiscoveryProvider>();
|
|
}
|
|
|
|
[Fact]
|
|
public void should_return_service_from_consul()
|
|
{
|
|
var service = new Service("", new ServiceHostAndPort("", 0), "", "", new List<string>());
|
|
|
|
this.Given(x => GivenConsulReturns(service))
|
|
.When(x => WhenIGetTheServices(1))
|
|
.Then(x => ThenTheCountIs(1))
|
|
.BDDfy();
|
|
}
|
|
|
|
private void GivenConsulReturns(Service service)
|
|
{
|
|
_services.Add(service);
|
|
_consulServiceDiscoveryProvider.Setup(x => x.Get()).ReturnsAsync(_services);
|
|
}
|
|
|
|
private void ThenTheCountIs(int count)
|
|
{
|
|
_result.Count.ShouldBe(count);
|
|
}
|
|
|
|
private void WhenIGetTheServices(int expected)
|
|
{
|
|
using (var provider = new PollConsul(_delay, _factory.Object, _consulServiceDiscoveryProvider.Object))
|
|
{
|
|
var result = Wait.WaitFor(3000).Until(() =>
|
|
{
|
|
try
|
|
{
|
|
_result = provider.Get().GetAwaiter().GetResult();
|
|
if (_result.Count == expected)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return false;
|
|
}
|
|
});
|
|
|
|
result.ShouldBeTrue();
|
|
}
|
|
}
|
|
}
|
|
}
|