ClientTest.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using NUnit.Framework;
  2. using Alipay.EasySDK.Factory;
  3. using Alipay.EasySDK.Util.Generic.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using Alipay.EasySDK.Kernel.Util;
  7. namespace UnitTest.Util.Generic
  8. {
  9. public class ClientTest
  10. {
  11. [SetUp]
  12. public void SetUp()
  13. {
  14. Factory.SetOptions(TestAccount.Mini.CONFIG);
  15. }
  16. [Test]
  17. public void TestExecuteWithoutAppAuthToken()
  18. {
  19. string outTradeNo = Guid.NewGuid().ToString();
  20. AlipayOpenApiGenericResponse response = Factory.Util.Generic().Execute(
  21. "alipay.trade.create", null, GetBizParams(outTradeNo));
  22. Assert.IsTrue(ResponseChecker.Success(response));
  23. Assert.AreEqual(response.Code, "10000");
  24. Assert.AreEqual(response.Msg, "Success");
  25. Assert.IsNull(response.SubCode);
  26. Assert.IsNull(response.SubMsg);
  27. Assert.NotNull(response.HttpBody);
  28. }
  29. [Test]
  30. public void TestExecuteWithAppAuthToken()
  31. {
  32. string outTradeNo = Guid.NewGuid().ToString();
  33. AlipayOpenApiGenericResponse response = Factory.Util.Generic().Execute(
  34. "alipay.trade.create", GetTextParams(), GetBizParams(outTradeNo));
  35. Assert.IsFalse(ResponseChecker.Success(response));
  36. Assert.AreEqual(response.Code, "20001");
  37. Assert.AreEqual(response.Msg, "Insufficient Token Permissions");
  38. Assert.AreEqual(response.SubCode, "aop.invalid-app-auth-token");
  39. Assert.AreEqual(response.SubMsg, "无效的应用授权令牌");
  40. Assert.NotNull(response.HttpBody);
  41. }
  42. private Dictionary<string, string> GetTextParams()
  43. {
  44. return new Dictionary<string, string>
  45. {
  46. { "app_auth_token", "201712BB_D0804adb2e743078d1822d536956X34" }
  47. };
  48. }
  49. private Dictionary<string, object> GetBizParams(string outTradeNo)
  50. {
  51. return new Dictionary<string, object>
  52. {
  53. { "subject", "Iphone6 16G" },
  54. { "out_trade_no", outTradeNo },
  55. { "total_amount", "0.10" },
  56. { "buyer_id", "2088002656718920" },
  57. { "extend_params", GetHuabeiParams() }
  58. };
  59. }
  60. private Dictionary<string, string> GetHuabeiParams()
  61. {
  62. return new Dictionary<string, string>
  63. {
  64. { "hb_fq_num", "3"},
  65. { "hb_fq_seller_percent", "3"}
  66. };
  67. }
  68. }
  69. }