public void AddSettingTest()
        {
            const string originalSetting = "Original Setting";
            const string newSetting      = "New Setting";
            const int    version         = 1;

            ISettingProvider provider = new SingleVersionSettingProvider();

            var setting = provider.GetLatestSetting();

            Assert.IsNull(setting);

            provider.AddSetting(originalSetting);

            setting = provider.GetLatestSetting();

            Assert.AreEqual(originalSetting, setting);

            setting = provider[version];

            Assert.AreEqual(originalSetting, setting);

            provider.AddSetting(newSetting);

            setting = provider.GetLatestSetting();

            Assert.AreEqual(newSetting, setting);

            setting = provider[version + 1];

            Assert.AreEqual(newSetting, setting);
        }
        public void UpdateSettingWithProperVersionTest()
        {
            const string newSetting = "New Setting";

            ISettingProvider provider = new SingleVersionSettingProvider(TestVersion, _testSetting);

            provider.UpdateSetting(TestVersion, newSetting);

            var updatedSetting = provider.GetLatestSetting();

            Assert.AreEqual(newSetting, updatedSetting);
        }
        public void RemoveSettingTest()
        {
            const string insertedSetting = "Test Setting";
            const int    version         = 1;

            ISettingProvider provider = new SingleVersionSettingProvider();

            Assert.IsFalse(provider.RemoveSetting(version));

            provider.AddSetting(insertedSetting);

            Assert.IsFalse(provider.RemoveSetting(version + 1));
            Assert.IsTrue(provider.RemoveSetting(version));

            Assert.IsNull(provider.GetLatestSetting());
        }
        public void UpdateSettingWithWrongVersionTest()
        {
            const string originalSetting = "Original Setting";
            const string newSetting      = "New Setting";
            const int    version         = 1;

            ISettingProvider provider = new SingleVersionSettingProvider();

            provider.UpdateSetting(version, newSetting);

            Assert.IsNull(provider.GetLatestSetting());

            provider.AddSetting(originalSetting);

            Assert.AreEqual(originalSetting, provider[version]);

            provider.UpdateSetting(version + 1, newSetting);

            Assert.AreEqual(originalSetting, provider[version]);
            Assert.AreEqual(originalSetting, provider.GetLatestSetting());
        }
        public void GetSettingThrowsExceptionWithBadVersionTest()
        {
            var exceptionMessage =
                $"Cannot retrieve a version that is not equal to the configured version ({TestVersion}).";

            ISettingProvider provider = new SingleVersionSettingProvider(TestVersion, _testSetting);

            ArgumentException thrownException = null;

            try
            {
                // ReSharper disable UnusedVariable
                var version = provider[TestVersion + 1];
                // ReSharper restore UnusedVariable
            }
            catch (ArgumentException ae)
            {
                thrownException = ae;
            }

            Assert.IsNotNull(thrownException);
            Assert.AreEqual(exceptionMessage, thrownException.Message);
        }
        public void GetSettingByVersionTest()
        {
            ISettingProvider provider = new SingleVersionSettingProvider(TestVersion, _testSetting);

            Assert.AreEqual(_testSetting, provider[TestVersion]);
        }