diff --git a/Vonage.Test.Unit/Extensions/ServiceCollectionExtensionsTest.cs b/Vonage.Test.Unit/Extensions/ServiceCollectionExtensionsTest.cs index 97041573b..8db692277 100644 --- a/Vonage.Test.Unit/Extensions/ServiceCollectionExtensionsTest.cs +++ b/Vonage.Test.Unit/Extensions/ServiceCollectionExtensionsTest.cs @@ -17,6 +17,7 @@ using Vonage.Redaction; using Vonage.Request; using Vonage.ShortCodes; +using Vonage.SubAccounts; using Vonage.Users; using Vonage.Verify; using Vonage.VerifyV2; @@ -25,116 +26,90 @@ namespace Vonage.Test.Unit.Extensions { - public class ServiceCollectionExtensionsTest - { - private readonly Credentials credentials = Credentials.FromApiKeyAndSecret("key", "secret"); + public class ServiceCollectionExtensionsTest + { + private readonly Credentials credentials = Credentials.FromApiKeyAndSecret("key", "secret"); - private readonly IConfigurationRoot configuration = new ConfigurationBuilder() - .AddInMemoryCollection(new Dictionary - { - {"appSettings:Vonage_key", "RandomValue"}, - }) - .Build(); + private readonly IConfigurationRoot configuration = new ConfigurationBuilder() + .AddInMemoryCollection(new Dictionary + { + {"appSettings:Vonage_key", "RandomValue"}, + }) + .Build(); - [Fact] - public void AddVonageClientScoped_ShouldProvideScopedClientInstance_GivenConfigurationIsProvided() - { - var provider = BuildScopedProviderWithConfiguration(configuration); - provider.GetRequiredService().Should().Be(provider.GetRequiredService()); - } + [Theory] + [MemberData(nameof(GetSpecificVonageClients))] + public void AddVonageClientScoped_ShouldProvideScopedSpecificClientInstance_GivenConfigurationIsProvided( + Type type) + { + var provider = BuildScopedProviderWithConfiguration(this.configuration); + provider.GetRequiredService(type).Should().Be(provider.GetRequiredService(type)); + } - [Fact] - public void AddVonageClientScoped_ShouldProvideScopedClientInstance_GivenCredentialsAreProvided() - { - var provider = BuildScopedProviderWithCredentials(this.credentials); - provider.GetRequiredService().Should().Be(provider.GetRequiredService()); - } + [Theory] + [MemberData(nameof(GetSpecificVonageClients))] + public void AddVonageClientScoped_ShouldProvideScopedSpecificClientInstance_GivenCredentialsAreProvided( + Type type) + { + var provider = BuildScopedProviderWithCredentials(this.credentials); + provider.GetRequiredService(type).Should().Be(provider.GetRequiredService(type)); + } - [Theory] - [MemberData(nameof(GetSpecificVonageClients))] - public void AddVonageClientScoped_ShouldProvideScopedSpecificClientInstance_GivenConfigurationIsProvided( - Type type) - { - var provider = BuildScopedProviderWithConfiguration(configuration); - provider.GetRequiredService(type).Should().Be(provider.GetRequiredService(type)); - } + [Theory] + [MemberData(nameof(GetSpecificVonageClients))] + public void + AddVonageClientTransient_ShouldProvideTransientSpecificClientInstance_GivenConfigurationIsProvided( + Type type) + { + var provider = BuildTransientProviderWithConfiguration(this.configuration); + provider.GetRequiredService(type).Should() + .NotBe(provider.GetRequiredService(type)); + } - [Theory] - [MemberData(nameof(GetSpecificVonageClients))] - public void AddVonageClientScoped_ShouldProvideScopedSpecificClientInstance_GivenCredentialsAreProvided( - Type type) - { - var provider = BuildScopedProviderWithCredentials(this.credentials); - provider.GetRequiredService(type).Should().Be(provider.GetRequiredService(type)); - } + [Theory] + [MemberData(nameof(GetSpecificVonageClients))] + public void AddVonageClientTransient_ShouldProvideTransientSpecificClientInstance_GivenCredentialsAreProvided( + Type type) + { + var provider = BuildTransientProviderWithCredentials(this.credentials); + provider.GetRequiredService(type).Should() + .NotBe(provider.GetRequiredService(type)); + } - [Fact] - public void AddVonageClientTransient_ShouldProvideTransientClientInstance_GivenConfigurationIsProvided() - { - var provider = BuildTransientProviderWithConfiguration(configuration); - provider.GetRequiredService().Should() - .NotBe(provider.GetRequiredService()); - } + public static IEnumerable GetSpecificVonageClients() + { + yield return new object[] {typeof(VonageClient)}; + yield return new object[] {typeof(IAccountClient)}; + yield return new object[] {typeof(IApplicationClient)}; + yield return new object[] {typeof(IConversionClient)}; + yield return new object[] {typeof(IMeetingsClient)}; + yield return new object[] {typeof(IMessagesClient)}; + yield return new object[] {typeof(INumberInsightClient)}; + yield return new object[] {typeof(INumbersClient)}; + yield return new object[] {typeof(IPricingClient)}; + yield return new object[] {typeof(IProactiveConnectClient)}; + yield return new object[] {typeof(IRedactClient)}; + yield return new object[] {typeof(IShortCodesClient)}; + yield return new object[] {typeof(ISubAccountsClient)}; + yield return new object[] {typeof(ISmsClient)}; + yield return new object[] {typeof(IUsersClient)}; + yield return new object[] {typeof(IVerifyClient)}; + yield return new object[] {typeof(IVerifyV2Client)}; + yield return new object[] {typeof(IVoiceClient)}; + yield return new object[] {typeof(ITokenGenerator)}; + yield return new object[] {typeof(ITokenGenerator)}; + } - [Fact] - public void AddVonageClientTransient_ShouldProvideTransientClientInstance_GivenCredentialsAreProvided() - { - var provider = BuildTransientProviderWithCredentials(this.credentials); - provider.GetRequiredService().Should() - .NotBe(provider.GetRequiredService()); - } + private static ServiceProvider BuildScopedProviderWithConfiguration(IConfiguration configuration) => + new ServiceCollection().AddVonageClientScoped(configuration).BuildServiceProvider(); - [Theory] - [MemberData(nameof(GetSpecificVonageClients))] - public void - AddVonageClientTransient_ShouldProvideTransientSpecificClientInstance_GivenConfigurationIsProvided( - Type type) - { - var provider = BuildTransientProviderWithConfiguration(configuration); - provider.GetRequiredService(type).Should() - .NotBe(provider.GetRequiredService(type)); - } + private static ServiceProvider BuildScopedProviderWithCredentials(Credentials credentials) => + new ServiceCollection().AddVonageClientScoped(credentials).BuildServiceProvider(); - [Theory] - [MemberData(nameof(GetSpecificVonageClients))] - public void AddVonageClientTransient_ShouldProvideTransientSpecificClientInstance_GivenCredentialsAreProvided( - Type type) - { - var provider = BuildTransientProviderWithCredentials(this.credentials); - provider.GetRequiredService(type).Should() - .NotBe(provider.GetRequiredService(type)); - } + private static ServiceProvider BuildTransientProviderWithConfiguration(IConfiguration configuration) => + new ServiceCollection().AddVonageClientTransient(configuration).BuildServiceProvider(); - public static IEnumerable GetSpecificVonageClients() - { - yield return new object[] {typeof(IAccountClient)}; - yield return new object[] {typeof(IApplicationClient)}; - yield return new object[] {typeof(IConversionClient)}; - yield return new object[] {typeof(IMeetingsClient)}; - yield return new object[] {typeof(IMessagesClient)}; - yield return new object[] {typeof(INumberInsightClient)}; - yield return new object[] {typeof(INumbersClient)}; - yield return new object[] {typeof(IPricingClient)}; - yield return new object[] {typeof(IProactiveConnectClient)}; - yield return new object[] {typeof(IRedactClient)}; - yield return new object[] {typeof(IShortCodesClient)}; - yield return new object[] {typeof(ISmsClient)}; - yield return new object[] {typeof(IUsersClient)}; - yield return new object[] {typeof(IVerifyClient)}; - yield return new object[] {typeof(IVerifyV2Client)}; - yield return new object[] {typeof(IVoiceClient)}; - } - - private static ServiceProvider BuildScopedProviderWithConfiguration(IConfiguration configuration) => - new ServiceCollection().AddVonageClientScoped(configuration).BuildServiceProvider(); - - private static ServiceProvider BuildScopedProviderWithCredentials(Credentials credentials) => - new ServiceCollection().AddVonageClientScoped(credentials).BuildServiceProvider(); - - private static ServiceProvider BuildTransientProviderWithConfiguration(IConfiguration configuration) => - new ServiceCollection().AddVonageClientTransient(configuration).BuildServiceProvider(); - - private static ServiceProvider BuildTransientProviderWithCredentials(Credentials credentials) => - new ServiceCollection().AddVonageClientTransient(credentials).BuildServiceProvider(); - } + private static ServiceProvider BuildTransientProviderWithCredentials(Credentials credentials) => + new ServiceCollection().AddVonageClientTransient(credentials).BuildServiceProvider(); + } } \ No newline at end of file diff --git a/Vonage/Extensions/ServiceCollectionExtensions.cs b/Vonage/Extensions/ServiceCollectionExtensions.cs index 0465a0291..69750bbd9 100644 --- a/Vonage/Extensions/ServiceCollectionExtensions.cs +++ b/Vonage/Extensions/ServiceCollectionExtensions.cs @@ -81,12 +81,14 @@ private static void RegisterScopedServices(IServiceCollection services) services.AddScoped(serviceProvider => serviceProvider.GetService().PricingClient); services.AddScoped(serviceProvider => serviceProvider.GetService().ProactiveConnectClient); services.AddScoped(serviceProvider => serviceProvider.GetService().RedactClient); - services.AddScoped(serviceProvider => serviceProvider.GetService().ShortCodesClient); + services.AddScoped(serviceProvider => serviceProvider.GetService().ShortCodesClient); + services.AddScoped(serviceProvider => serviceProvider.GetService().SubAccountsClient); services.AddScoped(serviceProvider => serviceProvider.GetService().SmsClient); services.AddScoped(serviceProvider => serviceProvider.GetService().UsersClient); services.AddScoped(serviceProvider => serviceProvider.GetService().VerifyClient); services.AddScoped(serviceProvider => serviceProvider.GetService().VerifyV2Client); services.AddScoped(serviceProvider => serviceProvider.GetService().VoiceClient); + services.AddScoped(_ => new Jwt()); } private static void RegisterTransientServices(IServiceCollection services) @@ -102,10 +104,12 @@ private static void RegisterTransientServices(IServiceCollection services) services.AddTransient(serviceProvider => serviceProvider.GetService().ProactiveConnectClient); services.AddTransient(serviceProvider => serviceProvider.GetService().RedactClient); services.AddTransient(serviceProvider => serviceProvider.GetService().ShortCodesClient); + services.AddTransient(serviceProvider => serviceProvider.GetService().SubAccountsClient); services.AddTransient(serviceProvider => serviceProvider.GetService().SmsClient); services.AddTransient(serviceProvider => serviceProvider.GetService().UsersClient); services.AddTransient(serviceProvider => serviceProvider.GetService().VerifyClient); services.AddTransient(serviceProvider => serviceProvider.GetService().VerifyV2Client); services.AddTransient(serviceProvider => serviceProvider.GetService().VoiceClient); + services.AddTransient(_ => new Jwt()); } } \ No newline at end of file