|
using System;
using System.Reflection;
using Geospatial;
using NUnit.Framework;
namespace UnitTests
{
public static class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Clear();
Console.WriteLine("Type 'exit' to finish or 'tests' to run the unit tests.\n");
Console.Write("Coordinate: ");
string input = Console.ReadLine();
switch (input.ToUpperInvariant())
{
case "EXIT":
return;
case "TESTS":
RunTests();
break;
default:
Location location;
if (!Location.TryParse(input, out location))
{
Console.WriteLine("Invalid input.");
}
else
{
Console.WriteLine("{0:DMS1}\n", location);
}
break;
}
Console.Write("\nPress any key to continue...");
Console.ReadKey();
}
}
private static void RunTests()
{
int totalPassed = 0;
int totalFailed = 0;
foreach (var type in Assembly.GetAssembly(typeof(Program)).GetTypes())
{
if (type.GetCustomAttributes(typeof(TestFixtureAttribute), false).Length != 0)
{
Console.WriteLine(type.Name);
int passed = 0;
int failed = 0;
RunTests(type, ref passed, ref failed);
totalPassed += passed;
totalFailed += failed;
}
}
Console.WriteLine("\nTotal number of tests ran:{0} (Failed:{1})\n", totalPassed + totalFailed, totalFailed);
}
private static void RunTests(Type type, ref int passed, ref int failed)
{
object instance = Activator.CreateInstance(type);
foreach (var method in type.GetMethods())
{
if (method.GetCustomAttributes(typeof(TestAttribute), false).Length != 0)
{
Console.Write("\t{0}...", method.Name);
try
{
method.Invoke(instance, null);
Console.WriteLine("passed.");
passed++;
}
catch (TargetInvocationException ex)
{
Console.WriteLine("FAILED ({0})", ex.InnerException.Message);
failed++;
}
}
}
Console.WriteLine("Passed:{0} Failed:{1}\n", passed, failed);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.