|
|
using System;
|
|
|
using System.Text;
|
|
|
using BWP.ABCClient.B2B;
|
|
|
using BWP.ABCClient.B2C;
|
|
|
using BWP.ABCClient.Businesses;
|
|
|
using BWP.ABCClient.Businesses.Type;
|
|
|
using BWP.ABCClient.Common;
|
|
|
using BWP.ABCClient.Market;
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
namespace BWP.ABCClient
|
|
|
{
|
|
|
[TestFixture]
|
|
|
public class BusinessTest
|
|
|
{
|
|
|
[Test]
|
|
|
public void B2CRequest()
|
|
|
{
|
|
|
EnsureCertsExists();
|
|
|
using (new MockWebServer("http://localhost:5000/B2C/", Encoding.UTF8, Encoding.GetEncoding("GB2312"), false)) {
|
|
|
var business = new BusinessBase<PaymentRequest, PaymentURLResponse>(BusinessTypes.B2C);
|
|
|
business.MerchantID = "103452083980419";
|
|
|
business.RequestUrl = "http://localhost:5000/B2C/";
|
|
|
business.RequestObj = PaymentRequest.New();
|
|
|
business.Request();
|
|
|
var responseObj = business.ResponseObj;
|
|
|
Assert.AreEqual("https://easyabc.95599.cn/b2c/NotCheckStatus/PaymentModeAct.ebf?TOKEN=12977496798933397376", responseObj.Message.TrxResponse.PaymentURL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
public void B2BRequest()
|
|
|
{
|
|
|
EnsureCertsExists();
|
|
|
using (new MockWebServer("http://localhost:5000/B2B/", Encoding.UTF8, Encoding.UTF8, false)) {
|
|
|
var business = new BusinessBase<FundTransferRequest, PaymentURLResponse>(BusinessTypes.B2B);
|
|
|
business.MerchantID = "337100000000066";
|
|
|
business.RequestUrl = "http://localhost:5000/B2B/";
|
|
|
business.RequestObj = FundTransferRequest.New();
|
|
|
business.Request();
|
|
|
var responseObj = business.ResponseObj;
|
|
|
Assert.AreEqual("https://easyabc.95599.cn/b2b/NotCheckStatus/PaymentModeAct.ebf?TOKEN=12975716546177309876", responseObj.Message.TrxResponse.PaymentURL);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
public void MarketRequest()
|
|
|
{
|
|
|
EnsureCertsExists();
|
|
|
Encoding gb2312Encoding = Encoding.GetEncoding("GB2312");
|
|
|
using (new MockWebServer("http://localhost:5000/Market/", gb2312Encoding, gb2312Encoding, true)) {
|
|
|
var business = new BusinessBase<PayRequest, MarketResponse>(BusinessTypes.Market);
|
|
|
business.MerchantID = "337100000000066";
|
|
|
business.RequestUrl = "http://localhost:5000/Market/";
|
|
|
business.RequestObj = PayRequest.New();
|
|
|
business.Request();
|
|
|
var responseObj = business.ResponseObj;
|
|
|
Assert.AreEqual("337199901033E01", responseObj.Message.Control.MerchantID);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
public void MarketOrderApplyRequest()
|
|
|
{
|
|
|
EnsureCertsExists();
|
|
|
Encoding gb2312Encoding = Encoding.GetEncoding("GB2312");
|
|
|
var orderApplyRequest=OrderApplyRequest.New();
|
|
|
orderApplyRequest.Message.Control.MerchantTrxNo = "Req110607008";
|
|
|
orderApplyRequest.Message.Control.MerchantID = "337199901033E01";
|
|
|
orderApplyRequest.Message.Parameters.BuyerCustomer = "84000471247";
|
|
|
orderApplyRequest.Message.Parameters.PayAmount = "0.01";
|
|
|
orderApplyRequest.Message.Parameters.OrderNo = "00000000011";
|
|
|
orderApplyRequest.Message.Parameters.SalerCustomer = "84003761702";
|
|
|
orderApplyRequest.Message.Parameters.SalerCustName = "张冠群";
|
|
|
orderApplyRequest.Message.Parameters.BuyerCustName = "宋元华";
|
|
|
|
|
|
using (new MockWebServer("http://localhost:5000/MarketOrderApply/", gb2312Encoding, gb2312Encoding, true)) {
|
|
|
var business = new BusinessBase<OrderApplyRequest, OrderApplyResponse>(BusinessTypes.Market);
|
|
|
business.MerchantID = "337199901033E01";
|
|
|
business.RequestUrl = "http://localhost:5000/MarketOrderApply/";
|
|
|
business.RequestObj = orderApplyRequest;
|
|
|
business.Request();
|
|
|
var responseObj = business.ResponseObj;
|
|
|
Console.WriteLine(MsgUtil.MsgToBareXml(orderApplyRequest));
|
|
|
Assert.AreEqual("337199901033E01", responseObj.Message.Control.MerchantID);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void EnsureCertsExists() {
|
|
|
var certManager = new CertManager();
|
|
|
certManager.SetupPfx("Certs/asC.pfx", "14814622");
|
|
|
certManager.SetupPfx("Certs/asB.pfx", "14814622");
|
|
|
certManager.SetupABCPubKey("Certs/TrustPay.cer");
|
|
|
certManager.SetupABCPubKey("Certs/TrustPayTest.cer");
|
|
|
}
|
|
|
}
|
|
|
}
|