TestConcreteFromInterface.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using PetaTest;
  6. using PetaJson;
  7. using System.Collections;
  8. namespace TestCases
  9. {
  10. [TestFixture]
  11. class TestConcreteFromInterface
  12. {
  13. [Test]
  14. public void TestGenericList()
  15. {
  16. var l = new List<int>() { 10, 20, 30 };
  17. var json = Json.Format(l);
  18. var l2 = Json.Parse<IList<int>>(json);
  19. Assert.IsInstanceOf(typeof(List<int>), l2);
  20. Assert.AreEquivalent(l, l2);
  21. }
  22. [Test]
  23. public void TestGenericDictionary()
  24. {
  25. var l = new Dictionary<string,int>() {
  26. {"A", 10},
  27. {"B", 20},
  28. {"C", 30}
  29. };
  30. var json = Json.Format(l);
  31. var l2 = Json.Parse<IDictionary<string,int>>(json);
  32. Assert.IsInstanceOf(typeof(Dictionary<string,int>), l2);
  33. Assert.AreEquivalent(l, l2);
  34. }
  35. [Test]
  36. public void TestObjectList()
  37. {
  38. var l = new List<int>() { 10, 20, 30 };
  39. var json = Json.Format(l);
  40. var l2 = Json.Parse<IList>(json);
  41. Assert.IsInstanceOf(typeof(List<object>), l2);
  42. Assert.AreEqual(l.Count, l2.Count);
  43. }
  44. [Test]
  45. public void TestObjectDictionary()
  46. {
  47. var l = new Dictionary<string, int>() {
  48. {"A", 10},
  49. {"B", 20},
  50. {"C", 30}
  51. };
  52. var json = Json.Format(l);
  53. var l2 = Json.Parse<IDictionary>(json);
  54. Assert.IsInstanceOf(typeof(Dictionary<string,object>), l2);
  55. Assert.AreEqual(l.Count, l2.Count);
  56. }
  57. }
  58. }