From 01311c4e8990ea2aa09779df33157e8e5c99f439 Mon Sep 17 00:00:00 2001 From: tr00d Date: Wed, 19 Jun 2024 15:02:31 +0200 Subject: [PATCH] feat: add NumberVerificationClient in services collection extensions --- .../ServiceCollectionExtensionsTest.cs | 22 ++++++++++--------- .../Extensions/ServiceCollectionExtensions.cs | 12 +++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs b/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs index 7527f902..6c3cd71d 100644 --- a/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs +++ b/Vonage.Test/Extensions/ServiceCollectionExtensionsTest.cs @@ -13,6 +13,7 @@ using Vonage.NumberInsights; using Vonage.NumberInsightV2; using Vonage.Numbers; +using Vonage.NumberVerification; using Vonage.Pricing; using Vonage.ProactiveConnect; using Vonage.Redaction; @@ -39,9 +40,9 @@ public class ServiceCollectionExtensionsTest {"vonage:Vonage_key", "RandomValue"}, }) .Build(); - + private readonly Credentials credentials = Credentials.FromApiKeyAndSecret("key", "secret"); - + [Theory] [MemberData(nameof(GetRegisteredTypes))] public void AddVonageClientScoped_ShouldProvideScopedInstance_GivenConfigurationIsProvided( @@ -50,7 +51,7 @@ public void AddVonageClientScoped_ShouldProvideScopedInstance_GivenConfiguration var provider = BuildScopedProviderWithConfiguration(this.configuration); provider.GetRequiredService(type).Should().Be(provider.GetRequiredService(type)); } - + [Theory] [MemberData(nameof(GetRegisteredTypes))] public void AddVonageClientScoped_ShouldProvideScopedInstance_GivenCredentialsAreProvided( @@ -59,7 +60,7 @@ public void AddVonageClientScoped_ShouldProvideScopedInstance_GivenCredentialsAr var provider = BuildScopedProviderWithCredentials(this.credentials); provider.GetRequiredService(type).Should().Be(provider.GetRequiredService(type)); } - + [Theory] [MemberData(nameof(GetRegisteredTypes))] public void @@ -69,7 +70,7 @@ public void var provider = BuildTransientProviderWithConfiguration(this.configuration); provider.GetRequiredService(type).Should().NotBeNull(); } - + [Theory] [MemberData(nameof(GetRegisteredTypes))] public void AddVonageClientTransient_ShouldProvideTransientInstance_GivenCredentialsAreProvided( @@ -78,7 +79,7 @@ public void AddVonageClientTransient_ShouldProvideTransientInstance_GivenCredent var provider = BuildTransientProviderWithCredentials(this.credentials); provider.GetRequiredService(type).Should().NotBeNull(); } - + public static IEnumerable GetRegisteredTypes() { yield return new object[] {typeof(VonageClient)}; @@ -90,6 +91,7 @@ public static IEnumerable GetRegisteredTypes() yield return new object[] {typeof(INumberInsightClient)}; yield return new object[] {typeof(INumberInsightV2Client)}; yield return new object[] {typeof(INumbersClient)}; + yield return new object[] {typeof(INumberVerificationClient)}; yield return new object[] {typeof(IPricingClient)}; yield return new object[] {typeof(IProactiveConnectClient)}; yield return new object[] {typeof(IRedactClient)}; @@ -106,16 +108,16 @@ public static IEnumerable GetRegisteredTypes() yield return new object[] {typeof(IVideoTokenGenerator)}; yield return new object[] {typeof(Credentials)}; } - + 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(); } diff --git a/Vonage/Extensions/ServiceCollectionExtensions.cs b/Vonage/Extensions/ServiceCollectionExtensions.cs index 76dd4d1e..15dca266 100644 --- a/Vonage/Extensions/ServiceCollectionExtensions.cs +++ b/Vonage/Extensions/ServiceCollectionExtensions.cs @@ -24,7 +24,7 @@ public static IServiceCollection AddVonageClientScoped(this IServiceCollection s RegisterScopedServices(services); return services; } - + /// /// Adds a scoped service of , and all api-specific clients, to the specified /// IServiceCollection. @@ -41,7 +41,7 @@ public static IServiceCollection AddVonageClientScoped(this IServiceCollection s RegisterScopedServices(services); return services; } - + /// /// Adds a transient service of , and all api-specific clients, to the specified /// IServiceCollection. @@ -56,7 +56,7 @@ public static IServiceCollection AddVonageClientTransient(this IServiceCollectio RegisterTransientServices(services); return services; } - + /// /// Adds a transient service of , and all api-specific clients, to the specified /// IServiceCollection. @@ -73,7 +73,7 @@ public static IServiceCollection AddVonageClientTransient(this IServiceCollectio RegisterTransientServices(services); return services; } - + private static void RegisterScopedServices(IServiceCollection services) { services.AddScoped(serviceProvider => serviceProvider.GetService().AccountClient); @@ -84,6 +84,7 @@ private static void RegisterScopedServices(IServiceCollection services) services.AddScoped(serviceProvider => serviceProvider.GetService().NumberInsightClient); services.AddScoped(serviceProvider => serviceProvider.GetService().NumberInsightV2Client); services.AddScoped(serviceProvider => serviceProvider.GetService().NumbersClient); + services.AddScoped(serviceProvider => serviceProvider.GetService().NumberVerificationClient); services.AddScoped(serviceProvider => serviceProvider.GetService().PricingClient); services.AddScoped(serviceProvider => serviceProvider.GetService().ProactiveConnectClient); services.AddScoped(serviceProvider => serviceProvider.GetService().RedactClient); @@ -99,7 +100,7 @@ private static void RegisterScopedServices(IServiceCollection services) services.AddScoped(_ => new Jwt()); services.AddScoped(_ => new VideoTokenGenerator()); } - + private static void RegisterTransientServices(IServiceCollection services) { services.AddTransient(serviceProvider => serviceProvider.GetService().AccountClient); @@ -110,6 +111,7 @@ private static void RegisterTransientServices(IServiceCollection services) services.AddTransient(serviceProvider => serviceProvider.GetService().NumberInsightClient); services.AddTransient(serviceProvider => serviceProvider.GetService().NumberInsightV2Client); services.AddTransient(serviceProvider => serviceProvider.GetService().NumbersClient); + services.AddTransient(serviceProvider => serviceProvider.GetService().NumberVerificationClient); services.AddTransient(serviceProvider => serviceProvider.GetService().PricingClient); services.AddTransient(serviceProvider => serviceProvider.GetService().ProactiveConnectClient); services.AddTransient(serviceProvider => serviceProvider.GetService().RedactClient);