Skip to content

Commit

Permalink
Fix unit test.
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <[email protected]>
  • Loading branch information
askpt committed Nov 11, 2024
1 parent b123c14 commit b695f49
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));

Check failure on line 35 in test/OpenFeature.Tests/OpenFeatureTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

OpenFeature.Tests.OpenFeatureTests.OpenFeature_Should_Initialize_Provider

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching: InitializeAsync(e => (e.Count == 0), System.Threading.CancellationToken) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): InitializeAsync(*EvaluationContext*, System.Threading.CancellationToken)

Check failure on line 35 in test/OpenFeature.Tests/OpenFeatureTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

OpenFeature.Tests.OpenFeatureTests.OpenFeature_Should_Initialize_Provider

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching: InitializeAsync(e => (e.Count == 0), System.Threading.CancellationToken) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): InitializeAsync(*EvaluationContext*, System.Threading.CancellationToken)

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));

Check failure on line 53 in test/OpenFeature.Tests/OpenFeatureTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

OpenFeature.Tests.OpenFeatureTests.OpenFeature_Should_Shutdown_Unused_Provider

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching: InitializeAsync(e => (e.Count == 0), System.Threading.CancellationToken) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): InitializeAsync(*EvaluationContext*, System.Threading.CancellationToken)

Check failure on line 53 in test/OpenFeature.Tests/OpenFeatureTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

OpenFeature.Tests.OpenFeatureTests.OpenFeature_Should_Shutdown_Unused_Provider

NSubstitute.Exceptions.ReceivedCallsException : Expected to receive exactly 1 call matching: InitializeAsync(e => (e.Count == 0), System.Threading.CancellationToken) Actually received no matching calls. Received 1 non-matching call (non-matching arguments indicated with '*' characters): InitializeAsync(*EvaluationContext*, System.Threading.CancellationToken)

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);

Check failure on line 217 in test/OpenFeature.Tests/OpenFeatureTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

OpenFeature.Tests.OpenFeatureTests.Should_Set_Given_Context

Expected context2.Count to be 0, but found 2 (difference of 2).

Check failure on line 217 in test/OpenFeature.Tests/OpenFeatureTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

OpenFeature.Tests.OpenFeatureTests.Should_Set_Given_Context

Expected context2.Count to be 0, but found 2 (difference of 2).
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 b695f49

Please sign in to comment.