From e4aa68ef91093fe5ec8e94894ed5170afd60d96a Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Wed, 3 Jan 2024 12:13:16 +0100 Subject: [PATCH] additional tests Signed-off-by: Florian Bacher --- .../OpenFeatureEventTests.cs | 51 ++++++++++++++++++- test/OpenFeature.Tests/TestImplementations.cs | 5 ++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/test/OpenFeature.Tests/OpenFeatureEventTests.cs b/test/OpenFeature.Tests/OpenFeatureEventTests.cs index 3eb21b3a..a29f147b 100644 --- a/test/OpenFeature.Tests/OpenFeatureEventTests.cs +++ b/test/OpenFeature.Tests/OpenFeatureEventTests.cs @@ -93,7 +93,7 @@ public async Task API_Level_Event_Handlers_Should_Be_Registered() } [Fact] - public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_After_Registering() + public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_After_Registering_Provider_Ready() { var eventHandler = Substitute.For(); @@ -103,7 +103,54 @@ public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_ Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, eventHandler); Thread.Sleep(1000); - eventHandler.Received().Invoke(Arg.Is(payload => payload.ProviderName == testProvider.GetMetadata().Name)); + eventHandler + .Received() + .Invoke( + Arg.Is( + payload => payload.ProviderName == testProvider.GetMetadata().Name && payload.Type == ProviderEventTypes.ProviderReady + )); + } + + [Fact] + public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_After_Registering_Provider_Error() + { + var eventHandler = Substitute.For(); + + var testProvider = new TestProvider(); + await Api.Instance.SetProvider(testProvider); + + testProvider.SetStatus(ProviderStatus.Error); + + Api.Instance.AddHandler(ProviderEventTypes.ProviderError, eventHandler); + + Thread.Sleep(1000); + eventHandler + .Received() + .Invoke( + Arg.Is( + payload => payload.ProviderName == testProvider.GetMetadata().Name && payload.Type == ProviderEventTypes.ProviderError + )); + } + + [Fact] + public async Task API_Level_Event_Handlers_Should_Be_Informed_About_Ready_State_After_Registering_Provider_Stale() + { + var eventHandler = Substitute.For(); + + var testProvider = new TestProvider(); + await Api.Instance.SetProvider(testProvider); + + testProvider.SetStatus(ProviderStatus.Stale); + + Api.Instance.AddHandler(ProviderEventTypes.ProviderStale, eventHandler); + + Thread.Sleep(1000); + eventHandler + .Received() + .Invoke( + Arg.Is( + payload => payload.ProviderName == testProvider.GetMetadata().Name && payload.Type == ProviderEventTypes.ProviderStale + )); } [Fact] diff --git a/test/OpenFeature.Tests/TestImplementations.cs b/test/OpenFeature.Tests/TestImplementations.cs index 4ca40213..d5257f67 100644 --- a/test/OpenFeature.Tests/TestImplementations.cs +++ b/test/OpenFeature.Tests/TestImplementations.cs @@ -87,6 +87,11 @@ public override ProviderStatus GetStatus() return this._status; } + public void SetStatus(ProviderStatus status) + { + this._status = status; + } + public override Task Initialize(EvaluationContext context) { this._status = ProviderStatus.Ready;