ClientTest.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using NUnit.Framework;
  2. using Alipay.EasySDK.Factory;
  3. using Alipay.EasySDK.Payment.Page.Models;
  4. using Alipay.EasySDK.Kernel.Util;
  5. namespace UnitTest.Payment.Page
  6. {
  7. public class ClientTest
  8. {
  9. [SetUp]
  10. public void SetUp()
  11. {
  12. Factory.SetOptions(TestAccount.Mini.CONFIG);
  13. }
  14. [Test]
  15. public void TestPay()
  16. {
  17. AlipayTradePagePayResponse response = Factory.Payment.Page().Pay("iPhone6 16G",
  18. "e5b5bd79-8310-447d-b63b-0fe3a393324d", "0.10", "https://www.taobao.com");
  19. Assert.IsTrue(ResponseChecker.Success(response));
  20. Assert.IsTrue(response.Body.Contains("<form name=\"punchout_form\" method=\"post\" action=\"https://openapi.alipay.com/gateway.do?"));
  21. Assert.IsTrue(response.Body.Contains("notify_url"));
  22. Assert.IsTrue(response.Body.Contains("return_url"));
  23. Assert.IsTrue(response.Body.Contains("<input type=\"hidden\" name=\"biz_content\" value=\"{&quot;subject&quot;:&quot;iPhone6 16G&quot;,&quot;"
  24. + "out_trade_no&quot;:&quot;e5b5bd79-8310-447d-b63b-0fe3a393324d&quot;,&quot;total_amount&quot;:&quot;0.10&quot;,&quot;"
  25. + "product_code&quot;:&quot;FAST_INSTANT_TRADE_PAY&quot;}\">"));
  26. Assert.IsTrue(response.Body.Contains("<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >"));
  27. Assert.IsTrue(response.Body.Contains("<script>document.forms[0].submit();</script>"));
  28. }
  29. [Test]
  30. public void TestPayWithOptionalNotify()
  31. {
  32. AlipayTradePagePayResponse response = Factory.Payment.Page().AsyncNotify("https://www.test2.com/newCallback")
  33. .Pay("iPhone6 16G", "e5b5bd79-8310-447d-b63b-0fe3a393324d", "0.10", "https://www.taobao.com");
  34. Assert.IsTrue(ResponseChecker.Success(response));
  35. Assert.IsTrue(response.Body.Contains("<form name=\"punchout_form\" method=\"post\" action=\"https://openapi.alipay.com/gateway.do?"));
  36. Assert.IsTrue(response.Body.Contains("notify_url=https%3a%2f%2fwww.test2.com%2fnewCallback"));
  37. Assert.IsTrue(response.Body.Contains("return_url"));
  38. 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;"
  39. + "e5b5bd79-8310-447d-b63b-0fe3a393324d&quot;,&quot;total_amount&quot;:&quot;0.10&quot;,&quot;product_code&quot;:&quot;"
  40. + "FAST_INSTANT_TRADE_PAY&quot;}\">"));
  41. Assert.IsTrue(response.Body.Contains("<input type=\"submit\" value=\"立即支付\" style=\"display:none\" >"));
  42. Assert.IsTrue(response.Body.Contains("<script>document.forms[0].submit();</script>"));
  43. }
  44. }
  45. }