public void SavingAndLoadingMustBeSame()
        {
            var repo     = new InMemoryRepository();
            var manager  = new SettingsManagerPeriodic(repo);
            var settings = manager.Get <Settings>();

            var custom = new CustomSetting()
            {
                Text = "1",
                Ref  = new CustomSetting()
                {
                    Text = "2"
                }
            };

            settings.Decimal    = 0.01m;
            settings.Text       = "test";
            settings.BigInteger = UInt64.MaxValue;
            settings.Boolean    = true;
            settings.Character  = 'X';
            settings.Enum       = ConsoleColor.Green;
            settings.Float      = float.MaxValue;
            settings.Integer    = int.MinValue;
            settings.Time       = DateTime.MaxValue;
            settings.TimeSpan   = TimeSpan.MaxValue;
            settings.TimeSpan2  = new TimeSpan(0, 1, 2, 3);
            settings.Custom     = custom;

            manager.Save(settings);
            settings = manager.Get <Settings>(true);

            Assert.AreEqual(0.01m, settings.Decimal);
            Assert.AreEqual("test", settings.Text);
            Assert.AreEqual(UInt64.MaxValue, settings.BigInteger);
            Assert.AreEqual(true, settings.Boolean);
            Assert.AreEqual('X', settings.Character);
            Assert.AreEqual(ConsoleColor.Green, settings.Enum);
            Assert.AreEqual(float.MaxValue, settings.Float);
            Assert.AreEqual(int.MinValue, settings.Integer);
            Assert.AreEqual(0, (int)(DateTime.MaxValue - settings.Time).TotalSeconds); //compare only to seconds precision
            Assert.AreEqual(TimeSpan.MaxValue, settings.TimeSpan);
            Assert.AreEqual(new TimeSpan(0, 1, 2, 3), settings.TimeSpan2);
            Assert.AreEqual(custom.Text, settings.Custom.Text);
            Assert.AreEqual(custom.Ref.Text, settings.Custom.Ref.Text);
        }
        public void SavingMustWriteNewObjectToRepository()
        {
            var repo    = new InMemoryRepository();
            var manager = new SettingsManagerPeriodic(repo)
            {
                AutoPersistOnCreate = false
            };
            var settings = manager.Get <Settings>();

            var custom = new CustomSetting()
            {
                Text = "abc"
            };
            var value = repo.Content.Where(i => i.Name == "Custom").Select(i => i.Value).FirstOrDefault();

            Assert.IsNull(settings.Custom);
            Assert.IsNull(value);

            settings.Custom = custom;
            manager.Save(settings);
            value = repo.Content.First(i => i.Name == "Custom").Value;
            Assert.IsNotNull(value);
            Assert.IsTrue(value.Contains("abc"));
        }
        public void SavingMustWriteNewObjectToRepository()
        {
            var repo = new InMemoryRepository();
            var manager = new SettingsManagerPeriodic(repo){AutoPersistOnCreate = false};
            var settings = manager.Get<Settings>();

            var custom = new CustomSetting()
            {
                Text = "abc"
            };
            var value = repo.Content.Where(i => i.Name == "Custom").Select(i=>i.Value).FirstOrDefault();
            Assert.IsNull(settings.Custom);
            Assert.IsNull(value);

            settings.Custom = custom;
            manager.Save(settings);
            value = repo.Content.First(i => i.Name == "Custom").Value;
            Assert.IsNotNull(value);
            Assert.IsTrue(value.Contains("abc"));
        }
        public void SavingAndLoadingMustBeSame()
        {
            var repo = new InMemoryRepository();
            var manager = new SettingsManagerPeriodic(repo);
            var settings = manager.Get<Settings>();

            var custom = new CustomSetting()
            {
                Text = "1",
                Ref = new CustomSetting() { Text = "2" }
            };

            settings.Decimal = 0.01m;
            settings.Text = "test";
            settings.BigInteger = UInt64.MaxValue;
            settings.Boolean = true;
            settings.Character = 'X';
            settings.Enum = ConsoleColor.Green;
            settings.Float = float.MaxValue;
            settings.Integer = int.MinValue;
            settings.Time = DateTime.MaxValue;
            settings.TimeSpan = TimeSpan.MaxValue;
            settings.TimeSpan2 = new TimeSpan(0, 1, 2, 3);
            settings.Custom = custom;

            manager.Save(settings);
            settings = manager.Get<Settings>(true);

            Assert.AreEqual(0.01m, settings.Decimal);
            Assert.AreEqual("test", settings.Text);
            Assert.AreEqual(UInt64.MaxValue, settings.BigInteger);
            Assert.AreEqual(true, settings.Boolean);
            Assert.AreEqual('X', settings.Character);
            Assert.AreEqual(ConsoleColor.Green, settings.Enum);
            Assert.AreEqual(float.MaxValue, settings.Float);
            Assert.AreEqual(int.MinValue, settings.Integer);
            Assert.AreEqual(0, (int)(DateTime.MaxValue - settings.Time).TotalSeconds); //compare only to seconds precision
            Assert.AreEqual(TimeSpan.MaxValue, settings.TimeSpan);
            Assert.AreEqual(new TimeSpan(0, 1, 2, 3), settings.TimeSpan2);
            Assert.AreEqual(custom.Text, settings.Custom.Text);
            Assert.AreEqual(custom.Ref.Text, settings.Custom.Ref.Text);
        }