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

Commit

Permalink
Move ConfigureOptions to CreateClient
Browse files Browse the repository at this point in the history
  • Loading branch information
dtillman committed Nov 22, 2016
1 parent 98731ce commit 23512f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/Steeltoe.Discovery.Client/DiscoveryClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ internal protected virtual object Create(IServiceProvider provider)
return null;
}

ConfigureOptions();

var logFactory = provider.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
var lifeCycle = provider.GetService(typeof(IApplicationLifetime)) as IApplicationLifetime;

Expand All @@ -54,7 +52,11 @@ internal protected virtual object Create(IServiceProvider provider)

public virtual object CreateClient(IApplicationLifetime lifeCycle = null, ILoggerFactory logFactory = null)
{

var logger = logFactory?.CreateLogger<DiscoveryClientFactory>();

ConfigureOptions();

if (_config == null)
{
logger?.LogWarning("Failed to create DiscoveryClient, no DiscoveryOptions");
Expand Down
19 changes: 10 additions & 9 deletions test/Steeltoe.Discovery.Client.Test/DiscoveryClientFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public void CreateClient_ClientTypeEureka_CreatesClient()
Assert.IsType(typeof(EurekaDiscoveryClient), client);
}

[Fact]
public void CreateClient_Calls_ConfigureOptions()
{
MyDiscoveryClientFactory factory = new MyDiscoveryClientFactory();
IServiceProvider provider = new MyServiceProvier();
IDiscoveryClient result = factory.CreateClient() as IDiscoveryClient;
Assert.NotNull(result);
Assert.True(factory.ConfigureOptionsCalled);
}

[Fact]
public void Create_NullIServiceProvider_ReturnsNull()
{
Expand Down Expand Up @@ -100,15 +110,6 @@ public void Create_MissingOptions_ReturnsUnknown()
Assert.Equal("Unknown", result.Description);
}

[Fact]
public void Create_Calls_ConfigureOptions()
{
MyDiscoveryClientFactory factory = new MyDiscoveryClientFactory();
IServiceProvider provider = new MyServiceProvier();
IDiscoveryClient result = factory.Create(provider) as IDiscoveryClient;
Assert.NotNull(result);
Assert.True(factory.ConfigureOptionsCalled);
}
}
class MyDiscoveryClientFactory : DiscoveryClientFactory
{
Expand Down

0 comments on commit 23512f9

Please sign in to comment.