Skip to content

Commit

Permalink
additional tests
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed Jan 3, 2024
1 parent 6836250 commit e4aa68e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
51 changes: 49 additions & 2 deletions test/OpenFeature.Tests/OpenFeatureEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventHandlerDelegate>();

Expand All @@ -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<ProviderEventPayload>(payload => payload.ProviderName == testProvider.GetMetadata().Name));
eventHandler
.Received()
.Invoke(
Arg.Is<ProviderEventPayload>(
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<EventHandlerDelegate>();

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<ProviderEventPayload>(
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<EventHandlerDelegate>();

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<ProviderEventPayload>(
payload => payload.ProviderName == testProvider.GetMetadata().Name && payload.Type == ProviderEventTypes.ProviderStale
));
}

[Fact]
Expand Down
5 changes: 5 additions & 0 deletions test/OpenFeature.Tests/TestImplementations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e4aa68e

Please sign in to comment.