public void WordTableWorkItem_GetLinks_ShouldParseEmptyCellContent()
        {
            _testDocument.Tables[1].Cell(2, 2).Range.Text = string.Empty;
            var target = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.Configuration, CommonConfiguration.Configuration.GetWorkItemConfiguration("Requirement"));

            Assert.AreEqual(0, target.Links[target.Links.Keys.First(x => x.LinkValueType == "Child")].Length);
        }
        public void WordTableWorkItem_GetIsNew_ShouldReturnTrueForWorkItemWithoutId()
        {
            _testDocument.Tables[1].Cell(2, 3).Range.Text = string.Empty;
            var target2 = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.Configuration, CommonConfiguration.Configuration.GetWorkItemConfiguration("Requirement"));

            Assert.IsTrue(target2.IsNew);
        }
Beispiel #3
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();
        }
        public void WordTableWorkItem_AddLinks_ShouldReplaceLinksIfOverwriteIsFalse()
        {
            var target      = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.Configuration, CommonConfiguration.Configuration.GetWorkItemConfiguration("Requirement"));
            var fakeAdapter = new Word2007TableSyncAdapter(_testDocument, CommonConfiguration.Configuration);

            fakeAdapter.Open(null);
            target.AddLinks(fakeAdapter, new[] { 4, 5 }, "Child", false);
            Assert.IsTrue(_testDocument.Tables[1].Cell(2, 2).Range.Text.StartsWith("4,5", StringComparison.OrdinalIgnoreCase));
        }
        [Ignore] // ALD: Configuration Variables no longer work.
        public void StaticValueField_AddValue_StaticValueFieldShouldContainBookmark()
        {
            var target = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.ConfigurationWithVariables, CommonConfiguration.ConfigurationWithVariables.GetWorkItemConfiguration("Requirement"));

            Assert.IsNotNull(target);
            //The Value of the field that contains the static value field should equal the text from the variable
            Assert.AreEqual(_testDocument.Tables[1].Cell(8, 1).Range.Bookmarks.Count, 1);
            Assert.AreEqual(_testDocument.Tables[1].Cell(8, 1).Range.Bookmarks[1].Name, CommonConfiguration.StaticValueTextBookMarkName);
            Assert.AreNotEqual(_testDocument.Tables[1].Cell(8, 1).Range.Bookmarks[1].Name, CommonConfiguration.BookmarkName);
        }
        public void WordTableWorkItem_AddBookmarks_DocumentAndRequirementShouldContainBookmark()
        {
            var target      = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.Configuration, CommonConfiguration.Configuration.GetWorkItemConfiguration("Requirement"));
            var fakeAdapter = new Word2007TableSyncAdapter(_testDocument, CommonConfiguration.Configuration);

            fakeAdapter.Open(null);

            Assert.IsNotNull(target);
            //Desription should contain a Bookmark
            Assert.AreEqual(_testDocument.Tables[1].Cell(3, 1).Range.Bookmarks.Count, 1);
            Assert.AreEqual(_testDocument.Tables[1].Cell(3, 1).Range.Bookmarks[1].Name, CommonConfiguration.BookmarkName);

            //Title should not contain a Bookmark
            Assert.AreNotEqual(_testDocument.Tables[1].Cell(2, 1).Range.Bookmarks.Count, 1);

            //The First Bookmark in the document should be the one from the configuration
            Assert.AreEqual(_testDocument.Bookmarks[1].Name, CommonConfiguration.BookmarkName);

            //The Value of the the Bookmarkshould be the value of the Description
            Assert.IsTrue(_testDocument.Tables[1].Cell(3, 1).Range.Text.Contains(_testDocument.Bookmarks[1].Range.Text));
        }
        public void WordTableWorkItem_GetRevision_ShouldReturnValueOfRevisionField()
        {
            var target = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.Configuration, CommonConfiguration.Configuration.GetWorkItemConfiguration("Requirement"));

            Assert.AreEqual(4, target.GetFieldRevision("System.Rev"));
        }
        public void WordTableWorkItem_GetIsNew_ShouldReturnFalseForWorkItemWithId()
        {
            var target = new WordTableWorkItem(_testDocument.Tables[1], "Requirement", CommonConfiguration.Configuration, CommonConfiguration.Configuration.GetWorkItemConfiguration("Requirement"));

            Assert.IsFalse(target.IsNew);
        }
        /// <summary>
        /// Creates a new <see cref="IWorkItem"/> object in this document.
        /// </summary>
        /// <param name="configuration">The configuration of the work item to create</param>
        /// <returns>The new <see cref="IWorkItem"/> object or null if the adapter failed to create work item.</returns>
        public IWorkItem CreateNewWorkItem(IConfigurationItem configuration)
        {
            Guard.ThrowOnArgumentNull(configuration, "configuration");

            SyncServiceTrace.D(Resources.CreateWorkItemBasedOnTemplate + configuration.RelatedTemplateFile);
            SyncServiceTrace.D("Assembly is " + Assembly.GetExecutingAssembly().Location);

            if (!File.Exists(configuration.RelatedTemplateFile))
            {
                SyncServiceTrace.E(Resources.LogService_Export_NoFile);
                return(null);
            }

            // Check if cursor is not in table, add new paragraph
            var selection = Document.ActiveWindow.Selection;

            if (selection == null)
            {
                SyncServiceTrace.E(Resources.SelectionNotExists);
                return(null);
            }

            if (WordSyncHelper.IsCursorBehindTable(selection))
            {
                selection.TypeParagraph();
            }

            if (WordSyncHelper.IsCursorInTable(selection))
            {
                return(null);
            }

            // insert template. Selection is collapsed to end when inserting,
            // so note old start to get range where file is inserted
            var fullPath = Path.GetFullPath(configuration.RelatedTemplateFile);

            SyncServiceTrace.D(Resources.FullPathOfTemplateFile + fullPath);
            var oldStart = selection.Start;

            if (!File.Exists(fullPath))
            {
                SyncServiceTrace.E(Resources.LogService_Export_NoFile);
                return(null);
            }


            selection.InsertFile(fullPath, ConfirmConversions: false);

            Range tableRange = Document.Range(oldStart, selection.End);

            Table table = tableRange.Tables.Cast <Table>().FirstOrDefault();

            if (table == null)
            {
                SyncServiceTrace.E(Resources.LogService_Export_NoTable);
            }
            else
            {
                // Add table marker if none is defined
                var tableRange2 = WordSyncHelper.GetCellRange(table, configuration.ReqTableCellRow, configuration.ReqTableCellCol);
                if (tableRange2 != null)
                {
                    if (tableRange2.Text.Replace("\r\a", string.Empty).Length == 0)
                    {
                        tableRange2.Text = configuration.WorkItemType + "\r\a";
                    }
                }

                var newItem = new WordTableWorkItem(table, configuration.WorkItemType, Configuration, configuration);
                WorkItems.Add(newItem);
                return(newItem);
            }

            return(null);
        }