Esempio n. 1
0
 /// <summary>
 /// Compares all idml's in outputPath to make sure the content.xml and styles.xml are the same
 /// </summary>
 public static void AreEqual(string expectFullName, string outputFullName, string msg)
 {
     using (var expFl = new ZipFile(expectFullName))
     {
         var outFl = new ZipFile(outputFullName);
         foreach (ZipEntry zipEntry in expFl)
         {
             //TODO: designmap.xml should be tested but \\MetadataPacketPreference should be ignored as it contains the creation date.
             if (!CheckFile(zipEntry.Name, "Stories,Spreads,Resources,MasterSpreads"))
             {
                 continue;
             }
             if (Path.GetExtension(zipEntry.Name) != ".xml")
             {
                 continue;
             }
             string      outputEntry    = new StreamReader(outFl.GetInputStream(outFl.GetEntry(zipEntry.Name).ZipFileIndex)).ReadToEnd();
             string      expectEntry    = new StreamReader(expFl.GetInputStream(expFl.GetEntry(zipEntry.Name).ZipFileIndex)).ReadToEnd();
             XmlDocument outputDocument = new XmlDocument();
             outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
             outputDocument.LoadXml(outputEntry);
             XmlDocument expectDocument = new XmlDocument();
             outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
             expectDocument.LoadXml(expectEntry);
             XmlDsigC14NTransform outputCanon = new XmlDsigC14NTransform();
             outputCanon.Resolver = new XmlUrlResolver();
             outputCanon.LoadInput(outputDocument);
             XmlDsigC14NTransform expectCanon = new XmlDsigC14NTransform();
             expectCanon.Resolver = new XmlUrlResolver();
             expectCanon.LoadInput(expectDocument);
             Stream outputStream = (Stream)outputCanon.GetOutput(typeof(Stream));
             Stream expectStream = (Stream)expectCanon.GetOutput(typeof(Stream));
             string errMessage   = string.Format("{0}: {1} doesn't match", msg, zipEntry.Name);
             Assert.AreEqual(expectStream.Length, outputStream.Length, errMessage);
             FileAssert.AreEqual(expectStream, outputStream, errMessage);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Compares all odt's in outputPath to make sure the content.xml and styles.xml are the same
        /// </summary>
        /// <param name="expectPath">expected output path</param>
        /// <param name="outputPath">output path</param>
        /// <param name="msg">message to display if mismatch</param>
        public static void AreEqual(string expectPath, string outputPath, string msg)
        {
            var outDi = new DirectoryInfo(outputPath);
            var expDi = new DirectoryInfo(expectPath);

            FileInfo[] outFi = outDi.GetFiles("*.od*");
            FileInfo[] expFi = expDi.GetFiles("*.od*");
            Assert.AreEqual(outFi.Length, expFi.Length, string.Format("{0} {1} odt found {2} expected", msg, outFi.Length, expFi.Length));
            foreach (FileInfo fi in outFi)
            {
                var outFl = new ZipFile(fi.FullName);
                var expFl = new ZipFile(Common.PathCombine(expectPath, fi.Name));
                foreach (string name in "content.xml,styles.xml".Split(','))
                {
                    string      outputEntry    = new StreamReader(outFl.GetInputStream(outFl.GetEntry(name).ZipFileIndex)).ReadToEnd();
                    string      expectEntry    = new StreamReader(expFl.GetInputStream(expFl.GetEntry(name).ZipFileIndex)).ReadToEnd();
                    XmlDocument outputDocument = new XmlDocument();
                    outputDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
                    outputDocument.LoadXml(outputEntry);
                    XmlDocument expectDocument = new XmlDocument();
                    expectDocument.XmlResolver = FileStreamXmlResolver.GetNullResolver();
                    expectDocument.LoadXml(expectEntry);
                    XmlDsigC14NTransform outputCanon = new XmlDsigC14NTransform();
                    outputCanon.Resolver = new XmlUrlResolver();
                    outputCanon.LoadInput(outputDocument);
                    XmlDsigC14NTransform expectCanon = new XmlDsigC14NTransform();
                    expectCanon.Resolver = new XmlUrlResolver();
                    expectCanon.LoadInput(expectDocument);
                    Stream outputStream = (Stream)outputCanon.GetOutput(typeof(Stream));
                    Stream expectStream = (Stream)expectCanon.GetOutput(typeof(Stream));
                    string errMessage   = string.Format("{0}: {1} {2} doesn't match", msg, fi.Name, name);
                    Assert.AreEqual(expectStream.Length, outputStream.Length, errMessage);
                    FileAssert.AreEqual(expectStream, outputStream, errMessage);
                }
            }
        }