示例#1
0
        private static void CompareResultWithReference(IDataBlock dataBlock, int dataBlockIndex, string completeFilePath, string referenceFileNamePostFix)
        {
            // Create the actual data
            string s = TestFramework.ExportToXml(new[] { dataBlock });

            string[] xmlStringArray = s.Split(new[] { '\n' });

            // Create the expected data
            string referenceFilePath = Path.GetDirectoryName(completeFilePath) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(completeFilePath) + dataBlockIndex.ToString() + referenceFileNamePostFix + ".xml";

            Assert.That(File.Exists(referenceFilePath), Is.True, string.Format("The file '{0}' exists", referenceFilePath));

            using (StreamReader xmlReferenceFile = new StreamReader(referenceFilePath))
            {
                // Compare all lines one by one
                // Read first expected line
                int    lineIndex    = 0;
                string expectedLine = xmlReferenceFile.ReadLine();
                while (!xmlReferenceFile.EndOfStream)
                {
                    if (lineIndex > 2)                     // Skip first three lines
                    {
                        string actualLine = xmlStringArray[lineIndex];
                        actualLine = actualLine.Trim('\r');

                        Assert.AreEqual(expectedLine, actualLine);
                    }
                    lineIndex++;

                    // Read next expected line
                    expectedLine = xmlReferenceFile.ReadLine();
                }
            }
        }