예제 #1
0
        /// <summary>
        /// Repopulates the team projects and children teams
        ///     returns a started Task so it can be awaited on
        /// </summary>
        private static Task <List <TeamProjectViewModel> > UpdateTeamProjects()
        {
            Task <List <TeamProjectViewModel> > t = Task.Run <List <TeamProjectViewModel> >(() =>
            {
                List <TeamProjectViewModel> result = new List <TeamProjectViewModel>();
                try
                {
                    var projects = FileIssueHelpers.GetProjectsAsync().Result;
                    foreach (var project in projects.OrderBy(project => project.Name))
                    {
                        var vm = new TeamProjectViewModel(project, new List <TeamProjectViewModel>());
                        result.Add(vm);
                    }
                    PopulateTreeviewWithTeams(result);
                    return(result);
                }
#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
            });

            return(t);
        }
예제 #2
0
        /// <summary>
        /// Logs the user in and moves to editing server screen.
        /// Forces a configuration change to the saved connection so the server URL is set,
        /// but the team project and team are null
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void NextButton_Click(object sender, RoutedEventArgs e)
        {
            if (InteractionAllowed)
            {
                if (Uri.IsWellFormedUriString(ServerComboBox.Text, UriKind.Absolute))
                {
                    var serverUri = ToUri(ServerComboBox.Text);

                    // block clicking "next" until login request is done
                    ToggleLoading(true);
                    await AzureDevOps.HandleLoginAsync(CredentialPromptType.PromptIfNeeded, serverUri).ConfigureAwait(false);

                    if (AzureDevOps.ConnectedToAzureDevOps)
                    {
                        AzureDevOps.Configuration.SavedConnection = FileIssueHelpers.CreateConnectionInfo(serverUri, null, null);
                        ChangeStates(ControlState.EditingServer);
                    }
                    else
                    {
                        ToggleLoading(false);
                        Dispatcher.Invoke(ServerComboBox.Focus);
                    }
                }
                else
                {
                    Dispatcher.Invoke(() => MessageDialog.Show(Properties.Resources.ADO_URL_Fromat_Message));
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Returns a connection info object from the selected fields in the treeview
        /// - also sets the date of last usage
        /// </summary>
        /// <returns></returns>
        private ConnectionInfo GetConnectionFromTreeView()
        {
            if (this.serverTreeview.SelectedItem == null)
            {
                return(null);
            }
            var item    = this.serverTreeview.SelectedItem;
            var vm      = item as TeamProjectViewModel;
            var team    = vm.Team;
            var project = vm.Project;

            if (team != null)
            {
                project = team.ParentProject;
            }
            else if (project != null)
            {
                team = null;
            }

            ConnectionInfo connection = FileIssueHelpers.CreateConnectionInfo(new Uri(this.ServerComboBox.Text), project, team);

            connection.SetLastUsage(DateTime.Now);
            return(connection);
        }
예제 #4
0
        public void CreateIssuePreviewAsync_TeamNameIsNotNull_ChainsThroughCorrectly()
        {
            using (ShimsContext.Create())
            {
                const string expectedProjectName = "Ultra Project";
                const string expectedTeamName    = "Ultra Team";
                string       actualProjectName   = null;
                string       actualTeamName      = null;
                Uri          expectedUri         = new Uri("https://www.bing.com");

                AzureDevOpsIntegration integration = new ShimAzureDevOpsIntegration
                {
                    CreateIssuePreviewStringStringIReadOnlyDictionaryOfAzureDevOpsFieldString = (p, t, f) =>
                    {
                        actualProjectName = p;
                        actualTeamName    = t;
                        return(expectedUri);
                    },
                    ConnectedToAzureDevOpsGet = () => true,
                };

                ShimAzureDevOpsIntegration.GetCurrentInstance = () => integration;

                ConnectionInfo connectionInfo = new ConnectionInfo(expectedUri,
                                                                   new TeamProject(expectedProjectName, Guid.Empty),
                                                                   new Team(expectedTeamName, Guid.Empty));
                IssueInformation issueInfo = new IssueInformation();

                Uri actualUri = FileIssueHelpers.CreateIssuePreviewAsync(connectionInfo, issueInfo).Result;

                Assert.AreEqual(expectedUri, actualUri);
                Assert.AreEqual(expectedProjectName, actualProjectName);
                Assert.AreEqual(expectedTeamName, actualTeamName);
            }
        }
예제 #5
0
        internal async Task HandleLoginAsync(CredentialPromptType showDialog = CredentialPromptType.DoNotPrompt, Uri serverUri = null)
        {
            serverUri = serverUri ?? Configuration.SavedConnection.ServerUri;

            if (serverUri == null)
            {
                return;
            }

            // If the main window is always on top, then an error occurs where
            //  the login dialog is not a child of the main window, so we temporarily
            //  turn topmost off and turn it back on after logging in
            bool oldTopmost = false;

            Application.Current.Dispatcher.Invoke(() =>
            {
                oldTopmost = Application.Current.MainWindow.Topmost;
                Application.Current.MainWindow.Topmost = false;
            });

            try
            {
                await FileIssueHelpers.ConnectAsync(serverUri, showDialog).ConfigureAwait(true);

                await FileIssueHelpers.PopulateUserProfileAsync().ConfigureAwait(true);
            }
            catch (Exception)
            {
                FileIssueHelpers.FlushToken(serverUri);
            }

            Application.Current.Dispatcher.Invoke(() => Application.Current.MainWindow.Topmost = oldTopmost);
        }
예제 #6
0
        public void RemoveInternalFromIssueText_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, FileIssueHelpers.RemoveInternalHTML(original, guid));
        }
예제 #7
0
        public void RemoveInternalFromIssueText_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, FileIssueHelpers.RemoveInternalHTML(original, guid));
        }
        public void FileNewIssue_IsNotEnabled_ReturnsPlaceholder()
        {
            using (ShimsContext.Create())
            {
                ShimAzureDevOpsIntegration.AllInstances.ConnectedToAzureDevOpsGet = (_) => false;
                var issueInfo = new IssueInformation();
                var connInfo  = new ConnectionInfo();
                var output    = FileIssueHelpers.FileNewIssue(issueInfo,
                                                              connInfo, false, 0, (_) => { });

                Assert.IsNull(output.issueId);
                Assert.IsNotNull(output.newIssueId);
                Assert.IsTrue(string.IsNullOrEmpty(output.newIssueId));
            }
        }
예제 #9
0
        public Task <IIssueResult> FileIssueAsync(IssueInformation issueInfo)
        {
            bool topMost = false;

            Application.Current.Dispatcher.Invoke(() => topMost = Application.Current.MainWindow.Topmost);

            Action <int> updateZoom = (int x) => Configuration.ZoomLevel = x;

            (int?issueId, string newIssueId) = FileIssueHelpers.FileNewIssue(issueInfo, Configuration.SavedConnection,
                                                                             topMost, Configuration.ZoomLevel, updateZoom);

            return(Task.Run <IIssueResult>(() => {
                // Check whether issue was filed once dialog closed & process accordingly
                if (!issueId.HasValue)
                {
                    return null;
                }

                try
                {
                    if (!FileIssueHelpers.AttachIssueData(issueInfo, newIssueId, issueId.Value).Result)
                    {
                        MessageDialog.Show(Properties.Resources.There_was_an_error_identifying_the_created_issue_This_may_occur_if_the_ID_used_to_create_the_issue_is_removed_from_its_Azure_DevOps_description_Attachments_have_not_been_uploaded);
                    }

                    return new IssueResult()
                    {
                        DisplayText = issueId.ToString(),
                        IssueLink = AzureDevOps.GetExistingIssueUrl(issueId.Value)
                    };
                }
#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

                return null;
            }));
        }
        /// <summary>
        /// Repopulates the team projects and children teams
        ///     returns a started Task so it can be awaited on
        /// </summary>
        private static Task <List <TeamProjectViewModel> > UpdateTeamProjects()
        {
            Task <List <TeamProjectViewModel> > t = Task.Run <List <TeamProjectViewModel> >(() =>
            {
                List <TeamProjectViewModel> result = new List <TeamProjectViewModel>();
                try
                {
                    var projects = FileIssueHelpers.GetProjectsAsync().Result;
                    foreach (var project in projects.OrderBy(project => project.Name))
                    {
                        var vm = new TeamProjectViewModel(project, new List <TeamProjectViewModel>());
                        result.Add(vm);
                    }
                    PopulateTreeviewWithTeams(result);
                    return(result);
                }
                catch (Exception)
                {
                    return(null);
                }
            });

            return(t);
        }
예제 #11
0
 public void BeforeEach()
 {
     _adoIntegrationMock = new Mock <IDevOpsIntegration>(MockBehavior.Strict);
     _fileIssueHelpers   = new FileIssueHelpers(_adoIntegrationMock.Object);
 }
예제 #12
0
 public void CreateIssuePreviewAsync_IssueInfoIsNull_ThrowsArgumentNullException()
 {
     FileIssueHelpers.CreateIssuePreviewAsync(new ConnectionInfo(), null);
 }
예제 #13
0
 /// <summary>
 /// Unit testable ctor
 /// </summary>
 internal AzureBoardsIssueReporting(IDevOpsIntegration devOpsIntegration, FileIssueHelpers fileIssueHelpers)
 {
     _fileIssueHelpers  = fileIssueHelpers;
     _devOpsIntegration = devOpsIntegration;
     DevOpsIntegration  = devOpsIntegration;
 }
 public void FileNewIssue_FileIssueIsNull_ThrowsArgumentNullException()
 {
     FileIssueHelpers.FileNewIssue(null, new ConnectionInfo(), false, 100, (unused) => { Assert.Fail("This method should never be called"); });
 }