using Quadarax.Application.QLiberace.Common.Settings; using Quadarax.Application.QLiberace.Common.Tests.Settings.Fakes; namespace Quadarax.Application.QLiberace.Common.Tests.Settings { [TestFixture(Category = "Dto")] public class ModuleSettingsTest { private ModuleSettingFake _setting; [SetUp] public void Setup() { _setting = new ModuleSettingFake(); } [Test(TestOf = typeof(ModuleSetting))] public void GetDataOk() { var data = _setting.GetData().ToArray(); Assert.That(data.Length, Is.EqualTo(7)); CollectionAssert.Contains(data,new Tuple("PropertyString1", "System.String", ModuleSettingFake.DefPropertyString1)); CollectionAssert.Contains(data,new Tuple("PropertyString2", "System.String", ModuleSettingFake.DefPropertyString2)); CollectionAssert.Contains(data,new Tuple("PropertyDateTime1", "System.DateTime", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime1String) ? (DateTime?)null : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime1String!))); CollectionAssert.Contains(data,new Tuple("PropertyDateTime2", "System.DateTime", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime2String) ? (DateTime?)null : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime2String!))); CollectionAssert.Contains(data,new Tuple("PropertyTimeSpan", "System.TimeSpan", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyTimeSpanString) ? (TimeSpan?)null : TimeSpan.Parse(ModuleSettingFake.DefPropertyTimeSpanString!))); CollectionAssert.Contains(data,new Tuple("PropertyInt", "System.Int32", ModuleSettingFake.DefPropertyInt)); CollectionAssert.Contains(data,new Tuple("PropertyBool", "System.Boolean", ModuleSettingFake.DefPropertyBool)); } [Test(TestOf = typeof(ModuleSetting))] public void SetDataOk() { var data = new[] { new Tuple("PropertyString1", "System.String", ModuleSettingFake.DefPropertyString1), new Tuple("PropertyString2", "System.String", ModuleSettingFake.DefPropertyString2), new Tuple("PropertyDateTime1", "System.DateTime", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime1String) ? (DateTime?)null : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime1String!)), new Tuple("PropertyDateTime2", "System.DateTime", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyDateTime2String) ? (DateTime?)null : DateTime.Parse(ModuleSettingFake.DefPropertyDateTime2String!)), new Tuple("PropertyTimeSpan", "System.TimeSpan", string.IsNullOrEmpty(ModuleSettingFake.DefPropertyTimeSpanString) ? (TimeSpan?)null : TimeSpan.Parse(ModuleSettingFake.DefPropertyTimeSpanString!)), new Tuple("PropertyInt", "System.Int32", ModuleSettingFake.DefPropertyInt), new Tuple("PropertyBool", "System.Boolean", ModuleSettingFake.DefPropertyBool) }; _setting.Clear(); _setting.SetData(data); var newSettings = new ModuleSettingFake(); Assert.That(_setting,Is.EqualTo(newSettings)); } [Test(TestOf = typeof(ModuleSetting))] public void GetSetIntegrityOk() { var now = DateTime.Now; var intv = 22; var stringv = "this is a test"; _setting.PropertyDateTime2 = now; _setting.PropertyDateTime1 = now; _setting.PropertyInt = intv; _setting.PropertyString2 = stringv; var data = _setting.GetData(); var settings = new ModuleSettingFake(); settings.SetData(data); Assert.That(settings.PropertyDateTime2,Is.EqualTo(_setting.PropertyDateTime2)); Assert.That(settings.PropertyDateTime1,Is.EqualTo(_setting.PropertyDateTime1)); Assert.That(settings.PropertyInt,Is.EqualTo(_setting.PropertyInt)); Assert.That(settings.PropertyString2,Is.EqualTo(_setting.PropertyString2)); } } }