ModuleSettingsTest.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Quadarax.Application.QLiberace.Common.Settings;
  2. using Quadarax.Application.QLiberace.Common.Tests.Settings.Fakes;
  3. namespace Quadarax.Application.QLiberace.Common.Tests.Settings
  4. {
  5. [TestFixture(Category = "Dto")]
  6. public class ModuleSettingsTest
  7. {
  8. private ModuleSettingFake _setting;
  9. [SetUp]
  10. public void Setup()
  11. {
  12. _setting = new ModuleSettingFake();
  13. }
  14. [Test(TestOf = typeof(ModuleSetting))]
  15. public void GetDataOk()
  16. {
  17. var data = _setting.GetData().ToArray();
  18. Assert.That(data.Length, Is.EqualTo(7));
  19. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyString1", "System.String", ModuleSettingFake.DefPropertyString1));
  20. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyString2", "System.String", ModuleSettingFake.DefPropertyString2));
  21. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyDateTime1", "System.DateTime", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime1String)
  22. ? (DateTime?)null
  23. : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime1String!)));
  24. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyDateTime2", "System.DateTime", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime2String)
  25. ? (DateTime?)null
  26. : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime2String!)));
  27. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyTimeSpan", "System.TimeSpan", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyTimeSpanString)
  28. ? (TimeSpan?)null
  29. : TimeSpan.Parse(ModuleSettingFake.DefPropertyTimeSpanString!)));
  30. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyInt", "System.Int32", ModuleSettingFake.DefPropertyInt));
  31. CollectionAssert.Contains(data,new Tuple<string, string, object?>("PropertyBool", "System.Boolean", ModuleSettingFake.DefPropertyBool));
  32. }
  33. [Test(TestOf = typeof(ModuleSetting))]
  34. public void SetDataOk()
  35. {
  36. var data = new[]
  37. {
  38. new Tuple<string, string, object?>("PropertyString1", "System.String",
  39. ModuleSettingFake.DefPropertyString1),
  40. new Tuple<string, string, object?>("PropertyString2", "System.String",
  41. ModuleSettingFake.DefPropertyString2),
  42. new Tuple<string, string, object?>("PropertyDateTime1", "System.DateTime",
  43. string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime1String)
  44. ? (DateTime?)null
  45. : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime1String!)),
  46. new Tuple<string, string, object?>("PropertyDateTime2", "System.DateTime",
  47. string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime2String)
  48. ? (DateTime?)null
  49. : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime2String!)),
  50. new Tuple<string, string, object?>("PropertyTimeSpan", "System.TimeSpan",
  51. string.IsNullOrEmpty(ModuleSettingFake.DefPropertyTimeSpanString)
  52. ? (TimeSpan?)null
  53. : TimeSpan.Parse(ModuleSettingFake.DefPropertyTimeSpanString!)),
  54. new Tuple<string, string, object?>("PropertyInt", "System.Int32", ModuleSettingFake.DefPropertyInt),
  55. new Tuple<string, string, object?>("PropertyBool", "System.Boolean", ModuleSettingFake.DefPropertyBool)
  56. };
  57. _setting.Clear();
  58. _setting.SetData(data);
  59. var newSettings = new ModuleSettingFake();
  60. Assert.That(_setting,Is.EqualTo(newSettings));
  61. }
  62. [Test(TestOf = typeof(ModuleSetting))]
  63. public void GetSetIntegrityOk()
  64. {
  65. var now = DateTime.Now;
  66. var intv = 22;
  67. var stringv = "this is a test";
  68. _setting.PropertyDateTime2 = now;
  69. _setting.PropertyDateTime1 = now;
  70. _setting.PropertyInt = intv;
  71. _setting.PropertyString2 = stringv;
  72. var data = _setting.GetData();
  73. var settings = new ModuleSettingFake();
  74. settings.SetData(data);
  75. Assert.That(settings.PropertyDateTime2,Is.EqualTo(_setting.PropertyDateTime2));
  76. Assert.That(settings.PropertyDateTime1,Is.EqualTo(_setting.PropertyDateTime1));
  77. Assert.That(settings.PropertyInt,Is.EqualTo(_setting.PropertyInt));
  78. Assert.That(settings.PropertyString2,Is.EqualTo(_setting.PropertyString2));
  79. }
  80. }
  81. }