Ejemplo n.º 1
0
        //[InlineData("")]
        //[InlineData("")]
        //[InlineData("")]

        public void CA003_ContentAtoms_Throws(string name)
        {
            FileInfo sourceDocx             = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name));
            var      thisGuid               = Guid.NewGuid().ToString().Replace("-", "");
            var      sourceCopiedToDestDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", string.Format("-{0}-1-Source.docx", thisGuid))));

            if (!sourceCopiedToDestDocx.Exists)
            {
                File.Copy(sourceDocx.FullName, sourceCopiedToDestDocx.FullName);
            }

            var coalescedDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", string.Format("-{0}-2-Coalesced.docx", thisGuid))));

            if (!coalescedDocx.Exists)
            {
                File.Copy(sourceDocx.FullName, coalescedDocx.FullName);
            }

            var contentAtomDataFi = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", string.Format("-{0}-3-ContentAtomData.txt", thisGuid))));

            using (WordprocessingDocument wDoc = WordprocessingDocument.Open(coalescedDocx.FullName, true))
            {
                Assert.Throws <NotSupportedException>(() =>
                {
                    var contentParent = wDoc.MainDocumentPart.GetXDocument().Root.Element(W.body);
                    var settings      = new WmlComparerSettings();
                    WmlComparer.CreateComparisonUnitAtomList(wDoc.MainDocumentPart, contentParent, settings);
                });
            }
        }
Ejemplo n.º 2
0
        public void CA002_Annotations(string name)
        {
            FileInfo sourceDocx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name));

#if COPY_FILES_FOR_DEBUGGING
            var sourceCopiedToDestDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", "-1-Source.docx")));
            if (!sourceCopiedToDestDocx.Exists)
            {
                File.Copy(sourceDocx.FullName, sourceCopiedToDestDocx.FullName);
            }

            var annotatedDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", "-2-Annotated.docx")));
            if (!annotatedDocx.Exists)
            {
                File.Copy(sourceDocx.FullName, annotatedDocx.FullName);
            }

            using (WordprocessingDocument wDoc = WordprocessingDocument.Open(annotatedDocx.FullName, true))
            {
                var contentParent = wDoc.MainDocumentPart.GetXDocument().Root.Element(W.body);
                var settings      = new WmlComparerSettings();
                WmlComparer.CreateComparisonUnitAtomList(wDoc.MainDocumentPart, contentParent, settings);
            }
#endif
        }
        //[InlineData("", 0)]
        //[InlineData("", 0)]
        //[InlineData("", 0)]
        //[InlineData("", 0)]

        public void CA001_ContentAtoms(string name, int contentAtomCount)
        {
            FileInfo sourceDocx = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, name));

            var thisGuid = Guid.NewGuid().ToString().Replace("-", "");
            var sourceCopiedToDestDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", string.Format("-{0}-1-Source.docx", thisGuid))));

            if (!sourceCopiedToDestDocx.Exists)
            {
                File.Copy(sourceDocx.FullName, sourceCopiedToDestDocx.FullName);
            }

            var coalescedDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", string.Format("-{0}-2-Coalesced.docx", thisGuid))));

            if (!coalescedDocx.Exists)
            {
                File.Copy(sourceDocx.FullName, coalescedDocx.FullName);
            }

            var contentAtomDataFi = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, sourceDocx.Name.Replace(".docx", string.Format("-{0}-3-ContentAtomData.txt", thisGuid))));

            using (WordprocessingDocument wDoc = WordprocessingDocument.Open(coalescedDocx.FullName, true))
            {
                var contentParent = wDoc.MainDocumentPart.GetXDocument().Root.Element(W.body);
                var settings      = new WmlComparerSettings();
                ComparisonUnitAtom[] contentAtomList = WmlComparer.CreateComparisonUnitAtomList(wDoc.MainDocumentPart, contentParent, settings);
                StringBuilder        sb = new StringBuilder();
                var part = wDoc.MainDocumentPart;

                sb.AppendFormat("Part: {0}", part.Uri.ToString());
                sb.Append(Environment.NewLine);
                sb.Append(ComparisonUnit.ComparisonUnitListToString(contentAtomList.ToArray()) + Environment.NewLine);
                sb.Append(Environment.NewLine);

                XDocument newMainXDoc = WmlComparer.Coalesce(contentAtomList);
                var       partXDoc    = wDoc.MainDocumentPart.GetXDocument();
                partXDoc.Root.ReplaceWith(newMainXDoc.Root);
                wDoc.MainDocumentPart.PutXDocument();

                File.WriteAllText(contentAtomDataFi.FullName, sb.ToString());

                Assert.Equal(contentAtomCount, contentAtomList.Count());
            }
        }