ClientTest.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using NUnit.Framework;
  2. using Alipay.EasySDK.Factory;
  3. using Alipay.EasySDK.Payment.Wap.Models;
  4. using Alipay.EasySDK.Kernel.Util;
  5. using System.Collections.Generic;
  6. namespace UnitTest.Payment.Wap
  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. AlipayTradeWapPayResponse response = Factory.Payment.Wap().Pay("iPhone6 16G",
  19. "b7f4bc7d-ea4b-4efd-9072-d8ea913c8946", "0.10",
  20. "https://www.taobao.com", "https://www.taobao.com");
  21. Assert.IsTrue(ResponseChecker.Success(response));
  22. Assert.IsTrue(response.Body.Contains("<form name=\"punchout_form\" method=\"post\" action=\"https://openapi.alipay.com/gateway.do?"));
  23. Assert.IsTrue(response.Body.Contains("notify_url"));
  24. Assert.IsTrue(response.Body.Contains("return_url"));
  25. Assert.IsTrue(response.Body.Contains("<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;subject&quot;:&quot;iPhone6 16G&quot;,&quot;"
  26. + "out_trade_no&quot;:&quot;b7f4bc7d-ea4b-4efd-9072-d8ea913c8946&quot;,&quot;"
  27. + "total_amount&quot;:&quot;0.10&quot;,&quot;quit_url&quot;:&quot;https://www.taobao.com&quot;,&quot;"
  28. + "product_code&quot;:&quot;QUICK_WAP_WAY&quot;}\">"));
  29. Assert.IsTrue(response.Body.Contains("<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >"));
  30. Assert.IsTrue(response.Body.Contains("<script>document.forms[0].submit();</script>"));
  31. }
  32. [Test]
  33. public void TestPayWithOptional()
  34. {
  35. Dictionary<string, object> optionalArgs = new Dictionary<string, object>
  36. {
  37. { "timeout_express", "10m" },
  38. { "body", "iPhone6 16G"}
  39. };
  40. AlipayTradeWapPayResponse response = Factory.Payment.Wap()
  41. .Agent("ca34ea491e7146cc87d25fca24c4cD11").BatchOptional(optionalArgs)
  42. .Pay("iPhone6 16G", "b7f4bc7d-ea4b-4efd-9072-d8ea913c8946", "0.10",
  43. "https://www.taobao.com", "https://www.taobao.com");
  44. Assert.IsTrue(ResponseChecker.Success(response));
  45. Assert.IsTrue(response.Body.Contains("<form name=\"punchout_form\" method=\"post\" "
  46. + "action=\"https://openapi.alipay.com/gateway.do?"));
  47. Assert.IsTrue(response.Body.Contains("notify_url"));
  48. Assert.IsTrue(response.Body.Contains("return_url"));
  49. Assert.IsTrue(response.Body.Contains("app_auth_token"));
  50. Assert.IsTrue(response.Body.Contains("timeout_express"));
  51. Assert.IsTrue(response.Body.Contains("body"));
  52. Assert.IsTrue(response.Body.Contains("<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;subject&quot;:&quot;iPhone6 16G&quot;,&quot;out_trade_no&quot;:&quot;"
  53. + "b7f4bc7d-ea4b-4efd-9072-d8ea913c8946&quot;,&quot;total_amount&quot;:&quot;0.10&quot;,&quot;quit_url&quot;:&quot;"
  54. + "https://www.taobao.com&quot;,&quot;product_code&quot;:&quot;QUICK_WAP_WAY&quot;,&quot;timeout_express&quot;:&quot;"
  55. + "10m&quot;,&quot;body&quot;:&quot;iPhone6 16G&quot;}\">"));
  56. Assert.IsTrue(response.Body.Contains("<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >"));
  57. Assert.IsTrue(response.Body.Contains("<script>document.forms[0].submit();</script>"));
  58. }
  59. }
  60. }