ConfigTest.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = new List<Config>
  20. {
  21. new Config
  22. {
  23. Name = "selector",
  24. Id = 2,
  25. Args = new List<string> { "12" },
  26. SubConfigs = new List<Config>
  27. {
  28. new Config
  29. {
  30. Name = "selector",
  31. Id = 4,
  32. Args = new List<string> { "14" },
  33. },
  34. new Config
  35. {
  36. Name = "selector",
  37. Id = 5,
  38. Args = new List<string> { "15", "17"},
  39. }
  40. }
  41. },
  42. new Config
  43. {
  44. Name = "selector",
  45. Id = 3,
  46. Args = new List<string> { "13" },
  47. SubConfigs = new List<Config>
  48. {
  49. new Config
  50. {
  51. Name = "selector",
  52. Id = 6,
  53. Args = new List<string> { "16" },
  54. }
  55. }
  56. }
  57. }
  58. };
  59. string json = MongoHelper.ToJson(config);
  60. Console.WriteLine(json);
  61. var newConfig = MongoHelper.FromJson<Config>(json);
  62. Assert.AreEqual(json, MongoHelper.ToJson(newConfig));
  63. }
  64. }
  65. }