public string Create(
            string expected,
            string actual,
            string escapedActual,
            bool willPerformAutomaticRewrite,
            UnitTestLocationInfo location)
        {
            // It is important to use verbatim-strings in order to get the correct Environment.NewLine at line endings
            string message = "";

            bool areAlike = stringUtils.UnifyNewLines(expected) == stringUtils.UnifyNewLines(actual);
            if (areAlike)
                message = AreAlikeNotice;

            if (willPerformAutomaticRewrite)
            {
                message += string.Format(@"Rewritting test expectations in '{0}:{1}'.
            Compile and re-run to see green lights.
            New expectations:
            {2}", location.Filepath, location.LineNumber, escapedActual);
            }
            else
            {
                var newExpected = string.Format("var expected = {0};", escapedActual);
                message += string.Format("{0}{0}Proposed output for unit test:{0}{0}{1}{0}", Environment.NewLine, newExpected);
            }

            return message;
        }
        public string Create(
            string expected,
            string actual,
            string escapedActual,
            bool willPerformAutomaticRewrite,
            UnitTestLocationInfo location)
        {
            // It is important to use verbatim-strings in order to get the correct Environment.NewLine at line endings
            string message = "";

            bool areAlike = stringUtils.UnifyNewLines(expected) == stringUtils.UnifyNewLines(actual);

            if (areAlike)
            {
                message = AreAlikeNotice;
            }

            if (willPerformAutomaticRewrite)
            {
                message += string.Format(@"Rewritting test expectations in '{0}:{1}'.
Compile and re-run to see green lights.
New expectations:
{2}", location.Filepath, location.LineNumber, escapedActual);
            }
            else
            {
                var newExpected = string.Format("var expected = {0};", escapedActual);
                message += string.Format("{0}{0}Proposed output for unit test:{0}{0}{1}{0}", Environment.NewLine, newExpected);
            }

            return(message);
        }
示例#3
0
        void CallUnderlyingAssert(
            string expected,
            string actual,
            UnitTestLocationInfo info)
        {
            var  escapedActual = stringUtils.Escape(actual);
            bool rewriteTest   = info != null &&
                                 printer.Configuration.Test.AutomaticTestRewrite(info);

            var message = printer.Configuration.Test.AssertMessageCreator(
                expected,
                actual,
                escapedActual,
                rewriteTest,
                info);

            if (rewriteTest)
            {
                var rewriter = new TestRewriter(Configuration.FactoryFileRepository);
                rewriter.RewriteTest(
                    info,
                    expected,
                    escapedActual);
            }

            Configuration.Test.AreEqualsMethod(expected, actual, message);
        }
示例#4
0
        void CallUnderlyingAssert(
            string expected,
            string actual,
            UnitTestLocationInfo info,
            string message,
            string escapedActual)
        {
            if (info == null)
            {
                Configuration.AreEqualsMethod(expected, actual, message);
                return;
            }

            if (printer.Configuration.AutomaticTestRewrite(info.Filepath))
            {
                new TestRewriter(Configuration.FactoryFileRepository)
                .RewriteTest(info, expected, escapedActual);

                message =
                    "Rewritting test expectations in '"
                    + info.Filepath
                    + "'." + @"
Compile and re-run to see green lights.
New expectations:
"
                    + escapedActual;
            }

            Configuration.AreEqualsMethod(expected, actual, message);
        }
示例#5
0
        public void RewriteTest(UnitTestLocationInfo info, string originalExpected, string newExpected)
        {
            Encoding enc            = null;
            string   content        = null;
            var      fileRepository = fileRepositoryFactory();
            var      bytes          = fileRepository.Read(info.Filepath);

            enc = encodings.First(x => TryConvertFromEncoding(x, bytes, out content));

            var newTestContent = new Parser().ReplaceExpected(content, info.LineNumber, originalExpected, newExpected);

            fileRepository.Write(info.Filepath, enc.GetBytes(newTestContent));
        }
示例#6
0
        public void RewriteTest(UnitTestLocationInfo info, string originalExpected, string newExpected)
        {
            Encoding enc = null;
            string content = null;
            var fileRepository = fileRepositoryFactory();
            var bytes = fileRepository.Read(info.Filepath);

            enc = encodings.First(x => TryConvertFromEncoding(x, bytes, out content));

            var newTestContent = new Parser().ReplaceExpected(content, info.LineNumber, originalExpected, newExpected);
            fileRepository.Write(info.Filepath, enc.GetBytes(newTestContent));
        }
示例#7
0
        void CallUnderlyingAssert(
            string expected,
            string actual,
            UnitTestLocationInfo info)
        {
            var escapedActual = stringUtils.Escape(actual);
            bool rewriteTest = info != null
                && printer.Configuration.Test.AutomaticTestRewrite(info);

            var message = printer.Configuration.Test.AssertMessageCreator(
                expected,
                actual,
                escapedActual,
                rewriteTest,
                info);

            if (rewriteTest)
            {
                var rewriter = new TestRewriter(Configuration.FactoryFileRepository);
                rewriter.RewriteTest(
                    info,
                    expected,
                    escapedActual);
            }

            Configuration.Test.AreEqualsMethod(expected, actual, message);
        }