mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 07:13:09 +01:00
Making test logging ~30% better
This commit is contained in:
parent
222546b7fe
commit
82b71c36de
@ -26,15 +26,22 @@ public static string TestSerialise<T>(this T poco)
|
||||
return JsonConvert.SerializeObject(poco, Formatting.Indented, _testSerialiserSettings);
|
||||
}
|
||||
|
||||
public static string DifferencesTo<T>(this IEnumerable<T> expected, IEnumerable<T> actual)
|
||||
{
|
||||
var first = String.Join(Environment.NewLine, expected);
|
||||
var second = String.Join(Environment.NewLine, actual);
|
||||
|
||||
return first.DifferencesTo(second);
|
||||
}
|
||||
|
||||
public static string DifferencesTo(this string first, string second)
|
||||
{
|
||||
const string start = "\n\nDifferences:\n";
|
||||
const string lineDiffTemplate = "{0}A: {1}\n{0}B: {2}";
|
||||
var start = Environment.NewLine + Environment.NewLine + "Differences:" + Environment.NewLine;
|
||||
|
||||
var sb = new StringBuilder(start);
|
||||
|
||||
var sr1 = new StringReader(first);
|
||||
var sr2 = new StringReader(second);
|
||||
|
||||
int count = 1;
|
||||
using (sr1)
|
||||
{
|
||||
@ -42,18 +49,26 @@ public static string DifferencesTo(this string first, string second)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
string line1, line2;
|
||||
var lineWasRead = sr1.LineRead(out line1);
|
||||
lineWasRead &= sr2.LineRead(out line2);
|
||||
var line1 = sr1.ReadLine();
|
||||
var line1Read = !String.IsNullOrEmpty(line1);
|
||||
var line2 = sr2.ReadLine();
|
||||
var line2Read = !String.IsNullOrEmpty(line2);
|
||||
|
||||
if (!lineWasRead)
|
||||
if (line1Read && line2Read)
|
||||
{
|
||||
if (line1 != line2)
|
||||
{
|
||||
var line = string.Format(lineDiffTemplate, count, line1, line2);
|
||||
sb.AppendLine(line);
|
||||
}
|
||||
}
|
||||
else if (!line1Read && !line2Read)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (line1 != line2)
|
||||
else // one string still has lines
|
||||
{
|
||||
var line = string.Format("{0}A: {1}\n{0}B: {2}", count, line1, line2);
|
||||
var line = string.Format(lineDiffTemplate, count, line1, line2);
|
||||
sb.AppendLine(line);
|
||||
}
|
||||
|
||||
@ -61,7 +76,6 @@ public static string DifferencesTo(this string first, string second)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@ -86,8 +100,13 @@ public static DateTime RoundToNearestSecond(this DateTime dt)
|
||||
: dt.AddMilliseconds(1000 - ms);
|
||||
}
|
||||
|
||||
public static void AssertValues<T>(this PageResponse<T> pageResponse, bool success, int totalItems, int pageSize, int page, int totalPages)
|
||||
where T : new()
|
||||
public static void AssertValues<T>(
|
||||
this PageResponse<T> pageResponse,
|
||||
bool success,
|
||||
int totalItems,
|
||||
int pageSize,
|
||||
int page,
|
||||
int totalPages) where T : new()
|
||||
{
|
||||
const string messageFormat = "Page response:\n{0}\n\nExpected {1} to equal {2}";
|
||||
var json = pageResponse.TestSerialise();
|
||||
|
Loading…
Reference in New Issue
Block a user