forked from Varorbc/PaySharp
-
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
9 changed files
with
361 additions
and
11 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
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
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
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,183 @@ | ||
using ICanPay.Alipay; | ||
using ICanPay.Core; | ||
using ICanPay.Core.Utils; | ||
using System; | ||
using System.Net; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace ICanPay.UnitTest | ||
{ | ||
public class AlipayGatewayTest | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
private readonly AlipayGateway _alipayGateway; | ||
private readonly Merchant _merchant; | ||
private readonly Order _order; | ||
private string _outTradeNo => DateTime.Now.ToString("yyyyMMddhhmmss"); | ||
|
||
public AlipayGatewayTest(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
|
||
_merchant = new Merchant | ||
{ | ||
AppId = "2016081600256163", | ||
NotifyUrl = "http://localhost:61337/Notify", | ||
ReturnUrl = "http://localhost:61337/Return", | ||
AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsW6+mN2E3Oji2DPjSKuYgRzK6MlH9q6W0iM0Yk3R0qbpp5wSesSXqudr2K25gIBOTCchiIbXO7GXt/zEdnhnC32eOaTnonDsnuBWIp+q7LoVx/gvKIX5LTHistCvGli8VW4EDGsu2jAyQXyMPgPrIz+/NzWis/gZsa4TaqVY4SpWRuSgMXxleh2ERB6k0ijK0IYM+Cv5fz1ZPDCgk7EbII2jk2fDxtlMLoN5UYEJCcD8OUyivm3Hti3u1kPolckCCf0xk+80g/4EdmzFAffsVgPeXZrkm5EIuiTTOIeRHXlTg3HtkkCw2Wl0CpYSKBr9Vzv7x0gNvb1wnXPmBJNRgQIDAQAB", | ||
Privatekey = "MIIEpAIBAAKCAQEAyC43UbsE5XZ2Pmqg1YgzeCqAMk4HOH8fYHslseeSgKxyDjybjqM0yjGIJry1FRmVvLnY7v8jURgwr7d/pDCSRdoHa6zaxuSzg0OlieNmujae34YZ54PmFxULZW0BHSdzmx3OIYK2GarRECkds531ZzpbLdRXqsxQf5G26JZLIFxmNuh/VjBjJ6Hic1WOFT+FCYyi8om+LkPn3jELeA7LPLXzFqzzxx0vo4yiAePrsX5WucWxf+Y8rZoDhRIy/cPtQECXi9SiAWOJe/82JqjVjfpowf3QN7UJHsA82RBloAS4lvvDGJA7a+8DDlqpqPer8cS41Dv5r39iqtJUybDqoQIDAQABAoIBAHi39kBhiihe8hvd7bQX+QIEj17G02/sqZ1jZm4M+rqCRB31ytGP9qvghvzlXEanMTeo0/v8/O1Qqzusa1s2t19MhqEWkrDTBraoOtIWwsKVYeXmVwTY9A8Db+XwgHV2by8iIEbxLqP38S/Pu8uv/GgON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
_order = new Order() | ||
{ | ||
Amount = 0.01, | ||
Subject = "支付宝测试" | ||
}; | ||
|
||
_alipayGateway = new AlipayGateway(_merchant); | ||
} | ||
|
||
[Fact] | ||
public void TestWebPay() | ||
{ | ||
_order.OutTradeNo = _outTradeNo; | ||
_alipayGateway.Order = _order; | ||
_alipayGateway.InitFormPayment(); | ||
|
||
Assert.Throws<WebException>(() => | ||
{ | ||
HttpUtil.Post(_alipayGateway.GatewayUrl, _alipayGateway.GatewayData.ToUrl()); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void TestWapPay() | ||
{ | ||
_order.OutTradeNo = _outTradeNo; | ||
_alipayGateway.Order = _order; | ||
string url = _alipayGateway.BuildUrlPayment(); | ||
|
||
Assert.Throws<WebException>(() => | ||
{ | ||
HttpUtil.Get(url); | ||
}); | ||
} | ||
|
||
[Fact] | ||
public void TestAppPay() | ||
{ | ||
_order.OutTradeNo = _outTradeNo; | ||
_alipayGateway.Order = _order; | ||
string result = _alipayGateway.BuildAppPayment(); | ||
|
||
_output.WriteLine(result); | ||
} | ||
|
||
[Fact] | ||
public void TestBarcodePay() | ||
{ | ||
_order.OutTradeNo = _outTradeNo; | ||
_alipayGateway.Order = _order; | ||
_alipayGateway.PaymentSucceed += _alipayGateway_PaymentSucceed; | ||
_alipayGateway.PaymentFailed += _alipayGateway_PaymentFailed; | ||
_alipayGateway.BuildBarcodePayment(); | ||
} | ||
|
||
private void _alipayGateway_PaymentSucceed(object arg1, PaymentSucceedEventArgs arg2) | ||
{ | ||
_output.WriteLine("支付成功"); | ||
} | ||
|
||
private void _alipayGateway_PaymentFailed(object arg1, PaymentFailedEventArgs arg2) | ||
{ | ||
_output.WriteLine(arg2.Message); | ||
} | ||
|
||
[Fact] | ||
public void TestScanPay() | ||
{ | ||
_order.OutTradeNo = _outTradeNo; | ||
_alipayGateway.Order = _order; | ||
string result = _alipayGateway.BuildScanPayment(); | ||
|
||
Assert.Contains("http", result); | ||
_output.WriteLine(result); | ||
} | ||
|
||
[Fact] | ||
public void TestQuery() | ||
{ | ||
var notify = (Notify)_alipayGateway.BuildQuery(new Auxiliary | ||
{ | ||
OutTradeNo = _outTradeNo | ||
}); | ||
|
||
Assert.Contains("交易不存在", notify.SubMessage); | ||
_output.WriteLine(Util.SerializeObject(notify)); | ||
} | ||
|
||
[Fact] | ||
public void TestCancel() | ||
{ | ||
var notify = (Notify)_alipayGateway.BuildCancel(new Auxiliary | ||
{ | ||
OutTradeNo = _outTradeNo | ||
}); | ||
|
||
Assert.Contains("10000", notify.Code); | ||
_output.WriteLine(Util.SerializeObject(notify)); | ||
} | ||
|
||
[Fact] | ||
public void TestClose() | ||
{ | ||
var notify = (Notify)_alipayGateway.BuildClose(new Auxiliary | ||
{ | ||
OutTradeNo = _outTradeNo | ||
}); | ||
|
||
Assert.Contains("交易不存在", notify.SubMessage); | ||
_output.WriteLine(Util.SerializeObject(notify)); | ||
} | ||
|
||
[Fact] | ||
public void TestRefund() | ||
{ | ||
var notify = (Notify)_alipayGateway.BuildRefund(new Auxiliary | ||
{ | ||
OutTradeNo = _outTradeNo, | ||
RefundAmount = 0.01, | ||
OutRefundNo = _outTradeNo | ||
}); | ||
|
||
Assert.Contains("交易不存在", notify.SubMessage); | ||
_output.WriteLine(Util.SerializeObject(notify)); | ||
} | ||
|
||
[Fact] | ||
public void TestRefundQuery() | ||
{ | ||
var notify = (Notify)_alipayGateway.BuildRefundQuery(new Auxiliary | ||
{ | ||
OutTradeNo = _outTradeNo, | ||
OutRefundNo = "123" | ||
}); | ||
|
||
Assert.Contains("交易不存在", notify.SubMessage); | ||
_output.WriteLine(Util.SerializeObject(notify)); | ||
} | ||
|
||
[Fact] | ||
public void TestBillDownload() | ||
{ | ||
var fileStream = _alipayGateway.BuildBillDownload(new Auxiliary | ||
{ | ||
BillType = "trade", | ||
BillDate = "2017-10-31" | ||
}); | ||
|
||
Assert.True(fileStream.Length > 0); | ||
} | ||
} | ||
} |
Oops, something went wrong.