Skip to content

Commit

Permalink
Added supporting unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Whit Waldo <[email protected]>
  • Loading branch information
WhitWaldo committed May 15, 2024
1 parent 2d4fe77 commit 990bf35
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/Dapr.AspNetCore.Test/DaprServiceCollectionExtensionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ public void AddDaprClient_RegistersDaprClientOnlyOnce()
Assert.True(daprClient.JsonSerializerOptions.PropertyNameCaseInsensitive);
}

[Fact]
public void AddDaprClient_RegistersUsingDependencyFromIServiceProvider()
{

var services = new ServiceCollection();
services.AddSingleton<TestConfigurationProvider>();
services.AddDaprClient((provider, builder) =>
{
var configProvider = provider.GetRequiredService<TestConfigurationProvider>();
var caseSensitivity = configProvider.GetCaseSensitivity();

builder.UseJsonSerializationOptions(new JsonSerializerOptions
{
PropertyNameCaseInsensitive = caseSensitivity
});
});

var serviceProvider = services.BuildServiceProvider();

DaprClientGrpc client = serviceProvider.GetRequiredService<DaprClient>() as DaprClientGrpc;

//Registers with case-insensitive as true by default, but we set as false above
Assert.False(client.JsonSerializerOptions.PropertyNameCaseInsensitive);
}

#if NET8_0_OR_GREATER
[Fact]
public void AddDaprClient_WithKeyedServices()
Expand All @@ -65,5 +90,10 @@ public void AddDaprClient_WithKeyedServices()
Assert.NotNull(daprClient);
}
#endif

private class TestConfigurationProvider
{
public bool GetCaseSensitivity() => false;
}
}
}

0 comments on commit 990bf35

Please sign in to comment.