ModuleSettingsTest.cs 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  63. }