/// <summary>
        /// Sets up a dummy query and layout for the given project.
        /// </summary>
        /// <param name="project">The mock project to create the query and layout for.</param>
        /// <param name="fields">Any extra fields that the layout specifies should be included in the query.</param>
        /// <returns>The dummy query and layout.</returns>
        private QueryAndLayoutInformation SetupDummyPickedQueryAndLayout(Mock <ITeamProject> project, params string[] fields)
        {
            QueryAndLayoutInformation queryLayout = new QueryAndLayoutInformation(TestHelper.ValidQueryDefinition, TestHelper.CreateTestLayoutInformation(fields));

            this.MockWorkItemQueryAndLayoutPickerWizardPresenter.Setup(picker => picker.QueryAndLayout).Returns(queryLayout);
            return(queryLayout);
        }
Exemple #2
0
        public void MultipleEntriesHaveSequentialIndicesAfterSecondLotOfAdditions()
        {
            // Arrange
            QueryAndLayoutInformation newItem1 = TestHelper.ValidQueryDefinitionAndLayout;
            QueryAndLayoutInformation newItem2 = TestHelper.ValidQueryDefinitionAndLayout;
            QueryAndLayoutInformation newItem3 = TestHelper.ValidQueryDefinitionAndLayout;
            QueryAndLayoutInformation newItem4 = TestHelper.ValidQueryDefinitionAndLayout;

            this.sut.Add(newItem1);
            this.sut.Add(newItem1);
            this.sut.FinalQueriesAndLayouts.Count();
            this.sut.AddRange(newItem3, newItem4);

            // Act
            QueryAndLayoutInformation ans1 = this.sut.FinalQueriesAndLayouts.First();
            QueryAndLayoutInformation ans2 = this.sut.FinalQueriesAndLayouts.Skip(1).First();
            QueryAndLayoutInformation ans3 = this.sut.FinalQueriesAndLayouts.Skip(2).First();
            QueryAndLayoutInformation ans4 = this.sut.FinalQueriesAndLayouts.Skip(3).First();

            // Assert
            Assert.AreEqual <int>(0, ans1.Index, "First entry does not have correct index");
            Assert.AreEqual <int>(1, ans2.Index, "Second entry does not have correct index");
            Assert.AreEqual <int>(2, ans3.Index, "Third entry does not have correct index");
            Assert.AreEqual <int>(3, ans4.Index, "Fourth entry does not have correct index");
        }
Exemple #3
0
        /// <summary>
        /// Adds the <paramref name="queryAndLayout"/> to the collection of queries and layouts in the document, but does not save the new query and layout.
        /// </summary>
        /// <param name="queryAndLayout">The query and layout to be added.</param>
        /// <returns>The query and layout with the query modified to include all the fields from all the layouts and exclude any fields not defined in the team project.</returns>
        public QueryAndLayoutInformation AddQueryAndLayout(QueryAndLayoutInformation queryAndLayout)
        {
            if (this.teamProject == null)
            {
                throw new InvalidOperationException(ModelResources.TeamProjectNotSet);
            }

            return(this.queryAndLayoutManager.Add(queryAndLayout));
        }
Exemple #4
0
        public void CanAddAQueryAndLayoutToTheManager()
        {
            // Arrange
            QueryAndLayoutInformation newItem = TestHelper.ValidQueryDefinitionAndLayout;

            // Act
            this.sut.Add(newItem);

            // Assert
            Assert.AreEqual <int>(1, this.sut.OriginalQueriesAndLayouts.Count(), "There should now be one query and layout stored in the manager");
            Assert.AreSame(newItem, this.sut.OriginalQueriesAndLayouts.First(), "The query and layout object that was added should be returned.");
        }
Exemple #5
0
        public void ExistingFieldsInTheLayoutNotAddedAgainToFinalQuery()
        {
            // Arrange
            QueryAndLayoutInformation ql = TestHelper.CreateQueryAndLayout(SystemIdOnlyQuery, SystemIdReferenceName);

            this.sut.Add(ql);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreEqual <string>(SystemIdOnlyQuery, ans.Query.QueryText, "Changed query when no new fields were supposed to be added.");
        }
Exemple #6
0
        public void FinalQueriesAndLayoutsPreservesLayout()
        {
            // Arrange
            QueryAndLayoutInformation newItem = TestHelper.ValidQueryDefinitionAndLayout;

            this.sut.Add(newItem);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreSame(newItem.Layout, ans.Layout, "Layout not preserved");
        }
Exemple #7
0
        public void FinalQueriesAndLayoutsPreservesQueryDefinitionNames()
        {
            // Arrange
            QueryAndLayoutInformation newItem = TestHelper.ValidQueryDefinitionAndLayout;

            this.sut.Add(newItem);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreEqual <string>(newItem.Query.Name, ans.Query.Name, "QueryDefinition name not preserved");
        }
Exemple #8
0
        public void LayoutFieldsMergedIntoFinalFlatQuery()
        {
            // Arrange
            QueryAndLayoutInformation ql = TestHelper.CreateQueryAndLayout(SystemIdOnlyQuery, SystemTitleReferenceName);

            this.sut.Add(ql);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreEqual <string>("SELECT [System.Id], [System.Title] FROM WorkItems", ans.Query.QueryText, "Layout fields not merged correctly");
        }
Exemple #9
0
        public void IgnoresCaseAndWhiteSpaceWhenMergingFieldsFromLayout()
        {
            // Arrange
            QueryAndLayoutInformation ql = TestHelper.CreateQueryAndLayout("select    [system.id]   from WorkItems", SystemIdReferenceName.ToUpperInvariant(), SystemTitleReferenceName);

            this.sut.Add(ql);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreEqual <string>("SELECT [system.id]  , [System.Title] FROM WorkItems", ans.Query.QueryText, "Layout fields not merged correctly");
        }
        public void CancellingWizardReturnsNullQueryAndLayoutDefinition()
        {
            // Arrange
            this.mockView.Setup(view => view.StartDialog()).Returns(false);
            this.sut.Initialise();

            // Act
            this.sut.Start();
            QueryAndLayoutInformation ans = this.sut.QueryAndLayout;

            // Assert
            Assert.IsNull(ans, "Should return a null query and layout if the wizard is cancelled");
        }
Exemple #11
0
        public void FieldsInTheLayoutNotInTeamProjectAreNotAddedToFinalQuery()
        {
            // Arrange
            QueryAndLayoutInformation ql = TestHelper.CreateQueryAndLayout(SystemIdOnlyQuery, "System.NoSuchField");

            this.sut.Add(ql);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreEqual <string>(SystemIdOnlyQuery, ans.Query.QueryText, "Non-existent project field should not be added to the final query");
        }
Exemple #12
0
        public void FirstEntryHasZeroIndex()
        {
            // Arrange
            QueryAndLayoutInformation newItem = TestHelper.ValidQueryDefinitionAndLayout;

            this.sut.Add(newItem);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.AreEqual <int>(0, ans.Index, "First entry does not have correct index");
        }
Exemple #13
0
        public void AddReturnsTheModifiedQuery()
        {
            // Arrange
            QueryAndLayoutInformation ql1 = TestHelper.CreateQueryAndLayout(SystemIdOnlyQuery, SystemTitleReferenceName, SystemAreaReferenceName);
            QueryAndLayoutInformation ql2 = TestHelper.CreateQueryAndLayout(SystemTitleOnlyQuery, SystemIdReferenceName, SystemDescriptionReferenceName);

            this.sut.Add(ql1);

            // Act
            QueryAndLayoutInformation ans = this.sut.Add(ql2);

            // Assert
            Assert.AreSame(this.sut.FinalQueriesAndLayouts.Last().Query, ans.Query, "Add did not return the modified query.");
        }
Exemple #14
0
        public void CanAddMoreThanOneQueryAndLayoutToTheManagerAtOneTime()
        {
            // Arrange
            QueryAndLayoutInformation newItem1 = TestHelper.ValidQueryDefinitionAndLayout;
            QueryAndLayoutInformation newItem2 = TestHelper.ValidQueryDefinitionAndLayout;

            Assert.AreNotSame(newItem1, newItem2, "Test not valid if the two objects are actually the same object.");

            // Act
            this.sut.AddRange(newItem1, newItem2);

            // Assert
            Assert.IsTrue(TestHelper.CheckUnorderedUniqueArrayMatch <QueryAndLayoutInformation>(new QueryAndLayoutInformation[] { newItem1, newItem2 }, this.sut.OriginalQueriesAndLayouts.ToArray()), "Distinct items not returned.");
        }
Exemple #15
0
        public void AllLayoutFieldsReturnsListOfAllFieldsReferencedInAllLayouts()
        {
            // Arrange
            QueryAndLayoutInformation ql1 = TestHelper.CreateQueryAndLayout(SystemIdOnlyQuery, SystemIdReferenceName, SystemTitleReferenceName, SystemAreaReferenceName);
            QueryAndLayoutInformation ql2 = TestHelper.CreateQueryAndLayout(SystemTitleOnlyQuery, SystemIdReferenceName, SystemDescriptionReferenceName);

            this.sut.Add(ql1);
            this.sut.Add(ql2);

            // Act
            string[] ans = this.sut.AllLayoutFields.ToArray();

            // Assert
            Assert.IsTrue(TestHelper.CheckUnorderedUniqueArrayMatch <string>(new string[] { SystemIdReferenceName, SystemTitleReferenceName, SystemAreaReferenceName, SystemDescriptionReferenceName }, ans), "Did not merge all layout fields");
        }
Exemple #16
0
        public void MultipleEntriesHaveSequentialIndices()
        {
            // Arrange
            QueryAndLayoutInformation newItem1 = TestHelper.ValidQueryDefinitionAndLayout;
            QueryAndLayoutInformation newItem2 = TestHelper.ValidQueryDefinitionAndLayout;

            this.sut.Add(newItem1);
            this.sut.Add(newItem1);

            // Act
            QueryAndLayoutInformation ans1 = this.sut.FinalQueriesAndLayouts.First();
            QueryAndLayoutInformation ans2 = this.sut.FinalQueriesAndLayouts.Skip(1).First();

            // Assert
            Assert.AreEqual <int>(0, ans1.Index, "First entry does not have correct index");
            Assert.AreEqual <int>(1, ans2.Index, "Second entry does not have correct index");
        }
        public void ConfirmingAQueryAndLayoutReturnsChosenInformationWithModifiedQuery()
        {
            // Arrange
            QueryDefinition           query    = this.SetupSelectedValidQueryOnQueryPagePresenter();
            LayoutInformation         layout   = this.SetupSelectedLayoutOnLayoutPagePresenter();
            QueryAndLayoutInformation expected = new QueryAndLayoutInformation(TestHelper.ValidQueryDefinition, layout);

            Assert.AreNotSame(query, expected.Query, "Pre-requisites of test not satisfied, using same query as initial and final");
            this.mockView.Setup(view => view.StartDialog()).Returns(true);
            this.mockDocument.Setup(doc => doc.AddQueryAndLayout(It.IsAny <QueryAndLayoutInformation>())).Returns(expected);
            this.sut.Initialise();

            // Act
            this.sut.Start();
            QueryAndLayoutInformation ans = this.sut.QueryAndLayout;

            // Assert
            Assert.AreSame(expected.Query, ans.Query, "Should return the definition of the chosen query after modification by the document.");
            Assert.AreSame(layout, ans.Layout, "Should return the chosen layout.");
        }
Exemple #18
0
        public void FinalQueryCanBeConstructedFromQueryContainingNewlineCharacters()
        {
            // Arrange
            QueryAndLayoutInformation ql = TestHelper.CreateQueryAndLayout(
                @"SELECT [System.Id], [System.WorkItemType]
                                                                            FROM WorkItemLinks
                                                                            WHERE Source.[System.TeamProject] = @project
                                                                            ORDER BY [Microsoft.VSTS.Common.BacklogPriority] ASC, [System.Id] ASC
                                                                            MODE (Recursive)
                                                                            ",
                SystemIdReferenceName);

            this.sut.Add(ql);

            // Act
            QueryAndLayoutInformation ans = this.sut.FinalQueriesAndLayouts.First();

            // Assert
            Assert.IsNotNull(ans.Query);
        }
Exemple #19
0
        public void EachQueryMergedWithAllFieldsFromAllLayouts()
        {
            // Arrange
            QueryAndLayoutInformation ql1 = TestHelper.CreateQueryAndLayout(SystemIdOnlyQuery, SystemTitleReferenceName, SystemAreaReferenceName);
            QueryAndLayoutInformation ql2 = TestHelper.CreateQueryAndLayout(SystemTitleOnlyQuery, SystemIdReferenceName, SystemDescriptionReferenceName);

            this.sut.Add(ql1);
            this.sut.FinalQueriesAndLayouts.Count();
            this.sut.Add(ql2);

            // Act
            string[] ans = this.sut.FinalQueriesAndLayouts.Select(qli => qli.Query.QueryText).ToArray();

            // Assert
            Assert.AreEqual <int>(2, ans.Length, "Expecting two queries, not adding to list correctly");
            string[] expectedFields = new string[] { SystemIdReferenceName, SystemTitleReferenceName, SystemDescriptionReferenceName, SystemAreaReferenceName };
            foreach (string field in expectedFields)
            {
                foreach (string query in ans)
                {
                    Assert.IsTrue(query.Contains(field), string.Format(CultureInfo.InvariantCulture, "Not all fields have been merged into all queries. Missing field is {0}, failing query is {1}", field, query));
                }
            }
        }
        /// <summary>
        /// Sets up a dummy null query and layout for the given project.
        /// </summary>
        /// <param name="project">The mock project to create the query and layout for.</param>
        private void SetupDummyNoPickedQueryAndLayout(Mock <ITeamProject> project)
        {
            QueryAndLayoutInformation queryLayout = null;

            this.MockWorkItemQueryAndLayoutPickerWizardPresenter.Setup(picker => picker.QueryAndLayout).Returns(queryLayout);
        }
Exemple #21
0
        private void HandleTeamRibbonImport(object sender, System.EventArgs e)
        {
            this.Logger.Log(TraceEventType.Information, "Flow controller HandleTeamRibbonImport called");
            Debug.Assert(this.Manager.ActiveContainer != null, "There should be an active container in the team project document manager");
            Debug.Assert(this.Manager.ActiveDocument != null, "There should be an active document in the team project document manager");
            ITeamProject teamProject = null;
            ITeamProjectPickerPresenter projectPickerPresenter = null;

            if (!this.Manager.ActiveDocument.IsInsertable)
            {
                this.TeamRibbonPresenter.DisplayError(FlowControllerResources.DocumentNotInsertable, string.Empty);
            }
            else if (!this.Manager.ActiveDocument.IsConnected)
            {
                projectPickerPresenter = this.Manager.ActiveContainer.Resolve <ITeamProjectPickerPresenter>();
                teamProject            = projectPickerPresenter.ChooseTeamProject();
            }
            else
            {
                teamProject = this.Manager.ActiveDocument.TeamProject;
            }

            if (teamProject != null)
            {
                this.Manager.ActiveContainer.RegisterInstance <ITeamProject>(teamProject);
                IWorkItemQueryAndLayoutPickerWizardPresenter workItemAndLayoutPickerWizardPresenter = this.Manager.ActiveContainer.Resolve <IWorkItemQueryAndLayoutPickerWizardPresenter>();
                workItemAndLayoutPickerWizardPresenter.Initialise();
                workItemAndLayoutPickerWizardPresenter.Start();
                QueryAndLayoutInformation queryAndLayout = workItemAndLayoutPickerWizardPresenter.QueryAndLayout;
                if (queryAndLayout != null)
                {
                    CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                    TaskScheduler           scheduler = this.UnityContainer.Resolve <TaskScheduler>();

                    Task <WorkItemTree> runQueryTask = new Task <WorkItemTree>(
                        () =>
                    {
                        this.Logger.Log(TraceEventType.Information, "Starting query for work items");
                        WorkItemTree ans = teamProject.QueryRunner.QueryForWorkItems(queryAndLayout.Query, cancellationTokenSource.Token);
                        this.Logger.Log(TraceEventType.Information, "Finished querying for work items");
                        return(ans);
                    },
                        cancellationTokenSource.Token);

                    Task queryErrorTask = runQueryTask.ContinueWith(
                        antecedent =>
                    {
                        this.Logger.Log(TraceEventType.Error, "Query execution failed: {0}", antecedent.Exception.InnerException.Message);
                    },
                        cancellationTokenSource.Token,
                        TaskContinuationOptions.OnlyOnFaulted,
                        scheduler);

                    Task queryDoneTask = runQueryTask.ContinueWith(
                        (antecedent) =>
                    {
                        this.Logger.Log(TraceEventType.Information, "Adding work items to document");
                        this.TeamRibbonPresenter.UpdateCancellableOperation(
                            FlowControllerResources.AddingWorkItemsToDocument);

                        if (projectPickerPresenter != null)
                        {
                            projectPickerPresenter.SaveTeamProject();
                        }

                        workItemAndLayoutPickerWizardPresenter.SaveQueryAndLayout();
                        this.Manager.ActiveDocument.SaveWorkItems(antecedent.Result, queryAndLayout.Layout.FieldNames.ToArray(), cancellationTokenSource.Token);
                        this.Manager.ActiveDocument.MapWorkItemsIntoDocument(queryAndLayout.Layout, queryAndLayout.Index, cancellationTokenSource.Token);
                        this.Logger.Log(TraceEventType.Information, "Finished adding work items to document");
                    },
                        cancellationTokenSource.Token,
                        TaskContinuationOptions.OnlyOnRanToCompletion,
                        scheduler);

                    this.AddFinalErrorHandlingTask(scheduler, runQueryTask, queryErrorTask, queryDoneTask);

                    runQueryTask.Start(scheduler);
                    this.TeamRibbonPresenter.StartCancellableOperation(FlowControllerResources.StartQueryExecution, cancellationTokenSource);
                }
            }

            this.TeamRibbonPresenter.UpdateState();
        }
Exemple #22
0
 /// <summary>
 /// Adds a new query and layout to the manager.
 /// </summary>
 /// <param name="queryAndLayout">The query and layout to be added.</param>
 /// <returns>The query and layout with the query modified to include all the fields from all the layouts and exclude any fields not defined in the team project.</returns>
 public QueryAndLayoutInformation Add(QueryAndLayoutInformation queryAndLayout)
 {
     this.originalQueriesAndLayouts.Add(queryAndLayout);
     this.BuildFinalQueries();
     return(this.finalQueriesAndLayouts.Last());
 }