Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
- Fix the options from DI not being passed through to the strategy.
- Assert that the strategy isn't null when retrieved.
  • Loading branch information
martincostello committed Sep 18, 2024
1 parent 72588cc commit bb45edf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/Polly.Extensions.Tests/ReloadableResiliencePipelineTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Polly.DependencyInjection;
using Polly.Registry;
using Polly.Telemetry;

Expand All @@ -20,18 +19,21 @@ public void AddResiliencePipeline_EnsureReloadable(string? name)
var resList = new List<IDisposable>();
var reloadableConfig = new ReloadableConfiguration();
reloadableConfig.Reload(new() { { "tag", "initial-tag" } });
var builder = new ConfigurationBuilder().Add(reloadableConfig);
var fakeListener = new FakeTelemetryListener();

var configuration = new ConfigurationBuilder()
.Add(reloadableConfig)
.Build();

var services = new ServiceCollection();

if (name == null)
{
services.Configure<ReloadableStrategyOptions>(builder.Build());
services.Configure<ReloadableStrategyOptions>(configuration);
}
else
{
services.Configure<ReloadableStrategyOptions>(name, builder.Build());
services.Configure<ReloadableStrategyOptions>(name, configuration);
}

services.Configure<TelemetryOptions>(options => options.TelemetryListeners.Add(fakeListener));
Expand All @@ -40,6 +42,8 @@ public void AddResiliencePipeline_EnsureReloadable(string? name)
builder.InstanceName = "my-instance";

var options = context.GetOptions<ReloadableStrategyOptions>(name);
options.Should().NotBeNull();

context.EnableReloads<ReloadableStrategyOptions>(name);

builder.AddStrategy(_ =>
Expand All @@ -48,7 +52,7 @@ public void AddResiliencePipeline_EnsureReloadable(string? name)
resList.Add(res);
return new ReloadableStrategy(options.Tag, res);
},
new ReloadableStrategyOptions());
options);
});

var serviceProvider = services.BuildServiceProvider();
Expand Down

0 comments on commit bb45edf

Please sign in to comment.