コード例 #1
0
        public void VerifySetValue()
        {
            const string key = "test";

            Assert.False(_settings.ContainsKey(key));
            _settings.SetValue(key, 42);
            Assert.True(_settings.ContainsKey(key));
            Assert.Equal(42, _settings.GetValue <int>(key));
        }
コード例 #2
0
        public void VerifyMigration()
        {
            // Set a value.
            _settings.SetValue("old", "value");

            // Move file back to old location to test migration.
            var oldLocation = typeof(DefaultApplicationSettings).Assembly.Location;
            var oldPath     = Path.Combine(Path.GetDirectoryName(oldLocation), "AppCenter.config");

            File.Move(DefaultApplicationSettings.FilePath, oldPath);

            // Migrate.
            _settings = new DefaultApplicationSettings();

            // Check.
            Assert.Equal("value", _settings.GetValue <string>("old"));
        }
コード例 #3
0
        public void VerifyMigrationSkippedWhenNewFileExists()
        {
            // Set a value.
            _settings.SetValue("key", "oldValue");

            // Move file back to old location to test migration.
            var oldLocation = typeof(DefaultApplicationSettings).Assembly.Location;
            var oldPath     = Path.Combine(Path.GetDirectoryName(oldLocation), "AppCenter.config");

            File.Copy(DefaultApplicationSettings.FilePath, oldPath);
            _settings.SetValue("key", "newValue");

            // Migrate.
            _settings = new DefaultApplicationSettings();

            // Check migration didn't happen.
            Assert.Equal("newValue", _settings.GetValue <string>("key"));
        }