public void UpdateIssueReporterSettings_InputIsNull_ThrowsArgumentNullException() { ConfigurationModel configs = GetConfigurationModel(null); IssueReporterManager repManager = new IssueReporterManager(configs, Enumerable.Empty <IIssueReporting>()); repManager.UpdateIssueReporterSettings(null); }
/// <summary> /// Adds the currently selected connection to the configuration so it is persisted /// </summary> /// <param name="configuration"></param> public bool UpdateConfigFromSelections(ConfigurationModel configuration) { // For first time / valid reconfigurations canSave will be enabled and hence config will be saved. Else only set the reporter. if (issueConfigurationControl != null && (issueConfigurationControl.CanSave || selectedIssueReporter.IsConfigured)) { configuration.SelectedIssueReporter = selectedIssueReporter.StableIdentifier; if (issueConfigurationControl.CanSave) { string serializedConfigs = configuration.IssueReporterSerializedConfigs; Dictionary <Guid, string> configs = new Dictionary <Guid, string>(); try { configs = JsonConvert.DeserializeObject <Dictionary <Guid, string> >(serializedConfigs); } catch (Exception e) { e.ReportException(); } string newConfigs = issueConfigurationControl.OnSave(); configs[selectedIssueReporter.StableIdentifier] = newConfigs; configuration.IssueReporterSerializedConfigs = JsonConvert.SerializeObject(configs); } IssueReporterManager.GetInstance().SetIssueReporter(selectedIssueReporter.StableIdentifier); issueConfigurationControl.OnDismiss(); return(true); } return(false); }
/// <summary> /// Inititates the view. Fetches a list of all the available issue reporters and creates a list. /// </summary> public void InitializeView() { IReadOnlyDictionary <Guid, IIssueReporting> options = IssueReporterManager.GetInstance().GetIssueFilingOptionsDict(); availableIssueReporters.Children.Clear(); Guid selectedGUID = IssueReporter.IssueReporting != null ? IssueReporter.IssueReporting.StableIdentifier : default(Guid); foreach (var reporter in options) { if (reporter.Key == null || reporter.Value == null) { continue; } RadioButton rb = CreateRadioButton(reporter.Value); if (selectedGUID.Equals(reporter.Key)) { rb.IsChecked = true; issueConfigurationControl = reporter.Value.RetrieveConfigurationControl(this.UpdateSaveButton); Grid.SetRow(issueConfigurationControl, 3); if (!issueFilingGrid.Children.Contains(issueConfigurationControl)) { issueFilingGrid.Children.Add(issueConfigurationControl); } } availableIssueReporters.Children.Add(rb); } this.issueFilingGrid.Visibility = Visibility.Visible; }
public void UpdateIssueReporterSettings_ReporterDoesNotSupportGetSettings_DoesNothing() { ConfigurationModel configs = GetConfigurationModel(null); IssueReporterManager repManager = new IssueReporterManager(configs, Enumerable.Empty <IIssueReporting>()); Mock <IIssueReporting> issueReportingMock = GetIssueReporterMock( setStableIdentifier: false, expectRestoreConfig: false, supportGetSerializedSettings: false); repManager.UpdateIssueReporterSettings(issueReportingMock.Object); issueReportingMock.VerifyAll(); }
public void UpdateIssueReporterSettings_SettingNotInOriginalConfig_AddsToConfig() { ConfigurationModel configs = GetConfigurationModel(null); IssueReporterManager repManager = new IssueReporterManager(configs, Enumerable.Empty <IIssueReporting>()); Mock <IIssueReporting> issueReportingMock = GetIssueReporterMock( expectRestoreConfig: false, supportGetSerializedSettings: true); repManager.UpdateIssueReporterSettings(issueReportingMock.Object); issueReportingMock.VerifyAll(); Assert.AreEqual(TestReporterConfigs, GetIssueReporterConfig(configs, TestGuid)); }
public void Constructor_WhitespaceConfigs_NoRestore() { ConfigurationModel configs = GetConfigurationModel(" "); var issueReporterMock = GetIssueReporterMock(); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); issueReporterMock.Verify(p => p.RestoreConfigurationAsync(TestReporterConfigs), Times.Never); Assert.IsTrue(repManager.GetIssueFilingOptionsDict().ContainsKey(TestGuid)); }
public void SetIssueReporter_Valid_ReporterSet() { ConfigurationModel configs = GetConfigurationModel(null); var issueReporterMock = GetIssueReporterMock(); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); repManager.SetIssueReporter(TestGuid); Assert.AreEqual(TestGuid, IssueReporter.IssueReporting.StableIdentifier); }
public void RestorePersistedConfigurations_EmptyConfigs_NoRestore() { ConfigurationModel configs = GetConfigurationModel(string.Empty); var issueReporterMock = GetIssueReporterMock(); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); repManager.RestorePersistedConfigurations(); issueReporterMock.Verify(p => p.RestoreConfigurationAsync(TestReporterConfigs), Times.Never); Assert.IsTrue(repManager.IssueFilingOptionsDict.ContainsKey(TestGuid)); }
public void RestorePersistedConfigurations_NullReporterConfig_NoRestore() { ConfigurationModel configs = GetConfigurationModel("{\"" + RandomTestGuid + "\":\"\"}"); var issueReporterMock = GetIssueReporterMock(); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); repManager.RestorePersistedConfigurations(); issueReporterMock.Verify(p => p.RestoreConfigurationAsync(null), Times.Never); Assert.IsTrue(repManager.GetIssueFilingOptionsDict().ContainsKey(TestGuid)); }
public void SetIssueReporter_ReporterNonExistent_ReporterUnset() { ConfigurationModel configs = GetConfigurationModel(null); IssueReporter.IssueReporting = null; var issueReporterMock = GetIssueReporterMock(); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); repManager.SetIssueReporter(Guid.Parse(RandomTestGuid)); Assert.IsNull(IssueReporter.IssueReporting); }
public void Constructor_EmptyReporterConfig_NoRestore() { ConfigurationModel configs = GetConfigurationModel("{\"" + TestGuidString + "\":\"\"}"); var issueReporterMock = GetIssueReporterMock(); issueReporterMock.Setup(p => p.RestoreConfigurationAsync(string.Empty)).Returns(new Task <IIssueResult>(() => { return(null); })); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); issueReporterMock.Verify(p => p.RestoreConfigurationAsync(string.Empty), Times.Never); Assert.IsTrue(repManager.GetIssueFilingOptionsDict().ContainsKey(TestGuid)); }
public void Constructor_Normal_DictionaryPopulated() { ConfigurationModel configs = new ConfigurationModel(); configs.IssueReporterSerializedConfigs = TestSerializedConfigs; Mock <IIssueReporting> issueReporterMock = GetIssueReporterMock(); List <IIssueReporting> issueReportingOptions = new List <IIssueReporting>() { issueReporterMock.Object }; IssueReporterManager repManager = new IssueReporterManager(configs, issueReportingOptions); issueReporterMock.Verify(p => p.RestoreConfigurationAsync(TestReporterConfigs), Times.Once); Assert.IsTrue(repManager.GetIssueFilingOptionsDict().ContainsKey(TestGuid)); }
public void UpdateIssueReporterSettings_SettingInOriginalConfig_UpdatesConfig() { const string newSettings = "la di dah"; ConfigurationModel configs = GetConfigurationModel(null); configs.IssueReporterSerializedConfigs = TestSerializedConfigs; IssueReporterManager repManager = new IssueReporterManager(configs, Enumerable.Empty <IIssueReporting>()); Mock <IIssueReporting> issueReportingMock = GetIssueReporterMock( expectRestoreConfig: false, supportGetSerializedSettings: true, newSettings: newSettings); Assert.IsFalse(configs.IssueReporterSerializedConfigs.Contains(newSettings)); Assert.AreEqual(TestReporterConfigs, GetIssueReporterConfig(configs, TestGuid)); repManager.UpdateIssueReporterSettings(issueReportingMock.Object); issueReportingMock.VerifyAll(); Assert.AreEqual(newSettings, GetIssueReporterConfig(configs, TestGuid)); }
private void IssueReporterOnChecked(object sender, RoutedEventArgs e) { if (issueConfigurationControl != null) { issueFilingGrid.Children.Remove(issueConfigurationControl); issueConfigurationControl = null; UpdateSaveButton(); } Guid clickedOptionTag = (Guid)((RadioButton)sender).Tag; if (clickedOptionTag != Guid.Empty) { IssueReporterManager.GetInstance().GetIssueFilingOptionsDict().TryGetValue(clickedOptionTag, out selectedIssueReporter); issueConfigurationControl = selectedIssueReporter?.RetrieveConfigurationControl(this.UpdateSaveButton); Grid.SetRow(issueConfigurationControl, 3); issueFilingGrid.Children.Add(issueConfigurationControl); } UpdateSaveButton(); }
/// <summary> /// Adds the currently selected connection to the configuration so it is persisted /// </summary> /// <param name="configuration"></param> public bool UpdateConfigFromSelections(ConfigurationModel configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } // For first time / valid reconfigurations canSave will be enabled and hence config will be saved. Else only set the reporter. if (issueConfigurationControl != null && (issueConfigurationControl.CanSave || selectedIssueReporter.IsConfigured)) { configuration.SelectedIssueReporter = selectedIssueReporter.StableIdentifier; if (issueConfigurationControl.CanSave) { string serializedConfigs = configuration.IssueReporterSerializedConfigs; Dictionary <Guid, string> configs = new Dictionary <Guid, string>(); try { Dictionary <Guid, string> parsedConfigs = JsonConvert.DeserializeObject <Dictionary <Guid, string> >(serializedConfigs); configs = parsedConfigs ?? configs; } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); } #pragma warning restore CA1031 // Do not catch general exception types string newConfigs = issueConfigurationControl.OnSave(); configs[selectedIssueReporter.StableIdentifier] = newConfigs; configuration.IssueReporterSerializedConfigs = JsonConvert.SerializeObject(configs); } IssueReporterManager.GetInstance().SetIssueReporter(selectedIssueReporter.StableIdentifier); IssueReporter.SetConfigurationPath(ConfigurationManager.GetDefaultInstance().SettingsProvider.ConfigurationFolderPath); issueConfigurationControl.OnDismiss(); return(true); } return(false); }