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); }
/// <summary> /// Assert that two strings are the "same" ignoring differences in line ending characters \r, \n. /// For all practical purposes, this method rectifies some of the many problems with source files stored in /// different methods on diffrent operating systems. /// <para> /// This method calls <see cref="AreEqual"/> after first unifiying the line endings. "\r" and "\r\n" are changed into "\n" /// </para> /// <para> /// Upon a failure, a suggested string for correcting the test is printed. /// </para> /// </summary> public void AreAlike(string expected, string actual) { AreEqual(stringUtils.UnifyNewLines(expected), stringUtils.UnifyNewLines(actual)); }