private void btnLoad_Click(object sender, EventArgs e) { dlgOpen.Filter = "Settings files (*.xml)|*.xml"; if (dlgOpen.ShowDialog(this) != DialogResult.OK) { return; } var settings = new WorkSettings { SettingsFile = dlgOpen.FileName }; try { settings.ReadSettingsFile(); } catch (Exception ex) { ShowInformation("Cannot load settings (" + ex.Message + ")"); return; } tbPath.Text = settings.TargetPath; tbWorkingDir.Text = settings.TargetWorkingDir; tbArgs.Text = settings.TargetArgs; SetLoggingEnabled(chkLoggingDumpMethod, settings.LogLevel, Logging.DumpMethod); SetLoggingEnabled(chkLoggingDumpInstrumentation, settings.LogLevel, Logging.DumpInstrumentation); SetLoggingEnabled(chkLoggingInstrumentMessages, settings.LogLevel, Logging.MethodInstrumentation); SetLoggingEnabled(chkLoggingMethodInner, settings.LogLevel, Logging.MethodInner); SetLoggingEnabled(chkLoggingSkipByRule, settings.LogLevel, Logging.SkipByRules); SetLoggingEnabled(chkLoggingSkipByState, settings.LogLevel, Logging.SkipByState); ckbFlattenDomains.Checked = settings.DisableFlattenDomains; tbRules.Text = string.Empty; foreach (var s in settings.IncludeItems) { if (tbRules.Text.Length > 0) { tbRules.Text = tbRules.Text + "\r\n"; } tbRules.Text = tbRules.Text + "+" + s; } foreach (var s in settings.ExcludeItems) { if (tbRules.Text.Length > 0) { tbRules.Text = tbRules.Text + "\r\n"; } tbRules.Text = tbRules.Text + "-" + s; } }
public void LoadSettingsFile_FullPath() { // arrange var settings = new WorkSettings(); settings.SettingsFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FullPath.config"); // act settings.ReadSettingsFile(); // assert Assert.AreEqual(@"C:\TEMP\TARGET.EXE", settings.TargetPath); Assert.AreEqual(@"C:\TEMP", settings.TargetWorkingDir); Assert.AreEqual(@"C:\TEMP\OUTPUT.TXT", settings.FileNameForReport); }
public void LoadSettingsFile_RelPath() { // arrange var newPath = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\")); var settings = new WorkSettings(); settings.SettingsFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RelPath.config"); // act settings.ReadSettingsFile(); // assert Assert.AreEqual(Path.Combine(newPath, "TARGET.EXE"), Path.GetFullPath(settings.TargetPath)); Assert.AreEqual(newPath, Path.GetFullPath(settings.TargetWorkingDir)); Assert.AreEqual(Path.Combine(newPath, "OUTPUT.TXT"), Path.GetFullPath(settings.FileNameForReport)); }