Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private void InvokeAndAssert(Type targetType, object targetObject, object mirrorObject, MemberInfo fieldInfo, string objectName)
        {
            bool exceptionSwallowedTarget;
            bool exceptionSwallowedMirror;

            object targetProperty = targetObject;
            object mirrorProperty = mirrorObject;
            string fieldName      = fieldInfo == null ? string.Empty : fieldInfo.Name;

            if (fieldInfo != null)
            {
                targetProperty = InvokeMember(targetType, targetObject, fieldInfo, Options.BindingFlags, true, out exceptionSwallowedTarget);
                mirrorProperty = InvokeMember(targetType, mirrorObject, fieldInfo, Options.BindingFlags, true, out exceptionSwallowedMirror);
            }

            if (Options.LogToConsole)
            {
                string consoleMessage = string.Format(
                    "ObjectComparer.Assert: {0}.{1}, values={2}|{3}"
                    , objectName
                    , fieldName
                    , targetProperty ?? "<null>"
                    , mirrorProperty ?? "<null>");

                Console.WriteLine(consoleMessage);
            }

            string message = string.Format(
                "ObjectComparer assertion failed: value1={3}, value2={4} on object={0}, type={1}, field={2}"
                , objectName
                , targetObject.GetType()
                , fieldName
                , targetProperty
                , mirrorProperty);


            TestFrameworkFacade.AssertEqual(targetProperty, mirrorProperty, message);
        }
Exemplo n.º 3
0
        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);
                }
            }
        }