Example #1
0
        public void SettingUpdateSave()
        {
            SetUpSettingsService();

            const string testId          = "testId";
            const string testStringValue = "testStringValue";
            const int    testIntValue    = 0;
            const bool   testBoolValue   = false;

            // create testSetting
            var testSetting = new TestSetting
            {
                Name        = testId,
                StringValue = testStringValue,
                IntValue    = testIntValue,
                BoolValue   = testBoolValue
            };

            // save/update
            _directoryFile.DeleteFileAndDirectory(_settingsService.Filename);

            _settingsService.SetISetting(testSetting);
            _settingsService.SaveConfig();

            _settingsService.LoadConfig();
            Assert.Equal(testSetting.StringValue, testStringValue);
            Assert.Equal(testSetting.IntValue, testIntValue);
            Assert.Equal(testSetting.BoolValue, testBoolValue);

            Assert.True(true);
        }
Example #2
0
        public void Cloning()
        {
            const string name = "name";

            var setting = new TestSetting {
                Name = name
            };
            var clonedSetting = setting.CloneAndSetPropertiesFrom();

            Assert.NotNull(clonedSetting);
            setting.Name = null;
            Assert.Equal(name, clonedSetting.Name);

            Assert.True(true);
        }
Example #3
0
        public void LoadSaveSettings()
        {
            SetUpSettingsService();

            // Id doubles for Setting Id and for ISetting's Name
            const string testId  = "testId";
            const string testId2 = "testId2";

            // create, add 1st setting
            var settingContainer = _settingsService.GetSettingContainer(testId);
            var testSetting      = new TestSetting {
                Name = testId
            };

            settingContainer.Setting     = testSetting;
            settingContainer.SettingType = typeof(TestSetting).FullName;

            // create, add 2nd setting
            settingContainer = _settingsService.GetSettingContainer(testId2);
            var testSetting2 = new TestSetting {
                Name = testId2
            };

            settingContainer.Setting     = testSetting2;
            settingContainer.SettingType = typeof(TestSetting).FullName;

            // test save/load
            _directoryFile.DeleteFileAndDirectory(_settingsService.Filename);
            _settingsService.SaveConfig();
            _settingsService.LoadConfig();

            settingContainer = _settingsService.GetSettingContainer(testId);
            Assert.Equal(((TestSetting)settingContainer.Setting).Name, testId);
            settingContainer = _settingsService.GetSettingContainer(testId2);
            Assert.Equal(((TestSetting)settingContainer.Setting).Name, testId2);

            // test removing setting
            _settingsService.RemoveSettingContainer(testId);
            settingContainer = _settingsService.GetSettingContainer(testId);
            Assert.Null(settingContainer.Setting);
            // test that other setting was unchanged
            settingContainer = _settingsService.GetSettingContainer(testId2);
            Assert.Equal(((TestSetting)settingContainer.Setting).Name, testId2);

            Assert.True(true);
        }