/// <summary>
 /// Load work item from Word adapter
 /// </summary>
 private void LoadWordItem()
 {
     if (_wordAdapter.Open(null) == false)
     {
         return;
     }
     WordItem = _wordAdapter.WorkItems.Find(Id);
 }
        public void SynchronizedWorkItemViewModel_SynchronizationState_ShouldBeNew()
        {
            var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title");

            OpenAdapters(CommonConfiguration.TfsTestServerConfiguration(_testContext), config);
            _wordAdapter.CreateNewWorkItem(config.GetConfigurationItems().First());
            _wordAdapter.WorkItems.First().Fields["System.Title"].Value = "Was anderes";
            _wordAdapter = new Word2007TableSyncAdapter(_document, config);
            _wordAdapter.Open(null);

            _synchronizedWorkItemViewModel = new SynchronizedWorkItemViewModel(null, _wordAdapter.WorkItems.First(), _wordAdapter, _documentModel.Object, null);
            _synchronizedWorkItemViewModel.Refresh();
            Assert.AreEqual(SynchronizationState.New, _synchronizedWorkItemViewModel.SynchronizationState);
        }
        private void OpenAdapters(ServerConfiguration serverConfig, IConfiguration configuration)
        {
            _tfsAdapter = new Tfs2012SyncAdapter(serverConfig.TeamProjectCollectionUrl, serverConfig.TeamProjectName, null, configuration);
            _tfsAdapter.Open(new[]
            {
                serverConfig.SynchronizedWorkItemId
            });

            _documentModel = new Mock <ISyncServiceDocumentModel>();
            _documentModel.SetupGet(x => x.Configuration).Returns(configuration);
            _documentModel.SetupGet(x => x.TfsProject).Returns(serverConfig.TeamProjectName);
            _documentModel.SetupGet(x => x.TfsServer).Returns(serverConfig.TeamProjectCollectionUrl);

            _wordAdapter = new Word2007TableSyncAdapter(_document, configuration);
            _wordAdapter.Open(null);
        }
        public void SynchronizedWorkItemViewModel_SynchronizationState_ShouldBeDivergedWithConflicts()
        {
            var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title");

            config.GetConfigurationItems().First().FieldConfigurations.Add(new ConfigurationFieldItem("System.AreaPath", "", FieldValueType.PlainText, Direction.OtherToTfs, 5, 1, "", false, HandleAsDocumentType.OleOnDemand, null, null, null, ShapeOnlyWorkaroundMode.AddSpace, null, null, null));

            OpenAdapters(CommonConfiguration.TfsTestServerConfiguration(_testContext), config);
            var tfsItem   = _tfsAdapter.WorkItems.First();
            var oldFields = tfsItem.GetWorkItemByRevision(tfsItem.Revision - 1);

            Assert.AreNotEqual(tfsItem.Fields["System.AreaPath"].Value, oldFields["System.AreaPath"].Value);

            _wordAdapter.CreateNewWorkItem(config.GetConfigurationItems().First());
            _wordAdapter.WorkItems.First().Fields["System.Title"].Value    = "Test";
            _wordAdapter.WorkItems.First().Fields["System.Id"].Value       = oldFields["System.Id"].Value;
            _wordAdapter.WorkItems.First().Fields["System.Rev"].Value      = oldFields["System.Rev"].Value;
            _wordAdapter.WorkItems.First().Fields["System.AreaPath"].Value = oldFields["System.AreaPath"].Value;
            _wordAdapter = new Word2007TableSyncAdapter(_document, config);
            _wordAdapter.Open(null);

            _synchronizedWorkItemViewModel = new SynchronizedWorkItemViewModel(_tfsAdapter.WorkItems.First(), null, _wordAdapter, _documentModel.Object, null);
            _synchronizedWorkItemViewModel.Refresh();
            Assert.AreEqual(SynchronizationState.DivergedWithConflicts, _synchronizedWorkItemViewModel.SynchronizationState);
        }
        public void SynchronizedWorkItemViewModel_SynchronizationState_ShouldBeUpToDate_WithStackRankSetToTrue()
        {
            var config = CommonConfiguration.GetSimpleFieldConfiguration("Requirement", Direction.OtherToTfs, FieldValueType.PlainText, "System.Title");

            OpenAdapters(CommonConfiguration.TfsTestServerConfiguration(_testContext), config);
            config.UseStackRank = true;

            //add the stack rank configuration and a value
            _tfsAdapter.WorkItems.First().Configuration.FieldConfigurations.Add(new ConfigurationFieldItem("Microsoft.VSTS.Common.StackRank", string.Empty, FieldValueType.PlainText, Direction.OtherToTfs, 0, 0, string.Empty, false, HandleAsDocumentType.All, null, string.Empty, null, ShapeOnlyWorkaroundMode.AddSpace, false, null, null, null));
            _tfsAdapter.WorkItems.First().Fields["Microsoft.VSTS.Common.StackRank"].Value = "3000";

            _wordAdapter.CreateNewWorkItem(config.GetConfigurationItems().First());
            _wordAdapter.WorkItems.First().Fields["System.Title"].Value = _tfsAdapter.WorkItems.First().Fields["System.Title"].Value;
            _wordAdapter.WorkItems.First().Fields["System.Id"].Value = _tfsAdapter.WorkItems.First().Fields["System.Id"].Value;
            _wordAdapter.WorkItems.First().Fields["System.Rev"].Value = _tfsAdapter.WorkItems.First().Fields["System.Rev"].Value;
            _wordAdapter.WorkItems.First().Configuration.FieldConfigurations.Add(new ConfigurationFieldItem("Microsoft.VSTS.Common.StackRank", string.Empty, FieldValueType.PlainText, Direction.OtherToTfs, 0, 0, string.Empty, false, HandleAsDocumentType.All, null, string.Empty, null, ShapeOnlyWorkaroundMode.AddSpace, false, null, null, null));

            _wordAdapter = new Word2007TableSyncAdapter(_document, config);
            _wordAdapter.Open(null);

            _synchronizedWorkItemViewModel = new SynchronizedWorkItemViewModel(_tfsAdapter.WorkItems.First(), null, _wordAdapter, _documentModel.Object, null);
            _synchronizedWorkItemViewModel.Refresh();
            Assert.AreEqual(SynchronizationState.UpToDate, _synchronizedWorkItemViewModel.SynchronizationState);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Background method to import the work items from TFS.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="RunWorkerCompletedEventArgs"/> that contains the event data</param>
        private void DoImport(object sender, DoWorkEventArgs e)
        {
            SyncServiceTrace.I(Resources.ImportWorkItems);

            if (_workItemSyncService == null || _configService == null)
            {
                SyncServiceTrace.D(Resources.ServicesNotExists);
                throw new Exception(Resources.ServicesNotExists);
            }

            _documentModel.Save();

            _destination.ProcessOperations(_configuration.PreOperations);
            var importWorkItems = (from wim in FoundWorkItems

                                   select wim.Item).ToList();

            SyncServiceTrace.D(Resources.NumberOfFoundWorkItems + FoundWorkItems.Count);

            // display progress dialog
            var progressService = SyncServiceFactory.GetService <IProgressService>();

            progressService.ShowProgress();
            progressService.NewProgress(Resources.GetWorkItems_Title);

            // search for already existing work items in word and ask whether to overide them
            if (!(_source.Open(importWorkItems.Select(x => x.TfsItem.Id).ToArray()) && _destination.Open(null)))
            {
                return;
            }
            if (importWorkItems.Select(x => x.TfsItem.Id).Intersect(_destination.WorkItems.Select(x => x.Id)).Any())
            {
            }
            if (!_testSpecByQuery)
            {
                _workItemSyncService.Refresh(_source, _destination, importWorkItems.Select(x => x.TfsItem), _configuration);
            }

            if (_testSpecByQuery)
            {
                var testAdapter       = SyncServiceFactory.CreateTfsTestAdapter(_documentModel.TfsServer, _documentModel.TfsProject, _documentModel.Configuration);
                var model             = new TestSpecificationReportByQueryModel(_tfsService, _documentModel, testAdapter, _workItems);
                var expandSharedsteps = _configuration.ConfigurationTest.ExpandSharedSteps;
                var testCases         = model.GetTestCasesFromWorkItems(importWorkItems, expandSharedsteps);
                var sharedSteps       = model.GetSharedStepsFromWorkItems(importWorkItems);
                // Get any pre and post operations for the reports
                var preOperations    = _configuration.ConfigurationTest.GetPreOperationsForTestSpecification();
                var postOperations   = _configuration.ConfigurationTest.GetPostOperationsForTestSpecification();
                var testReport       = SyncServiceFactory.CreateWord2007TestReportAdapter(_wordDocument, _configuration);
                var testReportHelper = new TestReportHelper(testAdapter, testReport, _configuration, () => !IsImporting);

                testReportHelper.ProcessOperations(preOperations);
                if (sharedSteps.Count > 0)
                {
                    _workItemSyncService.RefreshAndSubstituteSharedStepItems(_source, _destination, importWorkItems.Select(x => x.TfsItem), _configuration, testReportHelper, sharedSteps);
                }
                if (testCases.Count > 0)
                {
                    _workItemSyncService.RefreshAndSubstituteTestItems(_source, _destination, importWorkItems.Select(x => x.TfsItem), _configuration, testReportHelper, testCases);
                }
                if (_testReportingProgressCancellationService.CheckIfContinue())
                {
                    testReportHelper.CreateSummaryPage(_wordDocument, null);
                    testReportHelper.ProcessOperations(postOperations);
                }
                else
                {
                    SyncServiceTrace.I(Resources.DoImportError);
                }

                _documentModel.TestReportGenerated = true;
            }

            _destination.ProcessOperations(_configuration.PostOperations);
        }