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 bugInfo  = new BugInformation(ruleForTelemetry: RuleId.BoundingRectangleContainedInParent.ToString());
                var connInfo = new StubIConnectionInfo
                {
                    ServerUriGet = () => FAKE_SERVER_URL,
                };
                (int?bugId, string newBugId) = FileBugAction.FileNewBug(bugInfo,
                                                                        connInfo, false, 0, (_) => { });

                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 RemoveInternalFromBugText_NoMatchingText()
        {
            var guid = Guid.NewGuid().ToString();

            string original = "<br><br><div><hr>should not be removed<hr></div>";
            string expected = "\r\n<BODY><BR><BR>\r\n<DIV>\r\n<HR>\r\nshould not be removed\r\n<HR>\r\n</DIV></BODY>";

            Assert.AreEqual(expected, FileBugAction.RemoveInternalHTML(original, guid));
        }
        public void RemoveInternalFromBugText_MatchingTextExists()
        {
            var guid = Guid.NewGuid().ToString();
            // Internal id doesn't exist if the text is modified by user in edit pane. this scenario simulate the case.
            string original = $"<br><br><div><hr>{guid}<hr></div>";
            string expected = "\r\n<BODY><BR><BR>\r\n<DIV></DIV></BODY>";

            Assert.AreEqual(expected, FileBugAction.RemoveInternalHTML(original, guid));
        }
        public void FileNewBug_IsNotEnabled_ReturnsPlaceholder()
        {
            using (ShimsContext.Create())
            {
                ShimBugReporter.IsEnabledGet = () => false;
                var bugInfo  = new BugInformation();
                var connInfo = new StubIConnectionInfo();
                var output   = FileBugAction.FileNewBug(bugInfo,
                                                        connInfo, false, 0, (_) => { });

                Assert.IsNull(output.bugId);
                Assert.IsNotNull(output.newBugId);
                Assert.IsTrue(string.IsNullOrEmpty(output.newBugId));
            }
        }
        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 bugInfo  = new BugInformation();
                var connInfo = new StubIConnectionInfo
                {
                    ServerUriGet = () => FAKE_SERVER_URL,
                };
                (int?bugId, string newBugId) = FileBugAction.FileNewBug(bugInfo,
                                                                        connInfo, false, 0, (_) => { });

                Assert.AreEqual(0, telemetryLog.Count);
            }
        }
        /// <summary>
        /// Handles click on file bug button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnFileBug_Click(object sender, RoutedEventArgs e)
        {
            var vm = ((Button)sender).Tag as ScanListViewItemViewModel;

            if (vm.BugId.HasValue)
            {
                // Bug already filed, open it in a new window
                try
                {
                    var bugUri = await BugReporter.GetExistingBugUriAsync(vm.BugId.Value).ConfigureAwait(true);

                    System.Diagnostics.Process.Start(bugUri.ToString());
                }
                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.BugId = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>()
                {
                    { TelemetryProperty.By, FileBugRequestSource.HowtoFix.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, BugReporter.IsConnected.ToString(CultureInfo.InvariantCulture) }
                });

                // TODO: figuring out whether a team project has been chosen should not require
                //  looking at the most recent connection, this should be broken out
                if (BugReporter.IsConnected && Configuration.SavedConnection?.IsPopulated == true)
                {
                    Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;
                    (int?bugId, string newBugId) = FileBugAction.FileNewBug(vm.GetBugInformation(), Configuration.SavedConnection, Configuration.AlwaysOnTop, Configuration.ZoomLevel, updateZoom);

                    vm.BugId = bugId;

                    // Check whether bug was filed once dialog closed & process accordingly
                    if (vm.BugId.HasValue)
                    {
                        vm.LoadingVisibility = Visibility.Visible;
                        try
                        {
                            var success = await FileBugAction.AttachBugData(this.EcId, vm.Element.BoundingRectangle,
                                                                            vm.Element.UniqueId, newBugId, vm.BugId.Value).ConfigureAwait(false);

                            if (!success)
                            {
                                MessageDialog.Show(Properties.Resources.ScannerResultControl_btnFileBug_Click_There_was_an_error_identifying_the_created_bug_This_may_occur_if_the_ID_used_to_create_the_bug_is_removed_from_its_AzureDevOps_description_Attachments_have_not_been_uploaded);
                                vm.BugId = null;
                            }
                            vm.LoadingVisibility = Visibility.Collapsed;
                        }
                        catch (Exception)
                        {
                            vm.LoadingVisibility = Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.ScannerResultControl_btnFileBug_Click_Please_log_in_to_AzureDevOps_ensure_both_AzureDevOps_account_name_and_team_project_are_selected);
                    if (accepted.HasValue && accepted.Value)
                    {
                        SwitchToServerLogin();
                    }
                }
            }
        }
Beispiel #7
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.BugId.HasValue)
            {
                // Bug already filed, open it in a new window
                try
                {
                    var bugUrl = BugReporter.GetExistingBugUriAsync(vm.BugId.Value).Result.ToString();
                    Process.Start(bugUrl);
                }
                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.BugId = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>()
                {
                    { TelemetryProperty.By, FileBugRequestSource.AutomatedChecks.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, BugReporter.IsConnected.ToString(CultureInfo.InvariantCulture) }
                });

                // TODO: figuring out whether a team project has been chosen should not require
                //  looking at the most recent connection, this should be broken out
                if (BugReporter.IsConnected && Configuration.SavedConnection?.IsPopulated == true)
                {
                    Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;

                    (int?bugId, string newBugId) = FileBugAction.FileNewBug(vm.GetBugInformation(), Configuration.SavedConnection,
                                                                            Configuration.AlwaysOnTop, Configuration.ZoomLevel, updateZoom);

                    vm.BugId = bugId;

                    // Check whether bug was filed once dialog closed & process accordingly
                    if (vm.BugId.HasValue)
                    {
                        try
                        {
                            var sc = DispatcherSynchronizationContext.Current;
                            vm.LoadingVisibility = Visibility.Visible;
                            var task = FileBugAction.AttachBugData(this.ElementContext.Id, vm.Element.BoundingRectangle, vm.Element.UniqueId, newBugId, vm.BugId.Value);

#pragma warning disable CA2008 // Do not create tasks without passing a TaskScheduler
                            task.ContinueWith(delegate
                            {
                                sc.Post(delegate {
                                    vm.LoadingVisibility = Visibility.Collapsed;

                                    if (!task.Result)
                                    {
                                        MessageDialog.Show(Properties.Resources.AutomatedChecksControl_btnFileBug_Click_There_was_an_error_identifying_the_created_bug__This_may_occur_if_the_ID_used_to_create_the_bug_is_removed_from_its_AzureDevOps_description__Attachments_have_not_been_uploaded);
                                        vm.BugId = null;
                                    }
                                }, null);
                            });
#pragma warning restore CA2008 // Do not create tasks without passing a TaskScheduler
                        }
                        catch (Exception)
                        {
                            vm.LoadingVisibility = Visibility.Collapsed;
                        }
                    }
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.AutomatedChecksControl_btnFileBug_Click_Please_sign_into_Azure_DevOps_ensure_both_AzureDevOps_account_name_and_team_project_are_selected);
                    if (accepted.HasValue && accepted.Value)
                    {
                        SwitchToServerLogin();
                    }
                }
            }
        }
        public async 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.BugId.HasValue)
            {
                // Bug already filed, open it in a new window
                try
                {
                    Uri uri = await BugReporter.GetExistingBugUriAsync(vm.BugId.Value).ConfigureAwait(true);

                    var bugUrl = uri.ToString();
                    System.Diagnostics.Process.Start(bugUrl);
                }
                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.BugId = null;
                }
            }
            else
            {
                // File a new bug
                Logger.PublishTelemetryEvent(TelemetryAction.Scan_File_Bug, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.By, FileBugRequestSource.Hierarchy.ToString() },
                    { TelemetryProperty.IsAlreadyLoggedIn, BugReporter.IsConnected.ToString(CultureInfo.InvariantCulture) },
                });

                if (BugReporter.IsConnected && Configuration.SavedConnection?.IsPopulated == true)
                {
                    Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;
                    (int?bugId, string newBugId) = FileBugAction.FileNewBug(this.SelectedElement.GetBugInformation(BugType.NoFailure), Configuration.SavedConnection, Configuration.AlwaysOnTop, Configuration.ZoomLevel, updateZoom);

                    vm.BugId = bugId;

                    // Check whether bug was filed once dialog closed & process accordingly
                    if (vm.BugId.HasValue)
                    {
                        try
                        {
                            var success = await FileBugAction.AttachBugData(this.ElementContext.Id, this.SelectedElement.BoundingRectangle,
                                                                            this.SelectedElement.UniqueId, newBugId, vm.BugId.Value).ConfigureAwait(false);

                            if (!success)
                            {
                                MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_There_was_an_error_identifying_the_created_bug_This_may_occur_if_the_ID_used_to_create_the_bug_is_removed_from_its_Azure_DevOps_description_Attachments_have_not_been_uploaded);
                                vm.BugId = null;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else
                {
                    bool?accepted = MessageDialog.Show(Properties.Resources.HierarchyControl_FileBug_Please_sign_in_to_Azure_DevOps_specify_both_Azure_DevOps_organization_name_and_project);
                    if (accepted.HasValue && accepted.Value)
                    {
                        this.HierarchyActions.SwitchToServerLogin();
                    }
                }
            }
        }