TestConcreteFromInterface.cs 1.6 KB

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