ClientTest.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using NUnit.Framework;
  2. using Alipay.EasySDK.Factory;
  3. using Alipay.EasySDK.Payment.App.Models;
  4. using System.Collections.Generic;
  5. using Alipay.EasySDK.Kernel.Util;
  6. namespace UnitTest.Payment.App
  7. {
  8. public class ClientTest
  9. {
  10. [SetUp]
  11. public void SetUp()
  12. {
  13. Factory.SetOptions(TestAccount.Mini.CONFIG);
  14. }
  15. [Test]
  16. public void TestPay()
  17. {
  18. AlipayTradeAppPayResponse response = Factory.Payment.App().Pay("iPhone6 16G",
  19. "f4833085-0c46-4bb0-8e5f-622a02a4cffc", "0.10");
  20. Assert.IsTrue(ResponseChecker.Success(response));
  21. Assert.IsTrue(response.Body.Contains("app_id=2019022663440152&biz_content=%7b%22subject%22%3a%22iPhone6+16G%22%2c%22" +
  22. "out_trade_no%22%3a%22f4833085-0c46-4bb0-8e5f-622a02a4cffc%22%2c%22total_amount%22%3a%220.10%22%7d&charset=UTF-8&" +
  23. "format=json&method=alipay.trade.app.pay&notify_url=https%3a%2f%2fwww.test.com%2fcallback&sign="));
  24. }
  25. [Test]
  26. public void TestPayWithOptional()
  27. {
  28. AlipayTradeAppPayResponse response = Factory.Payment.App()
  29. .Agent("ca34ea491e7146cc87d25fca24c4cD11")
  30. .Optional("extend_params", GetHuabeiConfig())
  31. .Pay("iPhone6 16G", "f4833085-0c46-4bb0-8e5f-622a02a4cffc", "0.10");
  32. Assert.IsTrue(ResponseChecker.Success(response));
  33. Assert.IsTrue(response.Body.Contains("app_auth_token=ca34ea491e7146cc87d25fca24c4cD11&app_id=2019022663440152&biz_content=%7b%22subject%22%3a%22iPhone6+16G%22%2c"
  34. + "%22out_trade_no%22%3a%22f4833085-0c46-4bb0-8e5f-622a02a4cffc%22%2c%22total_amount%22%3a%220"
  35. + ".10%22%2c%22extend_params%22%3a%7b%22hb_fq_num%22%3a%223%22%2c%22hb_fq_seller_percent%22%3a%22100%22%7d%7d&charset=UTF"
  36. + "-8&format=json&method=alipay.trade.app.pay&notify_url=https%3a%2f%2fwww.test.com%2fcallback&sign="));
  37. }
  38. private Dictionary<string, string> GetHuabeiConfig()
  39. {
  40. Dictionary<string, string> extendParams = new Dictionary<string, string>
  41. {
  42. { "hb_fq_num", "3" },
  43. { "hb_fq_seller_percent", "100" }
  44. };
  45. return extendParams;
  46. }
  47. }
  48. }