Skip to content

Commit

Permalink
test: Adjusted the test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
real-zony committed Jan 8, 2024
1 parent 210eeb9 commit 56270cb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/EasyAbp.Abp.WeChat.Pay.Tests/AbpWeChatPayTestConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbpBlobStoringOptions>(options =>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -39,7 +40,7 @@ public async Task CreateOrderAsync_Test()
},
Payer = new CreateOrderPayerModel
{
OpenId = "YourOpenId" // 请替换为测试用户的 OpenId,具体 Id 可以在微信公众号平台-用户管理进行查看。
OpenId = AbpWeChatPayTestConsts.OpenId // 请替换为测试用户的 OpenId,具体 Id 可以在微信公众号平台-用户管理进行查看。
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ public async Task Should_Return_Certificate_Bytes()
var blobContainer = options.CertificateBlobContainerName.IsNullOrEmpty()
? GetRequiredService<IBlobContainer>()
: GetRequiredService<IBlobContainerFactory>().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);
}
}
}

0 comments on commit 56270cb

Please sign in to comment.