IPurchasingAdapterTests.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections.Generic;
  2. using NUnit.Framework;
  3. namespace UnityEngine.Monetization.Editor.Tests
  4. {
  5. [TestFixture]
  6. public class IPurchasingAdapterTests
  7. {
  8. [Test]
  9. public void TestTransactionDetailsToJson()
  10. {
  11. var details = new TransactionDetails
  12. {
  13. productId = "testProductId",
  14. transactionId = "testTransactionId",
  15. price = 90m,
  16. currency = "USD",
  17. receipt = "testReceipt",
  18. extras = new Dictionary<string, object>
  19. {
  20. { "testKey", "testValue" },
  21. { "testNumber", 56 }
  22. }
  23. };
  24. var jsonDictionary = details.ToJsonDictionary();
  25. Assert.AreEqual(new Dictionary<string, object>
  26. {
  27. { "productId", "testProductId" },
  28. { "transactionId", "testTransactionId" },
  29. { "receipt", "testReceipt" },
  30. { "price", 90m },
  31. { "currency", "USD" },
  32. { "extras", new Dictionary<string, object>
  33. {
  34. { "testKey", "testValue" },
  35. { "testNumber", 56 }
  36. } }
  37. }, jsonDictionary);
  38. }
  39. [Test]
  40. public void TestTransactionDetailsValidJson()
  41. {
  42. var details = new TransactionDetails
  43. {
  44. productId = "testProductId",
  45. transactionId = "testTransactionId",
  46. price = 90m,
  47. currency = "USD",
  48. receipt = "testReceipt",
  49. extras = new Dictionary<string, object>
  50. {
  51. { "testKey", "testValue" },
  52. { "testNumber", 56 }
  53. }
  54. };
  55. var jsonDictionary = details.ToJsonDictionary();
  56. var json = MiniJSON.Json.Serialize(jsonDictionary);
  57. Assert.AreEqual("{\"productId\":\"testProductId\",\"transactionId\":\"testTransactionId\",\"receipt\":\"testReceipt\",\"price\":90,\"currency\":\"USD\",\"extras\":{\"testKey\":\"testValue\",\"testNumber\":56}}", json);
  58. }
  59. }
  60. }