TestReparse.cs 995 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Topten.JsonKit;
  6. using Xunit;
  7. namespace TestCases
  8. {
  9. class DaObject
  10. {
  11. [Json] public long id;
  12. [Json] public string Name;
  13. }
  14. public class TestReparse
  15. {
  16. void Compare(DaObject a, DaObject b)
  17. {
  18. Assert.Equal(a.id, b.id);
  19. Assert.Equal(a.Name, b.Name);
  20. }
  21. [Fact]
  22. public void Clone()
  23. {
  24. var a = new DaObject() { id = 101, Name = "#101" };
  25. var b = Json.Clone(a);
  26. Compare(a, b);
  27. }
  28. [Fact]
  29. public void Reparse()
  30. {
  31. var a = new DaObject() { id = 101, Name = "#101" };
  32. var dict = Json.Reparse<IDictionary<string, object>>(a);
  33. Assert.Equal(101UL, dict["id"]);
  34. Assert.Equal("#101", dict["name"]);
  35. var b = Json.Reparse<DaObject>(dict);
  36. Compare(a, b);
  37. }
  38. }
  39. }