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;
        }
Example #2
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));
        }
Example #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);
        }