コード例 #1
0
ファイル: TfsWorkItemTests.cs プロジェクト: qanh96/WordToTFS
        private void CreateAdapterForTeamProject()
        {
            _adapter = new Tfs2012SyncAdapter(_testServerConfiguration.TeamProjectCollectionUrl, _testServerConfiguration.TeamProjectName, null, _testServerConfiguration.Configuration);
            var resultOfAdapterOpening = _adapter.Open(new[] { CommonConfiguration.RequirementId, CommonConfiguration.IssueId });

            InvalidateTestIfNotTrue(resultOfAdapterOpening, "Adapter.Open() did not succeed.");
        }
コード例 #2
0
ファイル: TfsWorkItemTests.cs プロジェクト: qanh96/WordToTFS
        public void TfsWorkItem_GetSetMicroDocument_ShouldAttachMicroDocumentAndLoadIt()
        {
            var filename = Path.GetTempPath() + "AIT\\System.Description.docx";
            var dirName  = Path.GetDirectoryName(filename);

            if (dirName == null)
            {
                Assert.Fail("File does not exist.");
            }
            Directory.CreateDirectory(dirName);
            var content = Guid.NewGuid();

            using (var streamWriter = new StreamWriter(File.Open(filename, FileMode.Create)))
            {
                streamWriter.Write(content);
            }

            _issue.Fields["System.Description"].MicroDocument = filename;
            Assert.IsTrue(_issue.IsDirty);
            _adapter.Save();
            Assert.IsTrue(_issue.WorkItem.AttachedFileCount > 0);

            var adapter = new Tfs2012SyncAdapter(_testServerConfiguration.TeamProjectCollectionUrl, _testServerConfiguration.TeamProjectName, null, _testServerConfiguration.Configuration);

            Assert.IsTrue(adapter.Open(new[] { CommonConfiguration.IssueId }));

            var issue = (TfsWorkItem)adapter.WorkItems.Find(CommonConfiguration.IssueId);

            Assert.IsTrue(File.Exists((string)issue.Fields["System.Description"].MicroDocument));

            var actualContent = File.ReadAllLines((string)issue.Fields["System.Description"].MicroDocument);

            Assert.AreEqual(content.ToString(), actualContent[0]);
        }
コード例 #3
0
ファイル: TfsWorkItemTests.cs プロジェクト: qanh96/WordToTFS
        public void TfsWorkItem_SetValueHTML_ShouldAttachHTMLImages()
        {
            var filename = Path.GetTempPath() + "AIT\\image.jpg";
            var dirName  = Path.GetDirectoryName(filename);

            if (dirName == null)
            {
                Assert.Fail("File does not exist.");
            }
            Directory.CreateDirectory(dirName);

            using (var streamWriter = new StreamWriter(File.Open(filename, FileMode.Create)))
            {
                streamWriter.Write("sdfdsf");
            }

            _requirement.WorkItem.Attachments.Clear();
            var html = string.Format(CultureInfo.InvariantCulture, "<html><body><span>FOO <img src=\"{0}\"/> BAR</span></body></html>", filename);

            _requirement.Fields[_testServerConfiguration.HtmlFieldReferenceName].Value = html;
            Assert.IsTrue(_requirement.IsDirty);
            Assert.AreEqual(0, _adapter.Save().Count);

            var adapter = new Tfs2012SyncAdapter(_testServerConfiguration.TeamProjectCollectionUrl, _testServerConfiguration.TeamProjectName, null, _testServerConfiguration.Configuration);

            Assert.IsTrue(adapter.Open(new[] { CommonConfiguration.RequirementId }));
            var requirement = (TfsWorkItem)adapter.WorkItems.Find(CommonConfiguration.RequirementId);

            Assert.IsTrue(requirement.Fields[_testServerConfiguration.HtmlFieldReferenceName].Value.Contains("FOO"));
            Assert.IsTrue(requirement.Fields[_testServerConfiguration.HtmlFieldReferenceName].Value.Contains("BAR"));

            Assert.AreEqual(1, requirement.WorkItem.AttachedFileCount);
        }
コード例 #4
0
        public void IntegrationTest_PublishOfWorkItemWithUnclosedList_ShouldNotBePublished()
        {
            var systemVariableMock = new Mock <ISystemVariableService>();

            _ignoreFailOnUserInforation = true;

            var serverConfig = CommonConfiguration.TfsTestServerConfiguration(_testContext);

            serverConfig.Configuration.IgnoreFormatting = false;
            var requirementConf = serverConfig.Configuration.GetWorkItemConfiguration("Requirement");

            // import an workitems to use the structure as example for the new workitem
            var importItems = GetTfsWorkItems(new[] { serverConfig.HtmlRequirementId }, serverConfig).ToList();

            Refresh(serverConfig, importItems);

            //Add Bullet points to the table.
            _document.Tables[1].Cell(3, 1).Range.ListFormat.ApplyBulletDefault();
            var bulletItems = new[] { "One", "Two", "Three" };

            for (int i = 0; i < bulletItems.Length; i++)
            {
                string bulletItem = bulletItems[i];
                if (i < bulletItems.Length - 1)
                {
                    bulletItem = bulletItem + "\n";
                }
                _document.Tables[1].Cell(3, 1).Range.InsertBefore(bulletItem);
            }

            //delete the id
            _document.Tables[1].Cell(2, 3).Range.Text = string.Empty;
            _document.Tables[1].Cell(2, 1).Range.Text = "TestTitle";

            var createdWorkItem = new WordTableWorkItem(_document.Tables[1], "Requirement", serverConfig.Configuration, requirementConf);

            // publish
            var publishWorkItems = new List <IWorkItem>();

            publishWorkItems.Add(createdWorkItem);

            var configuration = serverConfig.Configuration;
            var tfsAdapter    = new Tfs2012SyncAdapter(serverConfig.TeamProjectCollectionUrl, serverConfig.TeamProjectName, null, configuration);
            var wordAdapter   = new Word2007TableSyncAdapter(_document, configuration);

            var syncService = new WorkItemSyncService(systemVariableMock.Object);

            syncService.Publish(wordAdapter, tfsAdapter, publishWorkItems, false, configuration);

            //Get the information storage
            var informationStorage = SyncServiceFactory.GetService <IInfoStorageService>();
            var error = informationStorage.UserInformation.FirstOrDefault(x => x.Type == UserInformationType.Error);

            //Test that an error was thrown
            Assert.IsNotNull(error);

            //Clear the information storage
            informationStorage.UserInformation.Clear();
        }
コード例 #5
0
        /// <summary>
        /// Helper method to get work items from tfs
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="serverConfiguration"></param>
        /// <returns></returns>
        private IEnumerable <IWorkItem> GetTfsWorkItems(int[] ids, ServerConfiguration serverConfiguration)
        {
            var configuration = serverConfiguration.Configuration;
            var tfsAdapter    = new Tfs2012SyncAdapter(serverConfiguration.TeamProjectCollectionUrl, serverConfiguration.TeamProjectName, null, configuration);

            tfsAdapter.Open(ids);
            return(tfsAdapter.WorkItems);
        }
コード例 #6
0
        /// <summary>
        /// Helper method to refresh information
        /// </summary>
        /// <param name="serverConfiguration"></param>
        /// <param name="workItems"></param>
        private void Refresh(ServerConfiguration serverConfiguration, IEnumerable <IWorkItem> workItems)
        {
            var systemVariableMock = new Mock <ISystemVariableService>();
            var configuration      = serverConfiguration.Configuration;
            var tfsAdapter         = new Tfs2012SyncAdapter(serverConfiguration.TeamProjectCollectionUrl, serverConfiguration.TeamProjectName, null, configuration);
            var wordAdapter        = new Word2007TableSyncAdapter(_document, configuration);

            var syncService = new WorkItemSyncService(systemVariableMock.Object);

            syncService.Refresh(tfsAdapter, wordAdapter, workItems, configuration);
            FailOnUserInformation();
        }
コード例 #7
0
ファイル: TfsWorkItemTests.cs プロジェクト: qanh96/WordToTFS
        public void TfsWorkItem_ChangePlainTextField_ShouldBeSaved()
        {
            _requirement.Fields["Microsoft.VSTS.Common.Triage"].Value = "Triaged";
            _adapter.Save();

            _requirement.Fields["Microsoft.VSTS.Common.Triage"].Value = "Pending";
            Assert.AreEqual("Pending", _requirement.Fields["Microsoft.VSTS.Common.Triage"].Value);
            _adapter.Save();

            var adapter = new Tfs2012SyncAdapter(_testServerConfiguration.TeamProjectCollectionUrl, _testServerConfiguration.TeamProjectName, null, _testServerConfiguration.Configuration);

            Assert.IsTrue(adapter.Open(new[] { CommonConfiguration.RequirementId }));
            var requirement = (TfsWorkItem)adapter.WorkItems.Find(CommonConfiguration.RequirementId);

            Assert.AreEqual("Pending", requirement.Fields["Microsoft.VSTS.Common.Triage"].Value);
        }
コード例 #8
0
        /// <summary>
        /// Get all work item ids for a given query name
        /// </summary>
        /// <param name="query"></param>
        /// <returns>ids of workitems</returns>
        private List <int> GetWorkItemsIdsByQueryName(string query)
        {
            ConsoleExtensionLogging.LogMessage(Resources.GetWorkItemsByQueryName + query, ConsoleExtensionLogging.LogLevel.Both);
            SyncServiceTrace.D(Resources.GetWorkItemsByQueryName + query);
            var queryconfig = new QueryConfiguration
            {
                QueryPath    = query,
                ImportOption = QueryImportOption.SavedQuery
            };
            var adapter        = new Tfs2012SyncAdapter(_documentModel.TfsServer, _documentModel.TfsProject, queryconfig, _documentModel.Configuration);
            var intIDs         = new List <int>();
            var queryWorkItems = adapter.LoadWorkItemsFromSavedQuery(queryconfig);

            foreach (var queryWorkItem in queryWorkItems)
            {
                intIDs.Add(queryWorkItem.Id);
            }

            return(intIDs);
        }
コード例 #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TfsWorkItem"/> class.
        /// </summary>
        /// <param name="workItem">The TFS work item to be wrapped</param>
        /// <param name="tfsAdapter">TFS adapter.</param>
        /// <param name="lookupFields">When this is set, the work item is only used to look up field values for link expansion.</param>
        /// <param name="configuration">Configuration of the  </param>
        internal TfsWorkItem(WorkItem workItem, Tfs2012SyncAdapter tfsAdapter, IEnumerable <string> lookupFields, IConfigurationItem configuration)
        {
            if (workItem == null)
            {
                throw new ArgumentNullException("workItem");
            }
            if (tfsAdapter == null)
            {
                throw new ArgumentNullException("tfsAdapter");
            }
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            WorkItem       = workItem;
            TfsAdapter     = tfsAdapter;
            _lookupFields  = lookupFields;
            _configuration = configuration;
        }