From 905ff36d7f6fc3662a8968f882fdb0dc8743f2dd Mon Sep 17 00:00:00 2001 From: Gary Jia Date: Mon, 16 Dec 2024 23:33:57 +0800 Subject: [PATCH] add tencent cloud sms test --- Directory.Packages.props | 3 +- framework/Volo.Abp.sln | 7 ++++ .../Volo.Abp.Sms.TencentCloud.csproj | 8 ++--- .../Sms/TencentCloud/TencentCloudSmsSender.cs | 3 +- .../Volo.Abp.Sms.TencentCloud.Tests.abppkg | 3 ++ .../Volo.Abp.Sms.TencentCloud.Tests.csproj | 26 ++++++++++++++ .../AbpSmsTencentCloudTestBase.cs | 11 ++++++ .../AbpSmsTencentCloudTestsModule.cs | 17 +++++++++ .../TencentCloudSmsSenderTests.cs | 36 +++++++++++++++++++ .../appsettings.json | 13 +++++++ 10 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs create mode 100644 framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json diff --git a/Directory.Packages.props b/Directory.Packages.props index 0602fe2658..9acb8f8bf7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -168,6 +168,7 @@ + @@ -177,4 +178,4 @@ - + \ No newline at end of file diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index eafe579a13..f716082008 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -475,6 +475,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.ExceptionHandling. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.TencentCloud", "src\Volo.Abp.Sms.TencentCloud\Volo.Abp.Sms.TencentCloud.csproj", "{BE7109C5-7368-4688-8557-4A15D3F4776A}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Sms.TencentCloud.Tests", "test\Volo.Abp.Sms.TencenCloud.Tests\Volo.Abp.Sms.TencentCloud.Tests.csproj", "{C753DDD6-5699-45F8-8669-08CE0BB816DE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1417,6 +1419,10 @@ Global {BE7109C5-7368-4688-8557-4A15D3F4776A}.Debug|Any CPU.Build.0 = Debug|Any CPU {BE7109C5-7368-4688-8557-4A15D3F4776A}.Release|Any CPU.ActiveCfg = Release|Any CPU {BE7109C5-7368-4688-8557-4A15D3F4776A}.Release|Any CPU.Build.0 = Release|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C753DDD6-5699-45F8-8669-08CE0BB816DE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1656,6 +1662,7 @@ Global {40FB8907-9CF7-44D0-8B5F-538AC6DAF8B9} = {447C8A77-E5F0-4538-8687-7383196D04EA} {E50739A7-5E2F-4EB5-AEA9-554115CB9613} = {447C8A77-E5F0-4538-8687-7383196D04EA} {BE7109C5-7368-4688-8557-4A15D3F4776A} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} + {C753DDD6-5699-45F8-8669-08CE0BB816DE} = {447C8A77-E5F0-4538-8687-7383196D04EA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj index 0aeef75e61..3077ff392e 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj @@ -18,13 +18,9 @@ - - - - - + - + diff --git a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs index bf09ad6f20..f0befb4af3 100644 --- a/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs +++ b/framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs @@ -22,7 +22,7 @@ public class TencentCloudSmsSender : ISmsSender, ITransientDependency { var client = CreateClient(); - await client.SendSms(new SendSmsRequest + var result = await client.SendSms(new SendSmsRequest() { SmsSdkAppId = Options.SmsSdkAppId, SignName = smsMessage.Properties.GetOrDefault(TencentCloudSmsProperties.SignName) as string, @@ -30,6 +30,7 @@ public class TencentCloudSmsSender : ISmsSender, ITransientDependency TemplateParamSet = smsMessage.Text.Split(','), PhoneNumberSet = [smsMessage.PhoneNumber] }); + } protected virtual SmsClient CreateClient() diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg new file mode 100644 index 0000000000..a686451fbc --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg @@ -0,0 +1,3 @@ +{ + "role": "lib.test" +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj new file mode 100644 index 0000000000..cd63f915d1 --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj @@ -0,0 +1,26 @@ + + + + + + net9.0 + + + + + + + + + + + + + + + + Always + + + + diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs new file mode 100644 index 0000000000..dfc666f21f --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs @@ -0,0 +1,11 @@ +using Volo.Abp.Testing; + +namespace Volo.Abp.Sms.TencentCloud; + +public class AbpSmsTencentCloudTestBase : AbpIntegratedTest +{ + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } +} diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs new file mode 100644 index 0000000000..f53cef85eb --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs @@ -0,0 +1,17 @@ +using Microsoft.Extensions.DependencyInjection; +using Volo.Abp.Modularity; + +namespace Volo.Abp.Sms.TencentCloud; + +[DependsOn(typeof(AbpSmsTencentCloudModule))] +public class AbpSmsTencentCloudTestsModule : AbpModule +{ + public override void ConfigureServices(ServiceConfigurationContext context) + { + var configuration = context.Services.GetConfiguration(); + + Configure( + configuration.GetSection("AbpTencentCloudSms") + ); + } +} diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs new file mode 100644 index 0000000000..9198f9b86d --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs @@ -0,0 +1,36 @@ +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Xunit; + +namespace Volo.Abp.Sms.TencentCloud; + +public class TencentCloudSmsSenderTests : AbpSmsTencentCloudTestBase +{ + private readonly ISmsSender _smsSender; + private readonly IConfiguration _configuration; + + public TencentCloudSmsSenderTests() + { + _configuration = GetRequiredService(); + _smsSender = GetRequiredService(); + } + + [Fact] + public async Task SendSms_Test() + { + var config = _configuration.GetSection("AbpTencentCloudSms"); + + // Please fill in the real parameters in the appsettings.json file. + if (config["SecretId"] == "") + { + return; + } + + var msg = new SmsMessage(config["TargetPhoneNumber"], + config["TemplateParam"]); + msg.Properties.Add(TencentCloudSmsProperties.SignName, config["SignName"]); + msg.Properties.Add(TencentCloudSmsProperties.TemplateId, config["TemplateId"]); + + await _smsSender.SendAsync(msg); + } +} diff --git a/framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json new file mode 100644 index 0000000000..44d4611caf --- /dev/null +++ b/framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json @@ -0,0 +1,13 @@ +{ + "AbpTencentCloudSms": { + "SecretId": "", + "SecretKey": "", + "Region": "", + "SmsSdkAppId": "", + "Endpoint": "", + "TargetPhoneNumber": "", + "SignName": "", + "TemplateId": "", + "TemplateParam": "" + } +} \ No newline at end of file