ConfigTest.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using BehaviorTree;
  4. using Helper;
  5. using Microsoft.VisualStudio.TestTools.UnitTesting;
  6. namespace BehaviorTreeTest
  7. {
  8. [TestClass]
  9. public class ConfigTest
  10. {
  11. [TestMethod]
  12. public void TestJsonToConfig()
  13. {
  14. var config = new Config
  15. {
  16. Name = "selector",
  17. Id = 1,
  18. Args = new List<string> { "11" },
  19. SubConfigs =
  20. new List<Config>
  21. {
  22. new Config
  23. {
  24. Name = "selector",
  25. Id = 2,
  26. Args = new List<string> { "12" },
  27. SubConfigs =
  28. new List<Config>
  29. {
  30. new Config
  31. {
  32. Name = "selector",
  33. Id = 4,
  34. Args = new List<string> { "14" },
  35. },
  36. new Config
  37. {
  38. Name = "selector",
  39. Id = 5,
  40. Args = new List<string> { "15", "17" },
  41. }
  42. }
  43. },
  44. new Config
  45. {
  46. Name = "selector",
  47. Id = 3,
  48. Args = new List<string> { "13" },
  49. SubConfigs =
  50. new List<Config>
  51. {
  52. new Config
  53. {
  54. Name = "selector",
  55. Id = 6,
  56. Args = new List<string> { "16" },
  57. }
  58. }
  59. }
  60. }
  61. };
  62. string json = MongoHelper.ToJson(config);
  63. Console.WriteLine(json);
  64. var newConfig = MongoHelper.FromJson<Config>(json);
  65. Assert.AreEqual(json, MongoHelper.ToJson(newConfig));
  66. }
  67. }
  68. }