示例#1
0
        /// <summary>
        /// Extracts a resource from the calling assembly and dumps it's contents into the specified file
        /// </summary>
        /// <param name="expectedFileName">The full path to the file that contains the expected content</param>
        /// <param name="actualFileName">The full path to the file that contains the actual content generated during the test</param>
        /// <param name="friendlyName">The friendly name will be used during error output</param>
        /// <param name="ignoreLineNumbers">A list of line numbers where mismatches should be ignored</param>
        public static void FilesEqual(string expectedFileName, string actualFileName, string friendlyName, params int[] ignoreLineNumbers)
        {
            string expectedLine = String.Empty;
            string actualLine   = String.Empty;

            string failHeader = "\r\nFile Check Failed:\t" + friendlyName
                                + "\r\nExpected:\t\t" + expectedFileName
                                + "\r\nActual:\t\t" + actualFileName;
            string failError;

            string[] expectedContent = File.ReadAllLines(expectedFileName);
            string[] actualContent   = File.ReadAllLines(actualFileName);

            for (int lineIndex = 0; lineIndex < expectedContent.Length && lineIndex < actualContent.Length; lineIndex++)
            {
                expectedLine = expectedContent[lineIndex];
                actualLine   = actualContent[lineIndex];
                failError    = failHeader + "\r\nLine Number:\t\t" + (lineIndex + 1);

                if (!ignoreLineNumbers.Contains(lineIndex + 1))
                {
                    TestFrameworkFacade.AssertEqual(expectedLine, actualLine, failError);
                }
            }

            if (expectedContent.Length != actualContent.Length)
            {
                TestFrameworkFacade.AssertFail(
                    "{0}\r\nExpected line count={1}, actual line count={2}, although they matched until the end of the shortest file was reached"
                    , failHeader
                    , expectedContent.Length
                    , actualContent.Length);
            }
        }
        private void TearDown()
        {
            if (Options.EmitRegionWrappers)
            {
                EmitCode("#endregion");
            }

            if (Options.AssertFailAfterGeneration)
            {
                var message = c_SuccessMessage;

                if (AppendEmittedCodeToFailMessage)
                {
                    message += "\r\n" + m_EmittedCode;
                }

                TestFrameworkFacade.AssertFail(message);

                if (LogEmittedCode)
                {
                    Console.WriteLine(m_EmittedCode);
                }
            }
        }