public void FileIssueAsync_NoRuleIsSpecified_SetsCorrectTelemetry() { IssueInformation expectedIssueInformation = new IssueInformation(); IssueInformation actualIssueInformation = null; List <PropertyBag> capturedTelemetry = CaptureTelemetryEvents(TelemetryAction.Issue_File_Attempt.ToString()); Mock <IIssueResult> issueResultMock = new Mock <IIssueResult>(MockBehavior.Strict); issueResultMock.Setup(x => x.IssueLink).Returns <Uri>(null); IssueReporter.TestControlledIsEnabled = true; IssueReporter.TestControlledDisplayName = DISPLAY_NAME; IssueReporter.TestControlledFileIssueAsync = (issueInformation) => { actualIssueInformation = issueInformation; return(issueResultMock.Object); }; IIssueResult result = FileIssueAction.FileIssueAsync(expectedIssueInformation); Assert.AreSame(issueResultMock.Object, result); Assert.AreSame(expectedIssueInformation, actualIssueInformation); Assert.AreEqual(1, capturedTelemetry.Count); Assert.AreEqual(DISPLAY_NAME, capturedTelemetry[0][TelemetryProperty.IssueReporter.ToString()]); _telemetrySinkMock.VerifyAll(); issueResultMock.VerifyAll(); }
public void FileIssueAsync_RuleIsSpecified_SetsCorrectTelemetry() { const string expectedRule = "An awesome rule"; IssueInformation expectedIssueInformation = new IssueInformation(ruleForTelemetry: expectedRule); IssueInformation actualIssueInformation = null; List <PropertyBag> capturedTelemetry = CaptureTelemetryEvents(TelemetryAction.Issue_Save.ToString()); Mock <IIssueResult> issueResultMock = new Mock <IIssueResult>(MockBehavior.Strict); issueResultMock.Setup(x => x.IssueLink).Returns(new Uri("https://AccessibilityInsights.io")); IssueReporter.TestControlledIsEnabled = true; IssueReporter.TestControlledDisplayName = DISPLAY_NAME; IssueReporter.TestControlledFileIssueAsync = (issueInformation) => { actualIssueInformation = issueInformation; return(issueResultMock.Object); }; IIssueResult result = FileIssueAction.FileIssueAsync(expectedIssueInformation); Assert.AreEqual(3, capturedTelemetry[0].Count); Assert.AreEqual(expectedRule, capturedTelemetry[0][TelemetryProperty.RuleId.ToString()]); Assert.AreEqual("", capturedTelemetry[0][TelemetryProperty.UIFramework.ToString()]); Assert.AreEqual(DISPLAY_NAME, capturedTelemetry[0][TelemetryProperty.IssueReporter.ToString()]); _telemetrySinkMock.VerifyAll(); issueResultMock.VerifyAll(); }
public void TestBugFilingTelemetrySpecificRule() { using (ShimsContext.Create()) { SetUpShims(); ShimIssueReporter.FileIssueAsyncIssueInformation = (_) => { var mockIssueResult = new Mock <IIssueResult>(); mockIssueResult.Setup(p => p.DisplayText).Returns("Issue Display text"); mockIssueResult.Setup(p => p.IssueLink).Returns(new Uri("https://www.google.com")); return(mockIssueResult.Object); }; // Save telemetry locally List <Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> > > telemetryLog = new List <Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> > >(); ShimLogger.PublishTelemetryEventTelemetryActionIReadOnlyDictionaryOfTelemetryPropertyString = (action, dict) => { telemetryLog.Add(new Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> >(action, dict)); }; var issueInfo = new IssueInformation(ruleForTelemetry: RuleId.BoundingRectangleContainedInParent.ToString()); var result = FileIssueAction.FileIssueAsync(issueInfo); Assert.AreEqual(RuleId.BoundingRectangleContainedInParent.ToString(), telemetryLog[0].Item2[TelemetryProperty.RuleId]); Assert.AreEqual("", telemetryLog[0].Item2[TelemetryProperty.UIFramework]); Assert.AreEqual(2, telemetryLog[0].Item2.Count); } }
public void FileBug(HierarchyNodeViewModel vm = null) { vm = vm ?? this.treeviewHierarchy.SelectedItem as HierarchyNodeViewModel; if (vm == null) { MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_Could_not_find_the_selected_item__the_bug_filing_is_canceled); return; } if (vm.IssueLink != null) { // Bug already filed, open it in a new window try { System.Diagnostics.Process.Start(vm.IssueLink.OriginalString); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue MessageDialog.Show(ex.InnerException?.Message); vm.IssueDisplayText = null; } #pragma warning restore CA1031 // Do not catch general exception types } else { // File a new bug var telemetryEvent = TelemetryEventFactory.ForIssueFilingRequest(FileBugRequestSource.Hierarchy); Logger.PublishTelemetryEvent(telemetryEvent); if (IssueReporter.IsConnected) { IssueInformation issueInformation = this.SelectedElement.GetIssueInformation(IssueType.NoFailure); FileIssueAction.AttachIssueData(issueInformation, this.ElementContext.Id, this.SelectedElement.BoundingRectangle, this.SelectedElement.UniqueId); IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation); if (issueResult != null) { vm.IssueDisplayText = issueResult.DisplayText; vm.IssueLink = issueResult.IssueLink; } File.Delete(issueInformation.TestFileName); } else { bool?accepted = MessageDialog.Show(Properties.Resources.HierarchyControl_FileIssue_Configure); if (accepted.HasValue && accepted.Value) { this.HierarchyActions.SwitchToServerLogin(); } } } }
public void FileBug(HierarchyNodeViewModel vm = null) { vm = vm ?? this.treeviewHierarchy.SelectedItem as HierarchyNodeViewModel; if (vm == null) { MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_Could_not_find_the_selected_item__the_bug_filing_is_canceled); return; } if (vm.IssueLink != null) { // Bug already filed, open it in a new window try { System.Diagnostics.Process.Start(vm.IssueLink.OriginalString); } catch (Exception ex) { // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue MessageDialog.Show(ex.InnerException?.Message); vm.IssueDisplayText = null; } } else { // File a new bug Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string> { { TelemetryProperty.By, FileBugRequestSource.Hierarchy.ToString() }, { TelemetryProperty.IsAlreadyLoggedIn, IssueReporter.IsConnected.ToString(CultureInfo.InvariantCulture) }, }); if (IssueReporter.IsConnected) { IssueInformation issueInformation = this.SelectedElement.GetIssueInformation(IssueType.NoFailure); FileIssueAction.AttachIssueData(issueInformation, this.ElementContext.Id, this.SelectedElement.BoundingRectangle, this.SelectedElement.UniqueId); IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation); if (issueResult != null) { vm.IssueDisplayText = issueResult.DisplayText; vm.IssueLink = issueResult.IssueLink; } File.Delete(issueInformation.TestFileName); } else { bool?accepted = MessageDialog.Show(Properties.Resources.HierarchyControl_FileIssue_Configure); if (accepted.HasValue && accepted.Value) { this.HierarchyActions.SwitchToServerLogin(); } } } }
public void FileNewBug_IsNotEnabled_ReturnsNull() { using (ShimsContext.Create()) { ShimIssueReporter.IsEnabledGet = () => false; var issueInfo = new IssueInformation(); var output = FileIssueAction.FileIssueAsync(issueInfo); Assert.IsNull(output); } }
/// <summary> /// Handles click on file bug button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFileBug_Click(object sender, RoutedEventArgs e) { var vm = ((Button)sender).Tag as RuleResultViewModel; if (vm.IssueLink != null) { // Bug already filed, open it in a new window try { Process.Start(vm.IssueLink.OriginalString); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue MessageDialog.Show(ex.InnerException?.Message); vm.IssueDisplayText = null; } #pragma warning restore CA1031 // Do not catch general exception types } else { // File a new bug var telemetryEvent = TelemetryEventFactory.ForIssueFilingRequest(FileBugRequestSource.AutomatedChecks); Logger.PublishTelemetryEvent(telemetryEvent); if (IssueReporter.IsConnected) { IssueInformation issueInformation = vm.GetIssueInformation(); FileIssueAction.AttachIssueData(issueInformation, this.ElementContext.Id, vm.Element.BoundingRectangle, vm.Element.UniqueId); IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation); if (issueResult != null) { vm.IssueDisplayText = issueResult.DisplayText; vm.IssueLink = issueResult.IssueLink; } File.Delete(issueInformation.TestFileName); } else { bool?accepted = MessageDialog.Show(Properties.Resources.AutomatedChecksControl_btnFileBug_Click_File_Issue_Configure); if (accepted.HasValue && accepted.Value) { SwitchToServerLogin(); } } } }
/// <summary> /// Handles click on file bug button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFileBug_Click(object sender, RoutedEventArgs e) { var vm = ((Button)sender).Tag as RuleResultViewModel; if (vm.IssueLink != null) { // Bug already filed, open it in a new window try { Process.Start(vm.IssueLink.OriginalString); } catch (Exception ex) { // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue MessageDialog.Show(ex.InnerException?.Message); vm.IssueDisplayText = null; } } else { // File a new bug Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>() { { TelemetryProperty.By, FileBugRequestSource.AutomatedChecks.ToString() }, { TelemetryProperty.IsAlreadyLoggedIn, IssueReporter.IsConnected.ToString(CultureInfo.InvariantCulture) } }); if (IssueReporter.IsConnected) { IssueInformation issueInformation = vm.GetIssueInformation(); FileIssueAction.AttachIssueData(issueInformation, this.ElementContext.Id, vm.Element.BoundingRectangle, vm.Element.UniqueId); IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation); if (issueResult != null) { vm.IssueDisplayText = issueResult.DisplayText; vm.IssueLink = issueResult.IssueLink; } File.Delete(issueInformation.TestFileName); } else { bool?accepted = MessageDialog.Show(Properties.Resources.AutomatedChecksControl_btnFileBug_Click_File_Issue_Configure); if (accepted.HasValue && accepted.Value) { SwitchToServerLogin(); } } } }
public void FileNewBug_IsNotEnabled_ReturnsNull() { bool wasIssueFiled = false; IssueReporter.TestControlledIsEnabled = false; IssueReporter.TestControlledFileIssueAsync = (issueInformation) => { wasIssueFiled = true; return(null); }; var issueInfo = new IssueInformation(); var output = FileIssueAction.FileIssueAsync(issueInfo); Assert.IsNull(output); Assert.IsFalse(wasIssueFiled); }
public void TestBugFilingTelemetryNoRule() { using (ShimsContext.Create()) { SetUpShims(); // Save telemetry locally List <Tuple <TelemetryAction, TelemetryProperty, string> > telemetryLog = new List <Tuple <TelemetryAction, TelemetryProperty, string> >(); ShimLogger.PublishTelemetryEventTelemetryActionTelemetryPropertyString = (action, property, value) => { telemetryLog.Add(new Tuple <TelemetryAction, TelemetryProperty, string>(action, property, value)); }; var issueInfo = new IssueInformation(); var result = FileIssueAction.FileIssueAsync(issueInfo); Assert.AreEqual(0, telemetryLog.Count); } }
public void TestBugFilingTelemetryNoRule() { using (ShimsContext.Create()) { SetUpShims(); // Save telemetry locally List <Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> > > telemetryLog = new List <Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> > >(); ShimLogger.PublishTelemetryEventTelemetryActionIReadOnlyDictionaryOfTelemetryPropertyString = (action, dict) => { telemetryLog.Add(new Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> >(action, dict)); }; var issueInfo = new IssueInformation(); var result = FileIssueAction.FileIssueAsync(issueInfo); Assert.AreEqual(1, telemetryLog.Count); Assert.AreEqual(DISPLAY_NAME, telemetryLog[0].Item2[TelemetryProperty.IssueReporter]); } }
public void TestBugFilingTelemetrySpecificRule() { using (ShimsContext.Create()) { SetUpShims(); // Save telemetry locally List <Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> > > telemetryLog = new List <Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> > >(); ShimLogger.PublishTelemetryEventTelemetryActionIReadOnlyDictionaryOfTelemetryPropertyString = (action, dict) => { telemetryLog.Add(new Tuple <TelemetryAction, IReadOnlyDictionary <TelemetryProperty, string> >(action, dict)); }; var issueInfo = new IssueInformation(ruleForTelemetry: RuleId.BoundingRectangleContainedInParent.ToString()); var result = FileIssueAction.FileIssueAsync(issueInfo); Assert.AreEqual(3, telemetryLog[0].Item2.Count); Assert.AreEqual(RuleId.BoundingRectangleContainedInParent.ToString(), telemetryLog[0].Item2[TelemetryProperty.RuleId]); Assert.AreEqual("", telemetryLog[0].Item2[TelemetryProperty.UIFramework]); Assert.AreEqual(DISPLAY_NAME, telemetryLog[0].Item2[TelemetryProperty.IssueReporter]); } }
public void FileIssueAsync_ExceptionIsThrown_IsReportedToTelemetry() { Exception actualException = null; IssueInformation expectedIssueInformation = new IssueInformation(); _telemetrySinkMock.Setup(x => x.IsEnabled).Returns(true); _telemetrySinkMock.Setup(x => x.ReportException(It.IsAny <Exception>())) .Callback <Exception>((e) => actualException = e); IssueReporter.TestControlledIsEnabled = true; IssueReporter.TestControlledFileIssueAsync = (issueInformation) => { throw new InvalidCastException(); }; Assert.IsNull(FileIssueAction.FileIssueAsync(expectedIssueInformation)); Assert.IsNotNull(actualException); Assert.IsInstanceOfType(actualException, typeof(InvalidCastException)); _telemetrySinkMock.VerifyAll(); }
/// <summary> /// Handles control-related issue filing /// </summary> internal static void FileIssueFromControl(FileIssueWrapperInput input) { IIssueFilingSource vm = input.VM; if (vm.IssueLink != null) { // Bug already filed, open it in a new window try { System.Diagnostics.Process.Start(vm.IssueLink.OriginalString); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue MessageDialog.Show(ex.InnerException?.Message); vm.IssueDisplayText = null; } #pragma warning restore CA1031 // Do not catch general exception types } else { // File a new bug var telemetryEvent = TelemetryEventFactory.ForIssueFilingRequest(input.RequestSource); Logger.PublishTelemetryEvent(telemetryEvent); if (IssueReporter.IsConnected) { IssueInformation issueInformation = null; try { issueInformation = input.IssueInformationProvider(); FileIssueAction.AttachIssueData(issueInformation, input.EcId, vm.Element.BoundingRectangle, vm.Element.UniqueId); IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation); if (issueResult != null) { vm.IssueDisplayText = issueResult.DisplayText; vm.IssueLink = issueResult.IssueLink; } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); } #pragma warning restore CA1031 // Do not catch general exception types finally { if (issueInformation != null && File.Exists(issueInformation.TestFileName)) { File.Delete(issueInformation.TestFileName); } } } else { bool?accepted = MessageDialog.Show(Properties.Resources.FileIssuesChooseLocation); if (accepted.HasValue && accepted.Value) { input.SwitchToServerLogin(); } } } }
/// <summary> /// Handles click on file bug button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFileBug_Click(object sender, RoutedEventArgs e) { var vm = ((Button)sender).Tag as ScanListViewItemViewModel; if (vm.IssueLink != null) { // Bug already filed, open it in a new window try { System.Diagnostics.Process.Start(vm.IssueLink.OriginalString); } catch (Exception ex) { ex.ReportException(); // Happens when bug is deleted, message describes that work item doesn't exist / possible permission issue MessageDialog.Show(ex.InnerException?.Message); vm.IssueDisplayText = null; } } else { // File a new bug var telemetryEvent = TelemetryEventFactory.ForIssueFilingRequest(FileBugRequestSource.HowtoFix); Logger.PublishTelemetryEvent(telemetryEvent); if (IssueReporter.IsConnected) { IssueInformation issueInformation = null; try { issueInformation = vm.GetIssueInformation(); FileIssueAction.AttachIssueData(issueInformation, this.EcId, vm.Element.BoundingRectangle, vm.Element.UniqueId); IIssueResult issueResult = FileIssueAction.FileIssueAsync(issueInformation); if (issueResult != null) { vm.IssueDisplayText = issueResult.DisplayText; vm.IssueLink = issueResult.IssueLink; } } catch (Exception ex) { ex.ReportException(); } finally { if (issueInformation != null && File.Exists(issueInformation.TestFileName)) { File.Delete(issueInformation.TestFileName); } } } else { bool?accepted = MessageDialog.Show(Properties.Resources.ScannerResultControl_btnFileBug_Click_File_Issue_Configure); if (accepted.HasValue && accepted.Value) { SwitchToServerLogin(); } } } }