[Test] //ExSkip public void GlossaryDocument() { Document doc = new Document(); GlossaryDocument glossaryDoc = new GlossaryDocument(); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 1" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 2" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 3" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 4" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 5" }); Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count); doc.GlossaryDocument = glossaryDoc; // There is a different ways how to get created building blocks Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name); Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name); Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name); Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name); // Get a block by gallery, category and name BuildingBlock block4 = glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4"); // All GUIDs are the same by default Assert.AreEqual("00000000-0000-0000-0000-000000000000", block4.Guid.ToString()); // To be able to uniquely identify blocks by GUID, each GUID must be unique // We will do that using a custom visitor GlossaryDocVisitor visitor = new GlossaryDocVisitor(); glossaryDoc.Accept(visitor); Assert.AreEqual(5, visitor.GetDictionary().Count); Console.WriteLine(visitor.GetText()); // We can find our new blocks in Microsoft Word via Insert > Quick Parts > Building Blocks Organizer... doc.Save(MyDir + @"\Artifacts\BuildingBlocks.GlossaryDocument.dotx"); }
[Test] //ExSkip public void GlossaryDocument() { Document doc = new Document(); GlossaryDocument glossaryDoc = new GlossaryDocument(); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 1" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 2" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 3" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 4" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 5" }); Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count); doc.GlossaryDocument = glossaryDoc; // There are various ways of accessing building blocks. // 1 - Get the first/last building blocks in the collection: Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name); Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name); // 2 - Get a building block by index: Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name); Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name); // 3 - Get the first building block that matches a gallery, name and category: Assert.AreEqual("Block 4", glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4").Name); // We will do that using a custom visitor, // which will give every BuildingBlock in the GlossaryDocument a unique GUID GlossaryDocVisitor visitor = new GlossaryDocVisitor(); glossaryDoc.Accept(visitor); Assert.AreEqual(5, visitor.GetDictionary().Count); //ExSkip Console.WriteLine(visitor.GetText()); // When we open this document using Microsoft Word, // we can find the building blocks via Insert -> Quick Parts -> Building Blocks Organizer. doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx"); }
[Test] //ExSkip public void GlossaryDocument() { Document doc = new Document(); GlossaryDocument glossaryDoc = new GlossaryDocument(); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 1" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 2" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 3" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 4" }); glossaryDoc.AppendChild(new BuildingBlock(glossaryDoc) { Name = "Block 5" }); Assert.AreEqual(5, glossaryDoc.BuildingBlocks.Count); doc.GlossaryDocument = glossaryDoc; // There is a different ways how to get created building blocks Assert.AreEqual("Block 1", glossaryDoc.FirstBuildingBlock.Name); Assert.AreEqual("Block 2", glossaryDoc.BuildingBlocks[1].Name); Assert.AreEqual("Block 3", glossaryDoc.BuildingBlocks.ToArray()[2].Name); Assert.AreEqual("Block 4", glossaryDoc.GetBuildingBlock(BuildingBlockGallery.All, "(Empty Category)", "Block 4").Name); Assert.AreEqual("Block 5", glossaryDoc.LastBuildingBlock.Name); // We will do that using a custom visitor, which also will give every BuildingBlock in the GlossaryDocument a unique GUID GlossaryDocVisitor visitor = new GlossaryDocVisitor(); glossaryDoc.Accept(visitor); Assert.AreEqual(5, visitor.GetDictionary().Count); //ExSkip Console.WriteLine(visitor.GetText()); // We can find our new blocks in Microsoft Word via Insert > Quick Parts > Building Blocks Organizer... doc.Save(ArtifactsDir + "BuildingBlocks.GlossaryDocument.dotx"); }