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 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();
                    }
                }
            }
        }
Ejemplo n.º 5
0
        /// <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();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public static IIssueResult FileIssueAsync(IssueInformation issueInformation)
        {
            if (TestControlledFileIssueAsync != null)
            {
                return(TestControlledFileIssueAsync(issueInformation));
            }

            if (IsEnabled && IsConnected)
            {
                // Coding to the agreement that FileIssueAsync will return a kicked off task.
                // This will block the main thread.
                // It does seem like we currently block the main thread when we show the win form for azure devops
                // so keeping it as is till we have a discussion. Check for blocking behavior at that link.
                // https://github.com/Microsoft/accessibility-insights-windows/blob/master/src/AccessibilityInsights.SharedUx/Controls/HierarchyControl.xaml.cs#L858
                IIssueResult result = IssueReporting.FileIssueAsync(issueInformation).Result;
                IssueReporterManager.GetInstance().UpdateIssueReporterSettings(IssueReporting);
                return(result);
            }
            return(null);
        }
        /// <summary>
        /// File an issue. Telemetry wrapper.
        /// </summary>
        /// <param name="issueInformation">Issue infromation to pass on to the reporter</param>
        /// <returns></returns>
        public static IIssueResult FileIssueAsync(IssueInformation issueInformation)
        {
            if (!IssueReporter.IsEnabled)
            {
                return(null);
            }

            try
            {
                IIssueResult issueResult    = IssueReporter.FileIssueAsync(issueInformation);
                var          telemetryEvent = TelemetryEventFactory.ForIssueFilingCompleted(issueResult, issueInformation);
                Logger.PublishTelemetryEvent(telemetryEvent);
                return(issueResult);
            }
            catch (Exception e)
            {
                e.ReportException();
                return(null);
            }
        }
        public static TelemetryEvent ForIssueFilingCompleted(IIssueResult issueResult, IssueInformation issueInformation)
        {
            if (issueResult?.IssueLink != null && issueInformation?.RuleForTelemetry != null)
            {
                return(new TelemetryEvent(TelemetryAction.Issue_Save, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.RuleId, issueInformation.RuleForTelemetry },
                    { TelemetryProperty.UIFramework, issueInformation.UIFramework ?? string.Empty },
                    { TelemetryProperty.IssueReporter, IssueReporter.DisplayName?.ToString(CultureInfo.InvariantCulture) },
                }));
            }

            // if the bug is coming from the hierarchy tree, it will not have ruleID or UIFramework
            var action = issueResult?.IssueLink == null ?
                         TelemetryAction.Issue_File_Attempt : TelemetryAction.Issue_Save;

            return(new TelemetryEvent(action, new Dictionary <TelemetryProperty, string>
            {
                { TelemetryProperty.IssueReporter, IssueReporter.DisplayName?.ToString(CultureInfo.InvariantCulture) },
            }));
        }
        /// <summary>
        /// File an issue. Telemetry wrapper.
        /// </summary>
        /// <param name="issueInformation">Issue infromation to pass on to the reporter</param>
        /// <returns></returns>
        public static IIssueResult FileIssueAsync(IssueInformation issueInformation)
        {
            if (!IssueReporter.IsEnabled)
            {
                return(null);
            }

            try
            {
                IIssueResult issueResult    = IssueReporter.FileIssueAsync(issueInformation);
                var          telemetryEvent = TelemetryEventFactory.ForIssueFilingCompleted(issueResult, issueInformation);
                Logger.PublishTelemetryEvent(telemetryEvent);
                return(issueResult);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
                return(null);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
Ejemplo n.º 11
0
        /// <summary>
        /// File an issue. Telemetry wrapper.
        /// </summary>
        /// <param name="issueInformation">Issue infromation to pass on to the reporter</param>
        /// <returns></returns>
        public static IIssueResult FileIssueAsync(IssueInformation issueInformation)
        {
            if (!IssueReporter.IsEnabled)
            {
                return(null);
            }

            try
            {
                IIssueResult issueResult = IssueReporter.FileIssueAsync(issueInformation);

                if (issueResult.IssueLink != null)
                {
                    if (issueInformation.RuleForTelemetry != null)
                    {
                        Logger.PublishTelemetryEvent(TelemetryAction.Issue_Save, new Dictionary <TelemetryProperty, string>
                        {
                            { TelemetryProperty.RuleId, issueInformation.RuleForTelemetry },
                            { TelemetryProperty.UIFramework, issueInformation.UIFramework ?? string.Empty },
                        });
                    }
                    else // if the bug is coming from the hierarchy tree, it will not have ruleID or UIFramework
                    {
                        Logger.PublishTelemetryEvent(TelemetryAction.Issue_Save);
                    }
                }
                else
                {
                    Logger.PublishTelemetryEvent(TelemetryAction.Issue_File_Attempt);
                }
                return(issueResult);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 12
0
        /// <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();
                    }
                }
            }
        }