Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPallister committed Aug 12, 2018
1 parent 0604569 commit 8f05ec0
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Ocelot.Provider.Eureka.UnitTests
{
using System.Threading.Tasks;
using Configuration;
using Configuration.Builder;
using Configuration.Repository;
using Microsoft.AspNetCore.Builder.Internal;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Responses;
using Shouldly;
using Steeltoe.Common.Discovery;
using Xunit;

public class EurekaMiddlewareConfigurationProviderTests
{
[Fact]
public void should_not_build()
{
var configRepo = new Mock<IInternalConfigurationRepository>();
configRepo.Setup(x => x.Get())
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, null, null, null, null, null, null)));
var services = new ServiceCollection();
services.AddSingleton<IInternalConfigurationRepository>(configRepo.Object);
var sp = services.BuildServiceProvider();
var provider = EurekaMiddlewareConfigurationProvider.Get(new ApplicationBuilder(sp));
provider.ShouldBeOfType<Task>();
}

[Fact]
public void should_build()
{
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().WithType("eureka").Build();
var client = new Mock<IDiscoveryClient>();
var configRepo = new Mock<IInternalConfigurationRepository>();
configRepo.Setup(x => x.Get())
.Returns(new OkResponse<IInternalConfiguration>(new InternalConfiguration(null, null, serviceProviderConfig, null, null, null, null, null)));
var services = new ServiceCollection();
services.AddSingleton<IInternalConfigurationRepository>(configRepo.Object);
services.AddSingleton<IDiscoveryClient>(client.Object);
var sp = services.BuildServiceProvider();
var provider = EurekaMiddlewareConfigurationProvider.Get(new ApplicationBuilder(sp));
provider.ShouldBeOfType<Task>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
namespace Ocelot.Provider.Eureka.UnitTests
{
using Configuration.Builder;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Shouldly;
using Steeltoe.Common.Discovery;
using Xunit;

public class EurekaProviderFactoryTests
{
[Fact]
public void should_not_get()
{
var config = new ServiceProviderConfigurationBuilder().Build();
var sp = new ServiceCollection().BuildServiceProvider();
var provider = EurekaProviderFactory.Get(sp, config, null);
provider.ShouldBeNull();
}

[Fact]
public void should_get()
{
var config = new ServiceProviderConfigurationBuilder().WithType("eureka").Build();
var client = new Mock<IDiscoveryClient>();
var services = new ServiceCollection();
services.AddSingleton<IDiscoveryClient>(client.Object);
var sp = services.BuildServiceProvider();
var provider = EurekaProviderFactory.Get(sp, config, null);
provider.ShouldBeOfType<EurekaServiceDiscoveryProvider>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Moq;
using ServiceDiscovery.Providers;
using Shouldly;
using Steeltoe.Common.Discovery;
using TestStack.BDDfy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
namespace Ocelot.Provider.Eureka.UnitTests
{
using DependencyInjection;
using DownstreamRouteFinder.Middleware;
using DownstreamUrlCreator.Middleware;
using LoadBalancer.Middleware;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Middleware;
using Middleware.Pipeline;
using Pivotal.Discovery.Client;
using Request.Middleware;
using Shouldly;
using Steeltoe.Common.Discovery;
using Steeltoe.Discovery.Eureka;
using TestStack.BDDfy;
using WebSockets.Middleware;
using Xunit;

public class OcelotPipelineExtensionsTests
Expand All @@ -41,22 +36,6 @@ private void WhenIBuild()
_handlers = _builder.BuildOcelotPipeline(new OcelotPipelineConfiguration());
}

private void WhenIExpandBuild()
{
OcelotPipelineConfiguration configuration = new OcelotPipelineConfiguration();
configuration.MapWhenOcelotPipeline.Add((app) =>
{
app.UseDownstreamRouteFinderMiddleware();
app.UseDownstreamRequestInitialiser();
app.UseLoadBalancingMiddleware();
app.UseDownstreamUrlCreatorMiddleware();
app.UseWebSocketsProxyMiddleware();

return context => context.HttpContext.WebSockets.IsWebSocketRequest;
});
_handlers = _builder.BuildOcelotPipeline(new OcelotPipelineConfiguration());
}

private void GivenTheDepedenciesAreSetUp()
{
IConfigurationBuilder test = new ConfigurationBuilder();
Expand Down
24 changes: 24 additions & 0 deletions test/Ocelot.Provider.Eureka.UnitTests/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"Logging": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Error",
"System": "Error",
"Microsoft": "Error"
}
},
"spring": {
"application": {
"name": "ocelot"
}
},
"eureka": {
"client": {
"serviceUrl": "http://localhost:8761/eureka/",
"shouldRegisterWithEureka": true,
"shouldFetchRegistry": true,
"port": 5000,
"hostName": "localhost"
}
}
}

0 comments on commit 8f05ec0

Please sign in to comment.