public void RealtimeFileConfigurationEditTest() { var appName = DateTimeOffset.Now.Ticks.ToString(); var company = "ArtZilla.Config"; FileConfigurator ctr1 = null; FileConfigurator ctr2 = null; try { ctr1 = new FileConfigurator(appName, company); ctr1.Reset <ITestConfiguration>(); var cfg = ctr1.Realtime <ITestConfiguration>(); AssertCfg.IsDefault(cfg); const string message = "Testing realtime"; cfg.String = message; ctr1.Flush(); ctr2 = new FileConfigurator(appName, company); var other = ctr2.Readonly <ITestConfiguration>(); Assert.AreEqual(message, cfg.String, "realtime config not changed"); Assert.AreEqual(message, other.String, "readonly config not actual"); } finally { ctr1?.Reset <ITestConfiguration>(); ctr2?.Reset <ITestConfiguration>(); } }
public virtual void UsingKeyTest() { const int key = 42; var s = Create(); var x = s.As <ITestConfiguration>().As <int>(); x.Reset(key); AssertCfg.IsDefault(x.Readonly(key)); var c = x.Realtime(key); c.String = MagicLine; s.Flush(); var s2 = Create(); var y = s2.As <int, ITestConfiguration>(); Assert.IsTrue(y.IsExist(key)); AssertCfg.IsNotDefault(y.Readonly(key)); Assert.AreEqual(c.String, y.Readonly(key).String); y.Reset(key); var s3 = Create(); var z = s3.As <int, ITestConfiguration>(); Assert.IsFalse(z.IsExist(key)); }
public virtual void MultipleInstancesLoadTest() { var saver = Create(); var x = saver.As <ITestConfiguration>(); Console.WriteLine("Clear settings."); x.Reset(); var cfg = x.Realtime(); // should be in the default state AssertCfg.IsDefault(cfg); Console.WriteLine("Changing settings"); cfg.Int32 = MagicNumber; cfg.String = MagicLine; Console.WriteLine("Waiting file write"); saver.Flush(); // should not be in the default state AssertCfg.IsNotDefault(x.Readonly()); Console.WriteLine("Read and compare"); // should be equal AssertCfg.AssertEqualProperties(x.Readonly(), Create().Readonly <ITestConfiguration>()); }
protected virtual void TypedExistTest(T ctr) { var cfr = ctr.As<ITestConfiguration>(); cfr.Reset(); // Assert.IsTrue(cfr.IsExist(), "Configuration should exist after reset"); AssertCfg.IsDefault(cfr.Readonly()); }
protected virtual void KeysExistTest(T ctr) { var cfr = ctr.As<int, ITestConfiguration>(); cfr.Reset(0); cfr.Reset(42); // Assert.IsTrue(cfr.IsExist(0), "Configuration should exist after reset"); // Assert.IsTrue(cfr.IsExist(1), "Configuration should exist after reset"); AssertCfg.IsDefault(cfr.Readonly(0)); AssertCfg.IsDefault(cfr.Readonly(42)); }
protected virtual void LoadTest(T ctr) { var cfg = ctr.Copy<ITestConfiguration>(); cfg.Int32 = MagicNumber; cfg.String = MagicLine; ctr.Save(cfg); // should not be in the default state AssertCfg.IsNotDefault(ctr.Readonly<ITestConfiguration>()); // should be equal AssertCfg.AssertEqualProperties(cfg, ctr.Readonly<ITestConfiguration>()); }
protected virtual void ComplexSaveTest(T ctr) { ctr.Reset<IComplexConfig>(); Assert.IsFalse(AssertCfg.AreEquals(ctr.Readonly<IComplexConfig>().ValueArray, ComplexConfig.MagicArray), "Change test magic number"); var cfg = new ComplexConfig { ValueArray = ComplexConfig.MagicArray, ValueList = new List<int>(ComplexConfig.MagicArray), ValueDictionary = new Dictionary<int, string>(ComplexConfig.MagicDictionary) }; ctr.Save<IComplexConfig>(cfg); Assert.IsTrue(AssertCfg.AreEquals(ctr.Readonly<IComplexConfig>().ValueArray, ComplexConfig.MagicArray)); }
protected virtual void ComplexLoadTest(T ctr) { var cfg = ctr.Copy<IComplexConfig>(); cfg.ValueArray = ComplexConfig.MagicArray; cfg.ValueList = new List<int>(ComplexConfig.MagicArray); cfg.ValueDictionary = new Dictionary<int, string>(ComplexConfig.MagicDictionary); ctr.Save(cfg); // should not be in the default state AssertCfg.IsNotDefault(ctr.Readonly<IComplexConfig>()); // should be equal AssertCfg.AssertEqualProperties(cfg, ctr.Readonly<IComplexConfig>()); }
public void TestCopyMethod() { var cfr = ConfigManager.GetDefaultConfigurator(); var src = cfr.Copy <ITestConfiguration>(); var dst = new TestConfiguration(); ChangeConfig(src); if (AssertCfg.AreEqualAllProperties(dst, src)) { Assert.Fail(); } dst.Copy(src); AssertCfg.AssertEqualProperties(src, dst); }
protected virtual void ResetTest(T ctr) { var x = ctr.As<ITestConfiguration>(); // changing configuration var cfg = x.Realtime(); cfg.Int32 = MagicNumber; cfg.String = MagicLine; // should not be in the default state AssertCfg.IsNotDefault(x.Readonly()); // reseting configuration x.Reset(); // checking that it in default state now AssertCfg.IsDefault(x.Readonly()); }
protected virtual void ComplexResetTest(T ctr) { // changing configuration var cfg = ctr.Copy<IComplexConfig>(); cfg.ValueArray = ComplexConfig.MagicArray; cfg.ValueList = new List<int>(ComplexConfig.MagicArray); cfg.ValueDictionary = new Dictionary<int, string>(ComplexConfig.MagicDictionary); ctr.Save(cfg); // should not be in the default state AssertCfg.IsNotDefault(ctr.Readonly<IComplexConfig>()); // reseting configuration ctr.Reset<ITestConfiguration>(); // checking that it in default state now AssertCfg.IsDefault(ctr.Readonly<IComplexConfig>()); }
public void RealtimeMemoryConfigurationEditTest() { var ctr = new MemoryConfigurator(); ctr.Reset <ITestConfiguration>(); var cfg = ctr.Realtime <ITestConfiguration>(); AssertCfg.IsDefault(cfg); const string message = "Testing realtime"; cfg.String = message; var other = ctr.Readonly <ITestConfiguration>(); AssertCfg.IsNotDefault(cfg); AssertCfg.IsNotDefault(other); Assert.AreEqual(cfg.String, message, "realtime config not changed"); Assert.AreEqual(other.String, message, "readonly config not actual"); }
public void TestDefaultValues() => AssertCfg.IsDefault(CreateTestConfiguration());