private void Button_Click(object sender, RoutedEventArgs e) { Dispatcher.BeginInvoke(() => { NavigationService.GoBackWhenReady(); }); if (_pushEnabledCheckBox != null && _pushEnabledCheckBox.IsChecked.HasValue) { bool value = _pushEnabledCheckBox.IsChecked.Value; var appSettings = Application.Current as JeffWilcox.Controls.IExposeSettings; if (appSettings != null) { var pe = appSettings.PushEnabled; if (pe != null) { pe.PushEnabled = value; SettingsStorage ss = pe as SettingsStorage; if (ss != null) { ss.Save(); } } } } }
public void InvalidFileNameChars() { var settingsStorage = new SettingsStorage(this.path.Path); var fullPath = settingsStorage.Save( Path.Combine(this.path.Path, "Project"), "Con|fig>ura<tion", this.settings); Assert.IsTrue(fullPath.EndsWith("Con_fig_ura_tion.json")); }
public void InvalidJson() { var settingsStorage = new SettingsStorage(this.path.Path); var fullPath = settingsStorage.Save(null, null, this.settings); Assert.IsNotNull(settingsStorage.TryLoad(null, null)); File.AppendAllText(fullPath, "InvalidJson"); TestHelper.AssertThrows <VSPackageException>(() => { settingsStorage.TryLoad(null, null); Assert.Fail(); }); }
public void SaveLoadNoProject() { var settingsStorage = new SettingsStorage(this.path.Path); var fullPath = settingsStorage.Save(null, null, this.settings); var expectedPath = Path.Combine( this.path.Path, SettingsStorage.ApplicationDataSection, SettingsStorage.NoProjectConfigName + ".json"); Assert.AreEqual(expectedPath, fullPath); var loadedSettings = settingsStorage.TryLoad(null, null); AssertEqual(this.settings, loadedSettings); }
public void SaveLoad() { var settingsStorage = new SettingsStorage(null); const string projectName = "Project.csproj"; const string configurationName = "Configuration"; var projectPath = Path.Combine(this.path.Path, projectName); var fullPath = settingsStorage.Save(projectPath, configurationName, this.settings); var expectedPath = Path.Combine( this.path.Path, SettingsStorage.OpenCppCov, Path.GetFileNameWithoutExtension(projectName), configurationName + ".json"); Assert.AreEqual(expectedPath, fullPath); var loadedSettings = settingsStorage.TryLoad(projectPath, configurationName); AssertEqual(this.settings, loadedSettings); }
public void Save() { using (var testDirectory = new TestDirectory()) { var settingsFile = Path.Combine(testDirectory.FullPath, "TestSettings"); var storage = new SettingsStorage(settingsFile); storage.SettingsRows = new[] { new SettingsRow("1", "2", false, new[] { "jpg", "png" }), new SettingsRow("3", "4", true, null) }; // Чтобы потом проверить, что при записи NotFound не сохранилось. foreach (var row in storage.SettingsRows) { row.LeftDirectory.NotFound = true; row.RightDirectory.NotFound = true; } storage.Save(); Assert.True(File.Exists(settingsFile)); var settingsFileData = JsonConvert.DeserializeObject <SettingsRow[]>( File.ReadAllText(settingsFile, Encoding.UTF8)); Assert.Equal(storage.SettingsRows.Length, settingsFileData.Length); for (int i = 0; i < storage.SettingsRows.Length; i++) { var expectedRow = storage.SettingsRows[i]; var resultRow = settingsFileData[i]; Assert.Equal(expectedRow.LeftDirectory.DirectoryPath, resultRow.LeftDirectory.DirectoryPath); Assert.Equal(expectedRow.RightDirectory.DirectoryPath, resultRow.RightDirectory.DirectoryPath); Assert.Equal(expectedRow.IsUsed, resultRow.IsUsed); Assert.Equal(expectedRow.ExcludedExtensions, resultRow.ExcludedExtensions); // NotFound не хранится в файле, так как каждый раз при загрузке снова проверяется. Assert.False(resultRow.LeftDirectory.NotFound); Assert.False(resultRow.RightDirectory.NotFound); } } }