From 56270cb7f50bab2624d6bf99a820e1eeb250616a Mon Sep 17 00:00:00 2001 From: real-zony Date: Mon, 8 Jan 2024 10:57:21 +0800 Subject: [PATCH] test: Adjusted the test cases. --- .../Extensions/RandomStringHelper.cs | 9 ++++++--- .../AbpWeChatPayTestConsts.cs | 2 ++ .../AbpWeChatPayTestsModule.cs | 2 +- .../Services/BasicPaymentServiceTests.cs | 9 +++++---- .../Services/HttpClientCertificateTests.cs | 4 ++-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Common/EasyAbp.Abp.WeChat.Common/Extensions/RandomStringHelper.cs b/src/Common/EasyAbp.Abp.WeChat.Common/Extensions/RandomStringHelper.cs index c486c7e..dff70c0 100644 --- a/src/Common/EasyAbp.Abp.WeChat.Common/Extensions/RandomStringHelper.cs +++ b/src/Common/EasyAbp.Abp.WeChat.Common/Extensions/RandomStringHelper.cs @@ -5,13 +5,16 @@ namespace EasyAbp.Abp.WeChat.Common.Extensions { public static class RandomStringHelper { - public static string GetRandomString() + public static string GetRandomString(int length = 30) { - char[] constant = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; + char[] constant = + [ + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' + ]; var sb = new StringBuilder(); var rd = new Random(); - for (int i = 0; i < 30; i++) + for (var i = 0; i < length; i++) { sb.Append(constant[rd.Next(36)]); } diff --git a/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestConsts.cs b/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestConsts.cs index fc383bf..f03717f 100644 --- a/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestConsts.cs +++ b/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestConsts.cs @@ -5,7 +5,9 @@ public class AbpWeChatPayTestConsts public const bool IsSandBox = false; public const string MchId = ""; public const string ApiKey = ""; + public const string ApiV3Key = ""; public const string AppId = ""; public const string OpenId = ""; + public const string NotifyUrl = ""; } } \ No newline at end of file diff --git a/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestsModule.cs b/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestsModule.cs index 2639bb1..b7970ec 100644 --- a/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestsModule.cs +++ b/tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestsModule.cs @@ -23,12 +23,12 @@ public override void ConfigureServices(ServiceConfigurationContext context) op.MchId = mchId; op.ApiV3Key = AbpWeChatPayTestConsts.ApiKey; - // op.CertificateBlobContainerName = ""; op.CertificateBlobName = "apiclient_cert.p12"; op.CertificateSecret = mchId; op.NotifyUrl = $"https://my-abp-app.io/wechat-pay/notify/mch-id/{mchId}"; op.RefundNotifyUrl = $"https://my-abp-app.io/wechat-pay/refund-notify/mch-id/{mchId}"; op.IsSandBox = AbpWeChatPayTestConsts.IsSandBox; + op.ApiV3Key = AbpWeChatPayTestConsts.ApiV3Key; }); Configure(options => diff --git a/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/BasicPaymentServiceTests.cs b/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/BasicPaymentServiceTests.cs index 594d1a3..03a737c 100644 --- a/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/BasicPaymentServiceTests.cs +++ b/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/BasicPaymentServiceTests.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using EasyAbp.Abp.WeChat.Common.Extensions; using EasyAbp.Abp.WeChat.Pay.Services; using EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.JSPayment; using EasyAbp.Abp.WeChat.Pay.Services.BasicPayment.JSPayment.Models; @@ -28,9 +29,9 @@ public async Task CreateOrderAsync_Test() var response = await service.CreateOrderAsync(new CreateOrderRequest { MchId = service.MchId, - OutTradeNo = "20230816044401", - NotifyUrl = "https://weixin.qq.com/", - AppId = "YourAppId", // 请替换为你的 AppId + OutTradeNo = RandomStringHelper.GetRandomString(), + NotifyUrl = AbpWeChatPayTestConsts.NotifyUrl, + AppId = AbpWeChatPayTestConsts.AppId, // 请替换为你的 AppId Description = "Image形象店-深圳腾大-QQ公仔", Amount = new CreateOrderAmountModel { @@ -39,7 +40,7 @@ public async Task CreateOrderAsync_Test() }, Payer = new CreateOrderPayerModel { - OpenId = "YourOpenId" // 请替换为测试用户的 OpenId,具体 Id 可以在微信公众号平台-用户管理进行查看。 + OpenId = AbpWeChatPayTestConsts.OpenId // 请替换为测试用户的 OpenId,具体 Id 可以在微信公众号平台-用户管理进行查看。 } }); diff --git a/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/HttpClientCertificateTests.cs b/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/HttpClientCertificateTests.cs index c6161bf..72a6279 100644 --- a/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/HttpClientCertificateTests.cs +++ b/tests/EasyAbp.Abp.WeChat.Pay.Tests/Services/HttpClientCertificateTests.cs @@ -28,12 +28,12 @@ public async Task Should_Return_Certificate_Bytes() var blobContainer = options.CertificateBlobContainerName.IsNullOrEmpty() ? GetRequiredService() : GetRequiredService().Create(options.CertificateBlobContainerName); - + var certificateBytes = AsyncHelper.RunSync(() => blobContainer.GetAllBytesOrNullAsync(options.CertificateBlobName)); if (certificateBytes == null) throw new FileNotFoundException("指定的证书路径无效,请重新指定有效的证书文件路径。"); // Assert - certificateBytes.Length.ShouldBe(2); + certificateBytes.Length.ShouldNotBe(0); } } } \ No newline at end of file