Browse Source

add tencent cloud sms test

pull/21651/head
Gary Jia 1 year ago
parent
commit
905ff36d7f
No known key found for this signature in database GPG Key ID: 6160CAEE492F0D35
  1. 3
      Directory.Packages.props
  2. 7
      framework/Volo.Abp.sln
  3. 8
      framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj
  4. 3
      framework/src/Volo.Abp.Sms.TencentCloud/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSender.cs
  5. 3
      framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg
  6. 26
      framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj
  7. 11
      framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestBase.cs
  8. 17
      framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/AbpSmsTencentCloudTestsModule.cs
  9. 36
      framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo/Abp/Sms/TencentCloud/TencentCloudSmsSenderTests.cs
  10. 13
      framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json

3
Directory.Packages.props

@ -168,6 +168,7 @@
<PackageVersion Include="System.Text.Json" Version="9.0.0.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.1.0" />
<PackageVersion Include="TencentCloudSDK.Sms" Version="3.0.1142" />
<PackageVersion Include="TimeZoneConverter" Version="6.1.0" />
<PackageVersion Include="Unidecode.NET" Version="2.1.0" />
<PackageVersion Include="xunit" Version="2.9.2" />
@ -177,4 +178,4 @@
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2" />
<PackageVersion Include="Fody" Version="6.8.2" />
</ItemGroup>
</Project>
</Project>

7
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}

8
framework/src/Volo.Abp.Sms.TencentCloud/Volo.Abp.Sms.TencentCloud.csproj

@ -18,13 +18,9 @@
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Sms\Volo.Abp.Sms.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="TencentCloudSDK" />
</ItemGroup>
<ItemGroup>
<PackageVersion Update="TencentCloudSDK" Version="3.0.1142" />
<PackageReference Include="TencentCloudSDK.Sms" />
</ItemGroup>
</Project>

3
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()

3
framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.abppkg

@ -0,0 +1,3 @@
{
"role": "lib.test"
}

26
framework/test/Volo.Abp.Sms.TencenCloud.Tests/Volo.Abp.Sms.TencentCloud.Tests.csproj

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\..\common.test.props" />
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Sms.TencentCloud\Volo.Abp.Sms.TencentCloud.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Sms\Volo.Abp.Sms.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>
<ItemGroup>
<None Remove="appsettings.json" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

11
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<AbpSmsTencentCloudTestsModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}

17
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<AbpTencentCloudSmsOptions>(
configuration.GetSection("AbpTencentCloudSms")
);
}
}

36
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<IConfiguration>();
_smsSender = GetRequiredService<ISmsSender>();
}
[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"] == "<Enter your SecretId from TencentCloud>")
{
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);
}
}

13
framework/test/Volo.Abp.Sms.TencenCloud.Tests/appsettings.json

@ -0,0 +1,13 @@
{
"AbpTencentCloudSms": {
"SecretId": "<Enter your SecretId from TencentCloud>",
"SecretKey": "<Enter your SecretKey from TencentCloud>",
"Region": "<Enter your Region from TencentCloud>",
"SmsSdkAppId": "<Enter your SmsSdkAppId from TencentCloud>",
"Endpoint": "<Enter your EndPoint from TencentCloud>",
"TargetPhoneNumber": "<Enter the target phone number to receive the SMS>",
"SignName": "<Enter the SignName from TencentCloud>",
"TemplateId": "<Enter the TemplateId you need to send>",
"TemplateParam": "<Enter the template parameters,split by ','>"
}
}
Loading…
Cancel
Save