mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2026-02-11 10:16:20 +08:00
feat(tenpayv2): 升级公共组件
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"out_refund_no": "131811191610442717309",
|
||||
"out_trade_no": "71106718111915575302817",
|
||||
"refund_account": "REFUND_SOURCE_RECHARGE_FUNDS",
|
||||
"refund_fee": "3960",
|
||||
"refund_id": "50000408942018111907145868882",
|
||||
"refund_recv_accout": "支付用户零钱",
|
||||
"refund_request_source": "API",
|
||||
"refund_status": "SUCCESS",
|
||||
"settlement_refund_fee": "3960",
|
||||
"settlement_total_fee": "3960",
|
||||
"success_time": "2018-11-19 16:24:13",
|
||||
"total_fee": "3960",
|
||||
"transaction_id": "4200000215201811190261405420"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using SKIT.FlurlHttpClient.Tools.CodeAnalyzer;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class CodeAnalyzeTests
|
||||
{
|
||||
[Fact(DisplayName = "代码质量分析")]
|
||||
public void CodeAnalyze()
|
||||
{
|
||||
Assert.Null(Record.Exception(() =>
|
||||
{
|
||||
var options = new TypeDeclarationAnalyzerOptions()
|
||||
{
|
||||
SdkAssembly = Assembly.GetAssembly(typeof(WechatTenpayClient))!,
|
||||
SdkRequestModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2.Models",
|
||||
SdkResponseModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2.Models",
|
||||
SdkExecutingExtensionDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2",
|
||||
SdkWebhookEventDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2.Events",
|
||||
ThrowOnNotFoundRequestModelTypes = true,
|
||||
ThrowOnNotFoundResponseModelTypes = true,
|
||||
ThrowOnNotFoundExecutingExtensionTypes = true,
|
||||
ThrowOnNotFoundWebhookEventTypes = true
|
||||
};
|
||||
new TypeDeclarationAnalyzer(options).AssertNoIssues();
|
||||
}));
|
||||
|
||||
Assert.Null(Record.Exception(() =>
|
||||
{
|
||||
string workdir = Environment.CurrentDirectory;
|
||||
string projdir = Path.Combine(workdir, "../../../../../");
|
||||
|
||||
var options = new SourceFileAnalyzerOptions()
|
||||
{
|
||||
SdkAssembly = Assembly.GetAssembly(typeof(WechatTenpayClient))!,
|
||||
SdkRequestModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2.Models",
|
||||
SdkResponseModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2.Models",
|
||||
SdkWebhookEventDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV2.Events",
|
||||
ProjectSourceRootDirectory = Path.Combine(projdir, "./src/SKIT.FlurlHttpClient.Wechat.TenpayV2/"),
|
||||
ProjectTestRootDirectory = Path.Combine(projdir, "./test/SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests/"),
|
||||
ThrowOnNotFoundRequestModelClassCodeFiles = true,
|
||||
ThrowOnNotFoundResponseModelClassCodeFiles = true,
|
||||
ThrowOnNotFoundExecutingExtensionClassCodeFiles = true,
|
||||
ThrowOnNotFoundWebhookEventClassCodeFiles = true,
|
||||
ThrowOnNotFoundRequestModelSerializationSampleFiles = true,
|
||||
ThrowOnNotFoundResponseModelSerializationSampleFiles = true,
|
||||
ThrowOnNotFoundWebhookEventSerializationSampleFiles = true
|
||||
};
|
||||
new SourceFileAnalyzer(options).AssertNoIssues();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,23 +10,23 @@
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove=".gitignore" />
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="appsettings.*.json" Condition="'$(Configuration)' == 'Debug'">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</Content>
|
||||
<Content Include="appsettings.*.json" Condition="'$(Configuration)' == 'Debug'">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="ModelSamples/**/*.json" />
|
||||
<Content Include="EventSamples/**/*.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
|
||||
<PackageReference Include="SKIT.FlurlHttpClient.Tools.CodeAnalyzer" Version="0.1.0-alpha.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="SKIT.FlurlHttpClient.Tools.CodeAnalyzer" Version="0.3.0-preview.1" />
|
||||
<PackageReference Include="xunit" Version="2.6.6" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using SKIT.FlurlHttpClient.Tools.CodeAnalyzer;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class TestCase_CodeReview
|
||||
{
|
||||
[Fact(DisplayName = "测试用例:代码质量分析")]
|
||||
public void TestCodeAnalyzer()
|
||||
{
|
||||
Assert.Null(Record.Exception(() =>
|
||||
{
|
||||
CodeAnalyzerOptions options = new CodeAnalyzerOptions()
|
||||
{
|
||||
AssemblyName = "SKIT.FlurlHttpClient.Wechat.TenpayV2",
|
||||
WorkDirectoryForSourceCode = TestConfigs.WorkDirectoryForSdk,
|
||||
WorkDirectoryForTestSample = TestConfigs.WorkDirectoryForTest,
|
||||
AllowNotFoundEventTypes = true,
|
||||
AllowNotFoundEventSamples = true
|
||||
};
|
||||
CodeAnalyzer analyzer = new CodeAnalyzer(options);
|
||||
analyzer.Start();
|
||||
analyzer.Assert();
|
||||
analyzer.Flush();
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Xunit;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
@@ -11,7 +11,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
string merchantId = "10000100";
|
||||
string merchantSecret = "192006250b4c09247ec02edce69f6a2d";
|
||||
|
||||
var client = new WechatTenpayClient(merchantId, merchantSecret);
|
||||
var client = new WechatTenpayClient(new WechatTenpayClientOptions() { MerchantId = merchantId, MerchantSecret = merchantSecret });
|
||||
Assert.True(client.VerifyEventSignature(callbackXml));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class TestCase_JsonConverterOfFlattenNArrayObjectTest
|
||||
{
|
||||
private static void TestCustomJsonConverter(IJsonSerializer jsonSerializer)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
string expectedJson = "{\"return_code\":\"RETURN_CODE\",\"return_msg\":\"RETURN_MSG\",\"sign\":\"SIGN\",\"appid\":\"APPID\",\"mch_id\":\"MCH_ID\",\"result_code\":\"RESULT_CODE\",\"err_code\":\"ERR_CODE\",\"err_code_des\":\"ERR_CODE_DESC\",\"transaction_id\":\"TRANSACTION_ID\",\"count\":2,\"sub_order_no_0\":\"SUB_ORDER_NO_0\",\"sub_order_id_0\":\"SUB_ORDER_ID_0\",\"mch_customs_no_0\":\"MCH_CUSTOMS_NO_0\",\"customs_0\":\"CUSTOMS_0\",\"duty_0\":10,\"fee_type_0\":\"FEE_TYPE_0\",\"order_fee_0\":10,\"transport_fee_0\":10,\"product_fee_0\":10,\"state_0\":\"STATE_0\",\"explanation_0\":\"EXPLANATION_0\",\"modify_time_0\":\"20000101112233\",\"cert_check_result_0\":\"UNCHECKED\",\"sub_order_no_1\":\"SUB_ORDER_NO_1\",\"sub_order_id_1\":\"SUB_ORDER_ID_1\",\"mch_customs_no_1\":\"MCH_CUSTOMS_NO_1\",\"customs_1\":\"CUSTOMS_1\",\"duty_1\":11,\"fee_type_1\":\"FEE_TYPE_1\",\"order_fee_1\":11,\"transport_fee_1\":11,\"product_fee_1\":11,\"state_1\":\"STATE_1\",\"explanation_1\":\"EXPLANATION_1\",\"modify_time_1\":\"20010101112233\",\"cert_check_result_1\":\"UNCHECKED1\"}";
|
||||
var actualObj = jsonSerializer.Deserialize<Models.QueryMerchantCustomsCustomDeclarationResponse>(expectedJson);
|
||||
|
||||
Assert.Equal("RETURN_CODE", actualObj.ReturnCode);
|
||||
Assert.Equal("RETURN_MSG", actualObj.ReturnMessage);
|
||||
Assert.Equal("SIGN", actualObj.Signature);
|
||||
Assert.Equal("APPID", actualObj.AppId);
|
||||
Assert.Equal("MCH_ID", actualObj.MerchantId);
|
||||
Assert.Equal("RESULT_CODE", actualObj.ResultCode);
|
||||
Assert.Equal("ERR_CODE", actualObj.ErrorCode);
|
||||
Assert.Equal("ERR_CODE_DESC", actualObj.ErrorCodeDescription);
|
||||
Assert.Equal("TRANSACTION_ID", actualObj.TransactionId);
|
||||
Assert.Equal(2, actualObj.RecordCount);
|
||||
Assert.Equal("SUB_ORDER_NO_0", actualObj.RecordList[0].SubOrderNumber);
|
||||
Assert.Equal("SUB_ORDER_ID_0", actualObj.RecordList[0].SubOrderId);
|
||||
Assert.Equal("MCH_CUSTOMS_NO_0", actualObj.RecordList[0].MerchantCustomsNumber);
|
||||
Assert.Equal("CUSTOMS_0", actualObj.RecordList[0].Customs);
|
||||
Assert.Equal(10, actualObj.RecordList[0].Duty);
|
||||
Assert.Equal("FEE_TYPE_0", actualObj.RecordList[0].FeeType);
|
||||
Assert.Equal(DateTimeOffset.Parse("2000-01-01 11:22:33"), actualObj.RecordList[0].ModifyTime);
|
||||
Assert.Equal("SUB_ORDER_NO_1", actualObj.RecordList[1].SubOrderNumber);
|
||||
Assert.Equal("SUB_ORDER_ID_1", actualObj.RecordList[1].SubOrderId);
|
||||
Assert.Equal("MCH_CUSTOMS_NO_1", actualObj.RecordList[1].MerchantCustomsNumber);
|
||||
Assert.Equal("CUSTOMS_1", actualObj.RecordList[1].Customs);
|
||||
Assert.Equal(11, actualObj.RecordList[1].Duty);
|
||||
Assert.Equal("FEE_TYPE_1", actualObj.RecordList[1].FeeType);
|
||||
Assert.Equal(DateTimeOffset.Parse("2001-01-01 11:22:33"), actualObj.RecordList[1].ModifyTime);
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var expectedObj = new Models.QueryMerchantCustomsCustomDeclarationResponse()
|
||||
{
|
||||
ReturnCode = "RETURN_CODE",
|
||||
ReturnMessage = "RETURN_MSG",
|
||||
AppId = "APPID",
|
||||
MerchantId = "MCH_ID",
|
||||
ResultCode = "RESULT_CODE",
|
||||
ErrorCode = "ERR_CODE",
|
||||
ErrorCodeDescription = "ERR_CODE_DESC",
|
||||
TransactionId = "TRANSACTION_ID",
|
||||
RecordCount = 2,
|
||||
RecordList = new Models.QueryMerchantCustomsCustomDeclarationResponse.Types.Record[]
|
||||
{
|
||||
new Models.QueryMerchantCustomsCustomDeclarationResponse.Types.Record()
|
||||
{
|
||||
SubOrderNumber = "SUB_ORDER_NO_0",
|
||||
SubOrderId = "SUB_ORDER_ID_0",
|
||||
MerchantCustomsNumber = "MCH_CUSTOMS_NO_0",
|
||||
Customs = "CUSTOMS_0",
|
||||
Duty = 10,
|
||||
FeeType = "FEE_TYPE_0",
|
||||
ModifyTime = DateTimeOffset.Parse("2000-01-01 11:22:33"),
|
||||
},
|
||||
new Models.QueryMerchantCustomsCustomDeclarationResponse.Types.Record()
|
||||
{
|
||||
SubOrderNumber = "SUB_ORDER_NO_1",
|
||||
SubOrderId = "SUB_ORDER_ID_1",
|
||||
MerchantCustomsNumber = "MCH_CUSTOMS_NO_1",
|
||||
Customs = "CUSTOMS_1",
|
||||
Duty = 11,
|
||||
FeeType = "FEE_TYPE_1",
|
||||
ModifyTime = DateTimeOffset.Parse("2001-01-01 11:22:33"),
|
||||
}
|
||||
}
|
||||
};
|
||||
string actualJson = jsonSerializer.Serialize(expectedObj);
|
||||
|
||||
Assert.Null(Record.Exception(() => jsonSerializer.Deserialize<dynamic>(actualJson)));
|
||||
|
||||
Assert.DoesNotContain("#n", actualJson);
|
||||
Assert.DoesNotContain("$n", actualJson);
|
||||
|
||||
Assert.Contains("\"return_code\"", actualJson);
|
||||
Assert.Contains("\"RETURN_CODE\"", actualJson);
|
||||
Assert.Contains("\"return_msg\"", actualJson);
|
||||
Assert.Contains("\"RETURN_MSG\"", actualJson);
|
||||
Assert.Contains("\"sub_order_no_0\"", actualJson);
|
||||
Assert.Contains("\"SUB_ORDER_NO_0\"", actualJson);
|
||||
Assert.Contains("\"sub_order_id_0\"", actualJson);
|
||||
Assert.Contains("\"SUB_ORDER_ID_0\"", actualJson);
|
||||
Assert.Contains("\"sub_order_no_1\"", actualJson);
|
||||
Assert.Contains("\"SUB_ORDER_NO_1\"", actualJson);
|
||||
Assert.Contains("\"sub_order_id_1\"", actualJson);
|
||||
Assert.Contains("\"SUB_ORDER_ID_1\"", actualJson);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:自定义 Newtosoft.Json.JsonConverter 之 FlattenNArrayObjectConverterBase")]
|
||||
public void TestNewtosoftJsonConverter()
|
||||
{
|
||||
var jsonSettings = NewtonsoftJsonSerializer.GetDefaultSerializerSettings();
|
||||
jsonSettings.Formatting = Newtonsoft.Json.Formatting.None;
|
||||
jsonSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
|
||||
|
||||
TestCustomJsonConverter(new NewtonsoftJsonSerializer(jsonSettings));
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:自定义 System.Text.Json.Serialization.JsonConverter 之 FlattenNArrayObjectConverterBase")]
|
||||
public void TestSystemTextJsonConverter()
|
||||
{
|
||||
var jsonOptions = SystemTextJsonSerializer.GetDefaultSerializerOptions();
|
||||
jsonOptions.WriteIndented = false;
|
||||
jsonOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
|
||||
|
||||
TestCustomJsonConverter(new SystemTextJsonSerializer(jsonOptions));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class TestCase_JsonConverterOfYesOrNoBooleanBooleanTest
|
||||
{
|
||||
private sealed class MockObject
|
||||
{
|
||||
[Newtonsoft.Json.JsonProperty(Order = 1)]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.Internal.YesOrNoBooleanConverter))]
|
||||
[System.Text.Json.Serialization.JsonPropertyOrder(1)]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Internal.YesOrNoBooleanConverter))]
|
||||
public bool Property { get; set; }
|
||||
|
||||
[Newtonsoft.Json.JsonProperty(Order = 2)]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.Internal.YesOrNoBooleanConverter))]
|
||||
[System.Text.Json.Serialization.JsonPropertyOrder(2)]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Internal.YesOrNoBooleanConverter))]
|
||||
public bool? NullableProperty { get; set; }
|
||||
}
|
||||
|
||||
private static void TestCustomJsonConverter(IJsonSerializer jsonSerializer)
|
||||
{
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var expectObj = new MockObject() { NullableProperty = null };
|
||||
var actualJson = jsonSerializer.Serialize(expectObj);
|
||||
var actualObj = jsonSerializer.Deserialize<MockObject>(actualJson);
|
||||
|
||||
Assert.Equal("{\"Property\":\"N\"}", actualJson);
|
||||
|
||||
Assert.Equal(expectObj.Property, actualObj.Property);
|
||||
Assert.Equal(expectObj.Property, jsonSerializer.Deserialize<MockObject>("{\"Property\":\"N\"}").Property);
|
||||
Assert.Equal(expectObj.Property, jsonSerializer.Deserialize<MockObject>("{}").Property);
|
||||
|
||||
Assert.Equal(expectObj.NullableProperty, actualObj.NullableProperty);
|
||||
Assert.Equal(expectObj.NullableProperty, jsonSerializer.Deserialize<MockObject>("{\"NullableProperty\":null}").NullableProperty);
|
||||
Assert.Equal(expectObj.NullableProperty, jsonSerializer.Deserialize<MockObject>("{}").NullableProperty);
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var expectObj = new MockObject() { Property = false, NullableProperty = false };
|
||||
var actualJson = jsonSerializer.Serialize(expectObj);
|
||||
var actualObj = jsonSerializer.Deserialize<MockObject>(actualJson);
|
||||
|
||||
Assert.Equal("{\"Property\":\"N\",\"NullableProperty\":\"N\"}", actualJson);
|
||||
|
||||
Assert.Equal(expectObj.Property, actualObj.Property);
|
||||
Assert.Equal(expectObj.Property, jsonSerializer.Deserialize<MockObject>("{\"Property\":false}").Property);
|
||||
|
||||
Assert.Equal(expectObj.NullableProperty, actualObj.NullableProperty);
|
||||
Assert.Equal(expectObj.NullableProperty, jsonSerializer.Deserialize<MockObject>("{\"NullableProperty\":false}").NullableProperty);
|
||||
});
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
var expectObj = new MockObject() { Property = true, NullableProperty = true };
|
||||
var actualJson = jsonSerializer.Serialize(expectObj);
|
||||
var actualObj = jsonSerializer.Deserialize<MockObject>(actualJson);
|
||||
|
||||
Assert.Equal("{\"Property\":\"Y\",\"NullableProperty\":\"Y\"}", actualJson);
|
||||
|
||||
Assert.Equal(expectObj.Property, actualObj.Property);
|
||||
Assert.Equal(expectObj.Property, jsonSerializer.Deserialize<MockObject>("{\"Property\":true}").Property);
|
||||
|
||||
Assert.Equal(expectObj.NullableProperty, actualObj.NullableProperty);
|
||||
Assert.Equal(expectObj.NullableProperty, jsonSerializer.Deserialize<MockObject>("{\"NullableProperty\":true}").NullableProperty);
|
||||
});
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:自定义 Newtosoft.Json.JsonConverter 之 YesOrNoBooleanConverter")]
|
||||
public void TestNewtosoftJsonConverter()
|
||||
{
|
||||
var jsonSettings = NewtonsoftJsonSerializer.GetDefaultSerializerSettings();
|
||||
jsonSettings.Formatting = Newtonsoft.Json.Formatting.None;
|
||||
jsonSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
|
||||
|
||||
TestCustomJsonConverter(new NewtonsoftJsonSerializer(jsonSettings));
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:自定义 System.Text.Json.Serialization.JsonConverter 之 YesOrNoBooleanConverter")]
|
||||
public void TestSystemTextJsonConverter()
|
||||
{
|
||||
var jsonOptions = SystemTextJsonSerializer.GetDefaultSerializerOptions();
|
||||
jsonOptions.WriteIndented = false;
|
||||
jsonOptions.DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull;
|
||||
|
||||
TestCustomJsonConverter(new SystemTextJsonSerializer(jsonOptions));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class TestCase_JsonConverterTests
|
||||
{
|
||||
[Fact(DisplayName = "测试用例:自定义转换器之 `FlattenNArrayObjectConverterBase`")]
|
||||
public void TestFlattenNArrayObjectConverter()
|
||||
{
|
||||
var newtonsoftJsonSerializer = new FlurlNewtonsoftJsonSerializer();
|
||||
var systemTextJsonSerializer = new FlurlSystemTextJsonSerializer();
|
||||
|
||||
string rawJson = "{\"return_code\":\"RETURN_CODE\",\"return_msg\":\"RETURN_MSG\",\"sign\":\"SIGN\",\"appid\":\"APPID\",\"mch_id\":\"MCH_ID\",\"result_code\":\"RESULT_CODE\",\"err_code\":\"ERR_CODE\",\"err_code_des\":\"ERR_CODE_DESC\",\"transaction_id\":\"TRANSACTION_ID\",\"count\":2,\"sub_order_no_0\":\"SUB_ORDER_NO_0\",\"sub_order_id_0\":\"SUB_ORDER_ID_0\",\"mch_customs_no_0\":\"MCH_CUSTOMS_NO_0\",\"customs_0\":\"CUSTOMS_0\",\"duty_0\":10,\"fee_type_0\":\"FEE_TYPE_0\",\"order_fee_0\":10,\"transport_fee_0\":10,\"product_fee_0\":10,\"state_0\":\"STATE_0\",\"explanation_0\":\"EXPLANATION_0\",\"modify_time_0\":\"20000101112233\",\"cert_check_result_0\":\"UNCHECKED\",\"sub_order_no_1\":\"SUB_ORDER_NO_1\",\"sub_order_id_1\":\"SUB_ORDER_ID_1\",\"mch_customs_no_1\":\"MCH_CUSTOMS_NO_1\",\"customs_1\":\"CUSTOMS_1\",\"duty_1\":11,\"fee_type_1\":\"FEE_TYPE_1\",\"order_fee_1\":11,\"transport_fee_1\":11,\"product_fee_1\":11,\"state_1\":\"STATE_1\",\"explanation_1\":\"EXPLANATION_1\",\"modify_time_1\":\"20010101112233\",\"cert_check_result_1\":\"UNCHECKED1\"}";
|
||||
var parsedObjByNewtonsoftJson = newtonsoftJsonSerializer.Deserialize<Models.QueryMerchantCustomsCustomDeclarationResponse>(rawJson);
|
||||
var parsedObjBySystemTextJson = systemTextJsonSerializer.Deserialize<Models.QueryMerchantCustomsCustomDeclarationResponse>(rawJson);
|
||||
|
||||
Assert.Equal("RETURN_CODE", parsedObjByNewtonsoftJson.ReturnCode);
|
||||
Assert.Equal("RETURN_CODE", parsedObjBySystemTextJson.ReturnCode);
|
||||
Assert.Equal("RETURN_MSG", parsedObjByNewtonsoftJson.ReturnMessage);
|
||||
Assert.Equal("RETURN_MSG", parsedObjBySystemTextJson.ReturnMessage);
|
||||
Assert.Equal("SIGN", parsedObjByNewtonsoftJson.Signature);
|
||||
Assert.Equal("SIGN", parsedObjBySystemTextJson.Signature);
|
||||
Assert.Equal("APPID", parsedObjByNewtonsoftJson.AppId);
|
||||
Assert.Equal("APPID", parsedObjBySystemTextJson.AppId);
|
||||
Assert.Equal("MCH_ID", parsedObjByNewtonsoftJson.MerchantId);
|
||||
Assert.Equal("MCH_ID", parsedObjBySystemTextJson.MerchantId);
|
||||
Assert.Equal("RESULT_CODE", parsedObjByNewtonsoftJson.ResultCode);
|
||||
Assert.Equal("RESULT_CODE", parsedObjBySystemTextJson.ResultCode);
|
||||
Assert.Equal("ERR_CODE", parsedObjByNewtonsoftJson.ErrorCode);
|
||||
Assert.Equal("ERR_CODE", parsedObjBySystemTextJson.ErrorCode);
|
||||
Assert.Equal("ERR_CODE_DESC", parsedObjByNewtonsoftJson.ErrorCodeDescription);
|
||||
Assert.Equal("ERR_CODE_DESC", parsedObjBySystemTextJson.ErrorCodeDescription);
|
||||
Assert.Equal("TRANSACTION_ID", parsedObjByNewtonsoftJson.TransactionId);
|
||||
Assert.Equal("TRANSACTION_ID", parsedObjBySystemTextJson.TransactionId);
|
||||
Assert.Equal(2, parsedObjByNewtonsoftJson.RecordCount);
|
||||
Assert.Equal(2, parsedObjBySystemTextJson.RecordCount);
|
||||
Assert.Equal("SUB_ORDER_NO_0", parsedObjByNewtonsoftJson.RecordList[0].SubOrderNumber);
|
||||
Assert.Equal("SUB_ORDER_NO_0", parsedObjBySystemTextJson.RecordList[0].SubOrderNumber);
|
||||
Assert.Equal("SUB_ORDER_ID_0", parsedObjByNewtonsoftJson.RecordList[0].SubOrderId);
|
||||
Assert.Equal("SUB_ORDER_ID_0", parsedObjBySystemTextJson.RecordList[0].SubOrderId);
|
||||
Assert.Equal("MCH_CUSTOMS_NO_0", parsedObjByNewtonsoftJson.RecordList[0].MerchantCustomsNumber);
|
||||
Assert.Equal("MCH_CUSTOMS_NO_0", parsedObjBySystemTextJson.RecordList[0].MerchantCustomsNumber);
|
||||
Assert.Equal("CUSTOMS_0", parsedObjByNewtonsoftJson.RecordList[0].Customs);
|
||||
Assert.Equal("CUSTOMS_0", parsedObjBySystemTextJson.RecordList[0].Customs);
|
||||
Assert.Equal(10, parsedObjByNewtonsoftJson.RecordList[0].Duty);
|
||||
Assert.Equal(10, parsedObjBySystemTextJson.RecordList[0].Duty);
|
||||
Assert.Equal("FEE_TYPE_0", parsedObjByNewtonsoftJson.RecordList[0].FeeType);
|
||||
Assert.Equal("FEE_TYPE_0", parsedObjBySystemTextJson.RecordList[0].FeeType);
|
||||
Assert.Equal(DateTimeOffset.Parse("2000-01-01 11:22:33"), parsedObjByNewtonsoftJson.RecordList[0].ModifyTime);
|
||||
Assert.Equal(DateTimeOffset.Parse("2000-01-01 11:22:33"), parsedObjBySystemTextJson.RecordList[0].ModifyTime);
|
||||
Assert.Equal("SUB_ORDER_NO_1", parsedObjByNewtonsoftJson.RecordList[1].SubOrderNumber);
|
||||
Assert.Equal("SUB_ORDER_NO_1", parsedObjBySystemTextJson.RecordList[1].SubOrderNumber);
|
||||
Assert.Equal("SUB_ORDER_ID_1", parsedObjByNewtonsoftJson.RecordList[1].SubOrderId);
|
||||
Assert.Equal("SUB_ORDER_ID_1", parsedObjBySystemTextJson.RecordList[1].SubOrderId);
|
||||
Assert.Equal("MCH_CUSTOMS_NO_1", parsedObjByNewtonsoftJson.RecordList[1].MerchantCustomsNumber);
|
||||
Assert.Equal("MCH_CUSTOMS_NO_1", parsedObjBySystemTextJson.RecordList[1].MerchantCustomsNumber);
|
||||
Assert.Equal("CUSTOMS_1", parsedObjByNewtonsoftJson.RecordList[1].Customs);
|
||||
Assert.Equal("CUSTOMS_1", parsedObjBySystemTextJson.RecordList[1].Customs);
|
||||
Assert.Equal(11, parsedObjByNewtonsoftJson.RecordList[1].Duty);
|
||||
Assert.Equal(11, parsedObjBySystemTextJson.RecordList[1].Duty);
|
||||
Assert.Equal("FEE_TYPE_1", parsedObjByNewtonsoftJson.RecordList[1].FeeType);
|
||||
Assert.Equal("FEE_TYPE_1", parsedObjBySystemTextJson.RecordList[1].FeeType);
|
||||
Assert.Equal(DateTimeOffset.Parse("2001-01-01 11:22:33"), parsedObjByNewtonsoftJson.RecordList[1].ModifyTime);
|
||||
Assert.Equal(DateTimeOffset.Parse("2001-01-01 11:22:33"), parsedObjBySystemTextJson.RecordList[1].ModifyTime);
|
||||
|
||||
string unparsedJsonByNewtonsoftJson = newtonsoftJsonSerializer.Serialize(parsedObjByNewtonsoftJson);
|
||||
string unparsedJsonBySystemTextJson = systemTextJsonSerializer.Serialize(parsedObjByNewtonsoftJson);
|
||||
|
||||
Assert.Null(Record.Exception(() => Newtonsoft.Json.JsonConvert.DeserializeObject(unparsedJsonByNewtonsoftJson)));
|
||||
Assert.Null(Record.Exception(() => System.Text.Json.JsonDocument.Parse(unparsedJsonBySystemTextJson)));
|
||||
Assert.Contains("return_code", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("return_code", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("RETURN_CODE", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("RETURN_CODE", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("return_msg", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("return_msg", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("RETURN_MSG", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("RETURN_MSG", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("sub_order_no_0", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("sub_order_no_0", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("SUB_ORDER_NO_0", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("SUB_ORDER_NO_0", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("sub_order_id_0", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("sub_order_id_0", unparsedJsonBySystemTextJson);
|
||||
Assert.Contains("SUB_ORDER_ID_0", unparsedJsonByNewtonsoftJson);
|
||||
Assert.Contains("SUB_ORDER_ID_0", unparsedJsonBySystemTextJson);
|
||||
Assert.DoesNotContain("#n", unparsedJsonByNewtonsoftJson);
|
||||
Assert.DoesNotContain("#n", unparsedJsonBySystemTextJson);
|
||||
Assert.DoesNotContain("$n", unparsedJsonByNewtonsoftJson);
|
||||
Assert.DoesNotContain("$n", unparsedJsonBySystemTextJson);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Net.Http;
|
||||
using System.Net.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class TestCase_RequestSignTests
|
||||
public class TestCase_RequestSigningTests
|
||||
{
|
||||
internal class InnerFakeRequest : WechatTenpaySignableRequest
|
||||
{
|
||||
@@ -25,7 +25,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:生成请求签名")]
|
||||
public void TestRequestSign()
|
||||
public void TestRequestSigning()
|
||||
{
|
||||
const string MCHID = "10000100";
|
||||
const string MCHKEY = "192006250b4c09247ec02edce69f6a2d";
|
||||
@@ -37,8 +37,8 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
Body = "test",
|
||||
NonceString = "ibuaiVcKdpRxkhJA"
|
||||
};
|
||||
var client = new WechatTenpayClient(MCHID, MCHKEY);
|
||||
client.CreateRequest(request, HttpMethod.Post);
|
||||
var client = new WechatTenpayClient(new WechatTenpayClientOptions() { MerchantId = MCHID, MerchantSecret = MCHKEY });
|
||||
client.CreateFlurlRequest(request, HttpMethod.Post);
|
||||
|
||||
string actualSign = "9A0A8659F005D6984697E2CA0A9CF3B7";
|
||||
string expectedSign = request.Signature!;
|
||||
@@ -3,13 +3,13 @@ using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
{
|
||||
public class TestCase_ToolsXmlUtilityTests
|
||||
public class TestCase_ToolsXmlHelperTests
|
||||
{
|
||||
[Fact(DisplayName = "测试用例:XML2JSON")]
|
||||
public void TestXmlConvertToJson()
|
||||
{
|
||||
string xml = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
|
||||
string json = Utilities.XmlUtility.ConvertToJson(xml); ;
|
||||
string json = Utilities.XmlHelper.ConvertToJson(xml); ;
|
||||
|
||||
JObject jObject = JObject.Parse(json)!;
|
||||
Assert.Equal("SUCCESS", jObject["return_code"]!.ToString());
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
@@ -17,15 +17,12 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
using var stream = File.OpenRead("appsettings.local.json");
|
||||
using var jdoc = JsonDocument.Parse(stream);
|
||||
|
||||
var config = jdoc.RootElement.GetProperty("TestConfig");
|
||||
var config = jdoc.RootElement.GetProperty("TestConfigs");
|
||||
WechatAppId = config.GetProperty("AppId").GetString()!;
|
||||
WechatMerchantId = config.GetProperty("MerchantId").GetString()!;
|
||||
WechatMerchantSecret = config.GetProperty("MerchantSecret").GetString()!;
|
||||
WechatMerchantCertificateBytes = config.GetProperty("MerchantCertificateBase64String").GetBytesFromBase64();
|
||||
WechatOpenId = config.GetProperty("OpenId").GetString()!;
|
||||
|
||||
WorkDirectoryForSdk = jdoc.RootElement.GetProperty("WorkDirectoryForSdk").GetString()!;
|
||||
WorkDirectoryForTest = jdoc.RootElement.GetProperty("WorkDirectoryForTest").GetString()!;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -38,8 +35,5 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests
|
||||
public static readonly string WechatMerchantSecret;
|
||||
public static readonly byte[] WechatMerchantCertificateBytes;
|
||||
public static readonly string WechatOpenId;
|
||||
|
||||
public static readonly string WorkDirectoryForSdk;
|
||||
public static readonly string WorkDirectoryForTest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
{
|
||||
"TestConfig": {
|
||||
{
|
||||
"TestConfigs": {
|
||||
"MerchantId": "请在此填写用于测试的微信商户号",
|
||||
"MerchantSecret": "请在此填写用于测试的微信商户 API 密钥",
|
||||
"MerchantCertificateBase64String": "请在此填写用于测试的微信商户证书内容的 Base64 字节数组",
|
||||
"AppId": "请在此填写用于测试的微信 AppId",
|
||||
"OpenId": "请在此填写用于测试的微信用户唯一标识"
|
||||
},
|
||||
"WorkDirectoryForSdk": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.TenpayV2\\",
|
||||
"WorkDirectoryForTest": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.TenpayV2.UnitTests\\"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user