Skip to content

Commit

Permalink
Fix null refs.
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <[email protected]>
  • Loading branch information
askpt committed Jul 24, 2024
1 parent 4bb4cd1 commit bedb2f1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async Task IHostedLifecycleService.StartingAsync(CancellationToken cancellationT
{
foreach (var provider in this._providers)
{
await this._api.SetProviderAsync(provider.GetMetadata().Name ?? string.Empty, provider).ConfigureAwait(false);
await this._api.SetProviderAsync(provider.GetMetadata()?.Name ?? string.Empty, provider).ConfigureAwait(false);

if (this._api.GetProviderMetadata() is { Name: "No-op Provider" })
await this._api.SetProviderAsync(provider).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static void TryAddOpenFeatureClient(this OpenFeatureBuilder builder, stri
var api = services.GetRequiredService<Api>();
return api.GetClient(
api.GetProviderMetadata(providerName as string ?? string.Empty).Name,
api.GetProviderMetadata(providerName as string ?? string.Empty)?.Name,
null,
services.GetRequiredKeyedService<ILogger>(providerName),
services.GetRequiredKeyedService<EvaluationContextBuilder>(providerName).Build());
Expand Down
10 changes: 5 additions & 5 deletions test/OpenFeature.Extensions.Hosting.Tests/HostingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task Can_register_no_op()
#pragma warning restore xUnit1030

Assert.Equal(Api.Instance, app.Services.GetRequiredService<Api>());
Assert.Equal(Api.Instance.GetProviderMetadata().Name,
Assert.Equal(Api.Instance.GetProviderMetadata()?.Name,
app.Services.GetRequiredService<IFeatureClient>().GetMetadata().Name);

Assert.Empty(Api.Instance.GetContext().AsDictionary());
Expand All @@ -50,14 +50,14 @@ public async Task Can_register_some_feature_provider()
using var app = builder.Build();

Assert.Equal(Api.Instance, app.Services.GetRequiredService<Api>());
Assert.Equal("No-op Provider", app.Services.GetRequiredService<Api>().GetProviderMetadata().Name);
Assert.Equal("No-op Provider", app.Services.GetRequiredService<Api>().GetProviderMetadata()?.Name);

#pragma warning disable xUnit1030
await app.StartAsync().ConfigureAwait(false);
#pragma warning restore xUnit1030

Assert.Equal(Api.Instance, app.Services.GetRequiredService<Api>());
Assert.Equal(SomeFeatureProvider.Name, app.Services.GetRequiredService<Api>().GetProviderMetadata().Name);
Assert.Equal(SomeFeatureProvider.Name, app.Services.GetRequiredService<Api>().GetProviderMetadata()?.Name);
Assert.Equal(SomeFeatureProvider.Name, app.Services.GetRequiredService<IFeatureClient>().GetMetadata().Name);

Assert.Empty(Api.Instance.GetContext().AsDictionary());
Expand Down Expand Up @@ -85,14 +85,14 @@ public async Task Can_register_some_feature_provider_and_global_hook()
using var app = builder.Build();

Assert.Equal(Api.Instance, app.Services.GetRequiredService<Api>());
Assert.Equal("No-op Provider", app.Services.GetRequiredService<Api>().GetProviderMetadata().Name);
Assert.Equal("No-op Provider", app.Services.GetRequiredService<Api>().GetProviderMetadata()?.Name);

#pragma warning disable xUnit1030
await app.StartAsync().ConfigureAwait(false);
#pragma warning restore xUnit1030

Assert.Equal(Api.Instance, app.Services.GetRequiredService<Api>());
Assert.Equal(SomeFeatureProvider.Name, app.Services.GetRequiredService<Api>().GetProviderMetadata().Name);
Assert.Equal(SomeFeatureProvider.Name, app.Services.GetRequiredService<Api>().GetProviderMetadata()?.Name);
Assert.Equal(SomeFeatureProvider.Name, app.Services.GetRequiredService<IFeatureClient>().GetMetadata().Name);
Assert.NotEmpty(app.Services.GetServices<Hook>());

Expand Down

0 comments on commit bedb2f1

Please sign in to comment.