public ITeamProject ChooseTeamProject() { try { TeamProjectInformation tpi = this.pickerView.ChooseTeamProject(); this.waitNotifier.StartWait(); if (tpi == null) { this.chosenTeamProject = null; } else { this.chosenTeamProject = this.factory.CreateTeamProject(tpi.CollectionUri, tpi.ProjectName, tpi.Credentials); } this.projectDocument.TeamProject = this.chosenTeamProject; } catch (Exception ex) { this.DisplayError(this.pickerView, ex); } finally { this.waitNotifier.EndWait(); } return(this.chosenTeamProject); }
/// <summary> /// Sets up a dummy null project that has been picked. /// </summary> /// <returns>The dummy picked project.</returns> protected ITeamProject SetupDummyNoPickedProject() { ITeamProject project = null; Uri uri = null; this.MockTeamProjectPickerPresenter.Setup(picker => picker.ChooseTeamProject()).Returns(project); this.MockTeamProjectPickerPresenter.Setup(picker => picker.ChooseTeamProjectCollection()).Returns(uri); return(project); }
public void InitializeTest() { this.container = new UnityContainer(); TfsTeamProjectCollection collection = IntegrationTestHelper.Tpc; this.container.RegisterInstance <TfsTeamProjectCollection>(collection); this.container.RegisterInstance <ITfsQueryFactory>(new TfsQueryFactory(new WorkItemStore(collection))); this.sut = this.container.Resolve <TeamProject>(new ParameterOverride("projectName", TestHelper.ProjectName).OnType <TeamProject>()); }
/// <summary> /// Handles the <see cref="ILayoutDesignerPresenter.Connect"/> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The event arguments.</param> private void HandleLayoutDesignerPresenterConnect(object sender, EventArgs e) { this.Logger.Log(TraceEventType.Information, "Flow controller HandleLayoutDesignerPresenterConnect called"); ITeamProjectPickerPresenter projectPickerPresenter = this.Manager.ActiveContainer.Resolve <ITeamProjectPickerPresenter>(); ITeamProject teamProject = projectPickerPresenter.ChooseTeamProject(); if (teamProject != null) { projectPickerPresenter.SaveTeamProject(); } }
public void QueryAndLayoutPickerNotInvokedIfTeamProjectDataIsNotObtained() { // Arrange ITeamProject project = this.SetupDummyNoPickedProject(); // Act this.MockRibbonPresenter.Raise(ribbonPresenter => ribbonPresenter.Import += null, EventArgs.Empty); // Assert this.MockWorkItemQueryAndLayoutPickerWizardPresenter.Verify(picker => picker.Start(), Times.Never()); }
public void ChooseTeamProjectReturnsNullIfTheViewReturnsNull() { // Arrange TeamProjectInformation project = null; this.mockPickerView.Setup(picker => picker.ChooseTeamProject()).Returns(project); // Act ITeamProject ans = this.sut.ChooseTeamProject(); // Assert Assert.IsNull(ans, "The call should return null if team project data is null"); this.AssertNoErrrorsDisplayed(); }
public void ChooseTeamProjectSetsTeamProjectDocumentTeamProjectPropertyIfProjectHasBeenChosen() { // Arrange using (ITeamProject mockTeamProject = this.CreateMockTeamProjectFromFactory()) { this.mockPickerView.Setup(picker => picker.ChooseTeamProject()).Returns(mockTeamProject.TeamProjectInformation); // Act ITeamProject ans = this.sut.ChooseTeamProject(); // Assert Assert.AreSame(ans, this.mockDocument.Object.TeamProject, "The team project should be set on the team project document too."); } }
/// <summary> /// Loads project information and validates it. /// </summary> /// <param name="rebindCallback">The callback to be called if the document must be rebound because the collection cannot be found or the id does not match.</param> private void LoadProjectInformation(Func <Uri> rebindCallback) { XDocument projectInformationDoc = this.LoadAndValidateDocument(Constants.ProjectInformationNamespace, ProjectInformationSchema); if (projectInformationDoc != null) { Uri uri = new Uri(projectInformationDoc.Descendants(this.projectXName).Single().Attribute(this.collectionUriXName).Value); string collectionId = projectInformationDoc.Descendants(this.projectXName).Single().Attribute(this.collectionIdXName).Value; string name = projectInformationDoc.Descendants(this.projectXName).Single().Attribute(this.projectNameXName).Value; bool rebound = false; bool done = false; do { this.teamProject = this.factory.CreateTeamProject(uri, name, null); if (this.teamProject.TeamProjectInformation.CollectionId != new Guid(collectionId)) { uri = rebindCallback(); if (uri != null) { rebound = true; } else { done = true; } } else { done = true; } }while (!done); this.queryAndLayoutManager = this.factory.CreateQueryAndLayoutManager(this.teamProject.FieldDefinitions); if (rebound) { this.SaveTeamProject(); } if (uri != null) { this.IsConnected = true; } } else { this.IsConnected = false; } }
public void ChooseTeamProjectCollectionReturnsDataIfTheViewReturnsAProjectCollection() { // Arrange using (ITeamProject mockTeamProject = this.CreateMockTeamProjectFromFactory()) { this.mockPickerView.Setup(picker => picker.ChooseTeamProjectCollection()).Returns(mockTeamProject.TeamProjectInformation.CollectionUri); // Act Uri ans = this.sut.ChooseTeamProjectCollection(); // Assert Assert.AreSame(mockTeamProject.TeamProjectInformation.CollectionUri, ans, "The call should return the Uri that came from the view."); this.AssertNoErrrorsDisplayed(); } }
public void SaveTeamProjectWritesTeamProjectToTheDocument() { // Arrange using (ITeamProject mockTeamProject = this.CreateMockTeamProjectFromFactory()) { this.mockPickerView.Setup(picker => picker.ChooseTeamProject()).Returns(mockTeamProject.TeamProjectInformation); this.sut.ChooseTeamProject(); // Act this.sut.SaveTeamProject(); // Assert this.mockDocument.Verify(document => document.SaveTeamProject(), Times.Once()); this.AssertNoErrrorsDisplayed(); } }
public void Show() { try { if (this.designerDocument == null) { ITeamProject existingConnection = null; if (this.manager.ActiveDocument != null && this.manager.ActiveDocument.IsConnected) { existingConnection = this.manager.ActiveDocument.TeamProject; } this.designerDocument = this.manager.Add(true); this.designerDocument.Close += new EventHandler(this.HandleDesignerDocumentClose); if (existingConnection != null) { this.designerDocument.TeamProject = existingConnection; this.designerDocument.SaveTeamProject(); this.ConnectDesignerDocument(true); } } this.SetEditorControls(); this.SetViewLayoutList(); LayoutInformation layout = this.GetViewOrderedLayoutList().FirstOrDefault(); if (layout != null) { this.ChangeDisplayedLayout(layout); } this.view.ShowLayoutDesigner(); } catch (Exception ex) { this.DisplayError(this.view, ex); } }
/// <summary> /// Creates a mock team project and arranges for the mock factory to return it. /// </summary> /// <returns>The mock team project.</returns> private ITeamProject CreateMockTeamProjectFromFactory() { ITeamProject mockTeamProject = null; ITeamProject tempMockTeamProject = null; try { tempMockTeamProject = TestHelper.CreateMockTeamProject().Object; Uri uri = tempMockTeamProject.TeamProjectInformation.CollectionUri; string projectName = tempMockTeamProject.TeamProjectInformation.ProjectName; this.mockFactory.Setup(factory => factory.CreateTeamProject(uri, projectName, null)).Returns(tempMockTeamProject); mockTeamProject = tempMockTeamProject; tempMockTeamProject = null; } finally { if (tempMockTeamProject != null) { tempMockTeamProject.Dispose(); } } return(mockTeamProject); }
/// <summary> /// Initializes a new instance of the <see cref="WorkItemQueryPickerWizardPagePresenter"/> class. /// </summary> /// <param name="wizardView">The overall wizard view.</param> /// <param name="pageView">The view for this page.</param> /// <param name="teamProject">The team project that supplies the query definitions.</param> public WorkItemQueryPickerWizardPagePresenter(IWorkItemQueryAndLayoutPickerWizardView wizardView, IWorkItemQueryPickerWizardPageView pageView, ITeamProject teamProject) : base(wizardView, pageView) { this.pageView = pageView; this.teamProject = teamProject; }
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(); }