SerializeDeepTestObject.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Fire.UnitTest {
  7. public struct TestObj {
  8. public int id;
  9. public string Name;
  10. }
  11. public class SerializeDeepTestObject {
  12. public string TestString;
  13. public SerializeTestObject Obj1;
  14. public SerializeTestObject Obj2;
  15. public TestObj User;
  16. public int[] IntArray;
  17. public string[] StringArray;
  18. public void Fill() {
  19. this.TestString = "DeepTestString";
  20. this.Obj1 = new SerializeTestObject();
  21. this.Obj1.Fill();
  22. this.Obj2 = new SerializeTestObject();
  23. this.Obj2.Fill();
  24. this.User = new TestObj();
  25. this.User.id = 100;
  26. this.User.Name = "Misikuri";
  27. this.IntArray = new int[3];
  28. this.IntArray[0] = 10;
  29. this.IntArray[1] = 20;
  30. this.IntArray[2] = 30;
  31. this.StringArray = new string[3];
  32. this.StringArray[0] = "Hallo";
  33. this.StringArray[1] = "Welt";
  34. this.StringArray[2] = "!";
  35. }
  36. public bool Compare(SerializeDeepTestObject obj) {
  37. if (obj == null)
  38. return false;
  39. return (
  40. this.TestString == obj.TestString &&
  41. ((this.Obj1 == null && obj.Obj1 == null) || (this.Obj1 != null && this.Obj1.Compare(obj.Obj1))) &&
  42. ((this.Obj2 == null && obj.Obj2 == null) || (this.Obj2 != null && this.Obj2.Compare(obj.Obj2))) &&
  43. this.User.id == obj.User.id && this.User.Name == obj.User.Name &&
  44. (this.IntArray.Length == obj.IntArray.Length && this.IntArray[0] == obj.IntArray[0] && this.IntArray[1] == obj.IntArray[1] && this.IntArray[2] == obj.IntArray[2]) &&
  45. (this.StringArray.Length == obj.StringArray.Length && this.StringArray[0] == obj.StringArray[0] && this.StringArray[1] == obj.StringArray[1] && this.StringArray[2] == obj.StringArray[2]) &&
  46. true
  47. );
  48. }
  49. }
  50. }