[go: nahoru, domu]

Skip to content

Commit

Permalink
NET40 test changed: better testing app
Browse files Browse the repository at this point in the history
  • Loading branch information
masbicudo committed Jan 22, 2018
1 parent 4abd236 commit 38a5021
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<ItemGroup>
<Compile Include="Assert.cs" />
<Compile Include="Program.cs" />
<Compile Include="TestEndException.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
61 changes: 50 additions & 11 deletions ProjectGenerator/Templates/net40/%TestProjectName%.net40/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,57 @@ public override void AreEqual<T>(T expected, T value)
var eql = EqualityComparer<T>.Default.Equals(expected, value);
Console.ForegroundColor = eql ? ConsoleColor.Green : ConsoleColor.Red;
Console.Write(eql ? " OK " : " FAIL ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"{this.CurrentMethod}");
Console.ForegroundColor = prev;
Console.WriteLine($"AreEqual({ToLiteral(expected)}, {ToLiteral(value)})");
Console.WriteLine($" AreEqual({ToLiteral(expected)}, {ToLiteral(value)})");
this.State = eql ? TestState.Ok : TestState.Error;
if (this.State != TestState.Ok)
throw new TestEndException();
}

public override void IsInstanceOfType(object value, Type expectedType, string message)
{
var prev = Console.ForegroundColor;
var ok = value != null && expectedType.IsAssignableFrom(value.GetType());
Console.ForegroundColor = ok ? ConsoleColor.Green : ConsoleColor.Red;
Console.Write(ok ? " OK " : " FAIL ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"{this.CurrentMethod}");
Console.ForegroundColor = prev;
Console.WriteLine($" IsInstanceOfType({ToLiteral(value)}, typeof({expectedType.ToString()}), {ToLiteral(message)})");
this.State = ok ? TestState.Ok : TestState.Error;
if (this.State != TestState.Ok)
throw new TestEndException();
}

public override void Inconclusive(string message, object[] parameters)
{
var prev = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write(" NONE ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"{this.CurrentMethod}");
Console.ForegroundColor = prev;
Console.WriteLine($" {message}");
this.State = TestState.Inconclusive;
if (this.State != TestState.Ok)
throw new TestEndException();
}

public override void IsTrue(bool what)
{
var prev = Console.ForegroundColor;
var ok = what;
Console.ForegroundColor = ok ? ConsoleColor.Green : ConsoleColor.Red;
Console.Write(ok ? " OK " : " FAIL ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"{this.CurrentMethod}");
Console.ForegroundColor = prev;
Console.WriteLine($" IsTrue({what})");
this.State = ok ? TestState.Ok : TestState.Error;
if (this.State != TestState.Ok)
throw new TestEndException();
}

private static string ToLiteral<T>(T value)
Expand All @@ -34,15 +83,5 @@ private static string ToLiteral<T>(T value)

return value.ToString();
}

public override void IsInstanceOfType(object value, Type expectedType, string message)
{
var prev = Console.ForegroundColor;
var ok = value != null && expectedType.IsAssignableFrom(value.GetType());
Console.ForegroundColor = ok ? ConsoleColor.Green : ConsoleColor.Red;
Console.Write(ok ? " OK " : " FAIL ");
Console.ForegroundColor = prev;
Console.WriteLine($"IsInstanceOfType({ToLiteral(value)}, typeof({expectedType.ToString()}), {ToLiteral(message)})");
}
}
}
Loading

0 comments on commit 38a5021

Please sign in to comment.