Skip to content

Commit

Permalink
Fix unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
  • Loading branch information
askpt committed Dec 4, 2024
1 parent 194901a commit ab3b4fb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions test/OpenFeature.Tests/OpenFeatureTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ public async Task OpenFeature_Should_Initialize_Provider()
providerMockDefault.Status.Returns(ProviderStatus.NotReady);

await Api.Instance.SetProviderAsync(providerMockDefault);
await providerMockDefault.Received(1).InitializeAsync(Api.Instance.GetContext());

await providerMockDefault.Received(1).InitializeAsync(Arg.Is<EvaluationContext>(e => e.Count == 0));

var providerMockNamed = Substitute.For<FeatureProvider>();
providerMockNamed.Status.Returns(ProviderStatus.NotReady);

await Api.Instance.SetProviderAsync("the-name", providerMockNamed);
await providerMockNamed.Received(1).InitializeAsync(Api.Instance.GetContext());
await providerMockNamed.Received(1).InitializeAsync(Arg.Is<EvaluationContext>(e => e.Count == 0));
}

[Fact]
Expand All @@ -49,26 +50,26 @@ public async Task OpenFeature_Should_Shutdown_Unused_Provider()
providerA.Status.Returns(ProviderStatus.NotReady);

await Api.Instance.SetProviderAsync(providerA);
await providerA.Received(1).InitializeAsync(Api.Instance.GetContext());
await providerA.Received(1).InitializeAsync(Arg.Is<EvaluationContext>(e => e.Count == 0));

var providerB = Substitute.For<FeatureProvider>();
providerB.Status.Returns(ProviderStatus.NotReady);

await Api.Instance.SetProviderAsync(providerB);
await providerB.Received(1).InitializeAsync(Api.Instance.GetContext());
await providerB.Received(1).InitializeAsync(Arg.Is<EvaluationContext>(e => e.Count == 0));
await providerA.Received(1).ShutdownAsync();

var providerC = Substitute.For<FeatureProvider>();
providerC.Status.Returns(ProviderStatus.NotReady);

await Api.Instance.SetProviderAsync("named", providerC);
await providerC.Received(1).InitializeAsync(Api.Instance.GetContext());
await providerC.Received(1).InitializeAsync(Arg.Is<EvaluationContext>(e => e.Count == 0));

var providerD = Substitute.For<FeatureProvider>();
providerD.Status.Returns(ProviderStatus.NotReady);

await Api.Instance.SetProviderAsync("named", providerD);
await providerD.Received(1).InitializeAsync(Api.Instance.GetContext());
await providerD.Received(1).InitializeAsync(Arg.Is<EvaluationContext>(e => e.Count == 0));
await providerC.Received(1).ShutdownAsync();
}

Expand Down Expand Up @@ -212,13 +213,17 @@ public void Should_Set_Given_Context()

Api.Instance.SetContext(context);

Api.Instance.GetContext().Should().BeSameAs(context);
var context2 = Api.Instance.GetContext();
context2.Count.Should().Be(context.Count);
context2.TargetingKey?.Should().Be(context.TargetingKey);

context = EvaluationContext.Builder().Build();

Api.Instance.SetContext(context);

Api.Instance.GetContext().Should().BeSameAs(context);
var context3 = Api.Instance.GetContext();
context3.Count.Should().Be(context.Count);
context3.TargetingKey?.Should().Be(context.TargetingKey);
}

[Fact]
Expand Down

0 comments on commit ab3b4fb

Please sign in to comment.