예제 #1
0
        public void TestDiscoverRealCommentsWithLookupTable()
        {
            PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
            pca.AddAuthor(0, "Mena Shervill", 1);
            pca.AddAuthor(1, "bobh", 2);

            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_comment1.xml", FileMode.Open))
            {
                StateMachineBasedXmlFilter smbxf = new StateMachineBasedXmlFilter(new CommonNamespaces(OpenXmlFormat.Transitional));
                smbxf.ConnectToInputStream(from);

                smbxf.AddNodesToTriggerList(PptxMetadataDefinitions.SlideComment(pca.AuthorByIDLookupDict));

                DocumentText dt = smbxf.DocumentText;
                smbxf.Execute();

                Assert.AreEqual(1, dt.GetTextTypes(ContentType.Comment).Count, "expected to get a comment text type created");
                IAbstractTextType ttContent = dt.GetTextTypes(ContentType.Comment)[0];

                Assert.IsNotNull(ttContent, "Missing Content Text Type");
                Assert.AreEqual(3, ttContent.GetChildCount(), "we expected to get 3 items of comment text");

                Assert.AreEqual("hjrehjkwr", ttContent.GetChild(0).GetInfo("Content")[0].value);
                Assert.AreEqual("Another comment", ttContent.GetChild(1).GetInfo("Content")[0].value);
                Assert.AreEqual("For use as no doubt", ttContent.GetChild(2).GetInfo("Content")[0].value);

                Assert.AreEqual("Mena Shervill", ttContent.GetChild(0).GetInfo("Author")[0].value);
                Assert.AreEqual("bobh", ttContent.GetChild(1).GetInfo("Author")[0].value);
                Assert.AreEqual("bobh", ttContent.GetChild(2).GetInfo("Author")[0].value);
            }
        }
예제 #2
0
        public void TestAddAuthor()
        {
            PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
            pca.AddAuthor(0, "Author 1", 4);
            Assert.AreEqual(1, pca.NumberOfKnownAuthors);
            Assert.AreEqual("Author 1", pca.GetAuthorNameForIdx(0));
            Assert.AreEqual(4, pca.GetMaxCommentIndexUsedForAuthorIdx(0));

            pca.AddAuthor(1, "Author 2", 1);
            Assert.AreEqual(2, pca.NumberOfKnownAuthors);
            Assert.AreEqual("Author 2", pca.GetAuthorNameForIdx(1));
            Assert.AreEqual(1, pca.GetMaxCommentIndexUsedForAuthorIdx(1));
            Assert.AreEqual("Author 1", pca.GetAuthorNameForIdx(0));
            Assert.AreEqual(4, pca.GetMaxCommentIndexUsedForAuthorIdx(0));
        }
예제 #3
0
 public void TestAddAuthorsInRandomOrder()
 {
     PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
     pca.AddAuthor(0, "Author A", 4);
     pca.AddAuthor(5, "Author B", 1);
     pca.AddAuthor(4, "Author C", 1);
     Assert.AreEqual(3, pca.NumberOfKnownAuthors);
     Assert.AreEqual("Author A", pca.GetAuthorNameForIdx(0));
     Assert.AreEqual("Author C", pca.GetAuthorNameForIdx(4));
     Assert.AreEqual("Author B", pca.GetAuthorNameForIdx(5));
     int iMissedThrows = 0;
     try
     {
         pca.GetAuthorNameForIdx(-1);
         ++iMissedThrows;
     }
     catch
     {
     }
     try
     {
         pca.GetAuthorNameForIdx(1);
         ++iMissedThrows;
     }
     catch
     {
     }
     try
     {
         pca.GetAuthorNameForIdx(2);
         ++iMissedThrows;
     }
     catch
     {
     }
     try
     {
         pca.GetAuthorNameForIdx(3);
         ++iMissedThrows;
     }
     catch
     {
     }
     Assert.AreEqual(0, iMissedThrows,"Not all exceptional cases threw");
 }
예제 #4
0
 public void TestResettingKnownAuthorIsOK()
 {
     PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
     pca.AddAuthor(2, "Same Author", 4);
     Assert.AreEqual(4, pca.GetMaxCommentIndexUsedForAuthorIdx(2));
     pca.AddAuthor(2, "Same Author", 1);
     Assert.AreEqual(4, pca.GetMaxCommentIndexUsedForAuthorIdx(2));
     pca.AddAuthor(2, "Same Author", 7);
     Assert.AreEqual(7, pca.GetMaxCommentIndexUsedForAuthorIdx(2));
 }
예제 #5
0
 public void TestConstruction()
 {
     PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
     Assert.AreEqual(0, pca.NumberOfKnownAuthors);
 }
예제 #6
0
        public void TestAuthorByIDLookupDict()
        {
            PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
            pca.AddAuthor(0, "Author A", 4);
            pca.AddAuthor(5, "Author B", 1);
            pca.AddAuthor(4, "Author C", 1);
            Dictionary<string, string> abild = pca.AuthorByIDLookupDict;
            Assert.AreEqual(3, abild.Count, "Should just have the 3 know nauthors");

            Assert.AreEqual("Author A", abild["0"]);
            Assert.AreEqual("Author C", abild["4"]);
            Assert.AreEqual("Author B", abild["5"]);
        }
예제 #7
0
        public void TestLoadFromStream()
        {
            using (Stream from = File.Open(TESTFILE_DIR + "Ppt_commentAuthors.xml", FileMode.Open))
            {
                PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
                pca.ConnectToInputStream(from);
                pca.Execute();

                Assert.AreEqual(2, pca.NumberOfKnownAuthors);
                Assert.AreEqual("Mena Shervill", pca.GetAuthorNameForIdx(0));
                Assert.AreEqual(1, pca.GetMaxCommentIndexUsedForAuthorIdx(0));
                Assert.AreEqual("bobh", pca.GetAuthorNameForIdx(1));
                Assert.AreEqual(2, pca.GetMaxCommentIndexUsedForAuthorIdx(1));
            }
        }
예제 #8
0
 public void TestReuseAuthorFails()
 {
     PptxCommentAuthors pca = new PptxCommentAuthors(new DocumentText(), new CommonNamespaces(OpenXmlFormat.Transitional));
     pca.AddAuthor(1, "Author First", 4);
     pca.AddAuthor(1, "Author Different", 4);
 }