-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace BD.Common.UnitTest; | ||
|
||
static partial class Constants | ||
{ | ||
public const int sms_length = 6; | ||
|
||
public const string sms_phone_number = "18611112211"; | ||
|
||
public static readonly bool enable_HuaWeiCloudSmsSenderProviderTest = true; // ²»Ê¹Óó£Á¿ | ||
|
||
public const string hwc_api_address = ""; | ||
|
||
public const string hwc_app_key = ""; | ||
|
||
public const string hwc_app_secret = ""; | ||
|
||
public const string hwc_signature = ""; | ||
|
||
public const string hwc_sender = ""; | ||
|
||
public const string hwc_status_callback = ""; | ||
|
||
public const string hwc_default_template = ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using BD.Common.Models.SmsSender.Channels.HuaWeiCloud; | ||
using BD.Common.Services; | ||
using BD.Common.Services.Implementation.SmsSender; | ||
using Microsoft.Extensions.Logging; | ||
using static BD.Common.UnitTest.Constants; | ||
using HuaWeiCloudSmsSenderProvider = BD.Common.Services.Implementation.SmsSender.Channels.HuaWeiCloud.SmsSenderProvider; | ||
|
||
namespace BD.Common.UnitTest; | ||
|
||
public sealed class SmsSenderTest | ||
{ | ||
static async Task GeneralTest( | ||
ISmsSender smsSender, | ||
string? message = null, | ||
bool generateRandomNum = true) | ||
{ | ||
if (generateRandomNum) | ||
{ | ||
message ??= string.Join(null, new char[sms_length].Select(x => '6')); | ||
} | ||
|
||
var sendSmsResult = await smsSender.SendSmsAsync(sms_phone_number, message!, 0); | ||
Assert.IsTrue(sendSmsResult.IsSuccess); | ||
TestContext.WriteLine($"HttpStatusCode: {sendSmsResult.HttpStatusCode}"); | ||
TestContext.WriteLine($"Record: {sendSmsResult.Result?.GetRecord()}"); | ||
|
||
var checkSmsResult = await smsSender.CheckSmsAsync(sms_phone_number, message!); | ||
Assert.IsTrue(checkSmsResult.IsCheckSuccess); | ||
} | ||
|
||
[Test] | ||
public async Task DebugSmsSenderProviderTest() | ||
{ | ||
ISmsSender smsSender = new DebugSmsSenderProvider(); | ||
await GeneralTest(smsSender); | ||
} | ||
|
||
[Test] | ||
public async Task HuaWeiCloudSmsSenderProviderTest() | ||
{ | ||
if (!enable_HuaWeiCloudSmsSenderProviderTest) | ||
return; | ||
|
||
using var httpClient = new HttpClient(); | ||
var loggerFactory = LoggerFactory.Create(static o => o.AddConsole()); | ||
var logger = loggerFactory.CreateLogger<HuaWeiCloudSmsSenderProvider>(); | ||
|
||
SmsHuaWeiCloudOptions options = new() | ||
{ | ||
ApiAddress = hwc_api_address, | ||
AppKey = hwc_app_key, | ||
AppSecret = hwc_app_secret, | ||
Signature = hwc_signature, | ||
Sender = hwc_sender, | ||
StatusCallBack = hwc_status_callback, | ||
DefaultTemplate = hwc_default_template, | ||
}; | ||
ISmsSender smsSender = new HuaWeiCloudSmsSenderProvider(logger, options, httpClient); | ||
await GeneralTest(smsSender); | ||
} | ||
} |