diff --git a/NETMFTesting/Marknic.TestRunner.Rigging/Assert.cs b/NETMFTesting/Marknic.TestRunner.Rigging/Assert.cs
new file mode 100644
index 0000000..44a2e13
--- /dev/null
+++ b/NETMFTesting/Marknic.TestRunner.Rigging/Assert.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Collections;
+using System.Reflection;
+using Microsoft.SPOT;
+
+// ==============================================================================================
+// .NET MicroFramework TestRunner
+//
+// Author: Mark S. Nichols
+//
+// Copyright (c) 2013 Mark Nichols
+//
+// This source is subject to the Microsoft Permissive License.
+// ==============================================================================================
+
+namespace Marknic.TestRunner.Rigging
+{
+ ///
+ /// Assertions for the test methods
+ ///
+ public static class Assert
+ {
+ public static void IsTrue(bool condition, string message)
+ {
+ if (!condition)
+ {
+ throw new Exception(message);
+ }
+ }
+
+ public static void IsFalse(bool condition, string message)
+ {
+ if (condition)
+ {
+ throw new Exception(message);
+ }
+ }
+
+ public static void IsTrue(bool condition)
+ {
+ if (!condition)
+ {
+ throw new Exception("Result should have been true - result was false");
+ }
+ }
+
+ public static void IsFalse(bool condition)
+ {
+ if (condition)
+ {
+ throw new Exception("Result should have been false - result was true");
+ }
+ }
+
+ public static void AreEqual(int expected, int actual)
+ {
+ if (expected != actual)
+ {
+ throw new Exception("Expected value: " + expected + " - Actual value: " + actual);
+ }
+ }
+
+ public static void AreEqual(long expected, long actual)
+ {
+ if (expected != actual)
+ {
+ throw new Exception("Expected value: " + expected + " - Actual value: " + actual);
+ }
+ }
+
+ public static void AreEqual(string expected, string actual)
+ {
+ if (expected != actual)
+ {
+ throw new Exception("Expected value: " + expected + " - Actual value: " + actual);
+ }
+ }
+
+ public static void IsNotNull(object actual)
+ {
+ if (actual == null)
+ {
+ throw new Exception("Object tested was null");
+ }
+ }
+
+ public static void IsNull(object actual)
+ {
+ if (actual != null)
+ {
+ throw new Exception("Object tested was not null");
+ }
+ }
+
+ public static void AreEqual(object expected, object actual)
+ {
+ if (expected == null)
+ {
+ throw new Exception("Expected object was null");
+ }
+
+ if (actual == null)
+ {
+ throw new Exception("actual object was null");
+ }
+
+ if (expected != actual)
+ {
+ throw new Exception("Objects are not the same: " + expected + " - Actual: " + actual);
+ }
+ }
+ }
+}
diff --git a/NETMFTesting/Marknic.TestRunner.Rigging/Marknic.TestRunner.Rigging.csproj b/NETMFTesting/Marknic.TestRunner.Rigging/Marknic.TestRunner.Rigging.csproj
index e0e725b..739966d 100644
--- a/NETMFTesting/Marknic.TestRunner.Rigging/Marknic.TestRunner.Rigging.csproj
+++ b/NETMFTesting/Marknic.TestRunner.Rigging/Marknic.TestRunner.Rigging.csproj
@@ -1,51 +1,53 @@
-
-
-
- Marknic.TestRunner.Rigging
- Library
- Marknic.TestRunner.Rigging
- {b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 9.0.21022
- 2.0
- {3B9F95F2-EACD-4609-A8FA-459A088C081D}
- v4.2
- $(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\
-
-
-
-
-
-
-
-
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+ Marknic.TestRunner.Rigging
+ Library
+ Marknic.TestRunner.Rigging
+ {b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 9.0.21022
+ 2.0
+ {3B9F95F2-EACD-4609-A8FA-459A088C081D}
+ v4.2
+ $(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\
+
+
+
+
+
+
+
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/NETMFTesting/Marknic.TestRunner.Rigging/Result.cs b/NETMFTesting/Marknic.TestRunner.Rigging/Result.cs
new file mode 100644
index 0000000..053f5f5
--- /dev/null
+++ b/NETMFTesting/Marknic.TestRunner.Rigging/Result.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections;
+using System.Reflection;
+using Microsoft.SPOT;
+
+// ==============================================================================================
+// .NET MicroFramework TestRunner
+//
+// Author: Mark S. Nichols
+//
+// Copyright (c) 2013 Mark Nichols
+//
+// This source is subject to the Microsoft Permissive License.
+// ==============================================================================================
+
+namespace Marknic.TestRunner.Rigging
+{
+ ///
+ /// Tracking object for each test
+ ///
+ public class Result
+ {
+ public string MethodName { get; set; }
+ public bool Succeeded { get; set; }
+ public Exception Exception { get; set; }
+ }
+}
diff --git a/NETMFTesting/Marknic.TestRunner.Rigging/Rigging.cs b/NETMFTesting/Marknic.TestRunner.Rigging/Rigging.cs
index 112da51..3bc37ed 100644
--- a/NETMFTesting/Marknic.TestRunner.Rigging/Rigging.cs
+++ b/NETMFTesting/Marknic.TestRunner.Rigging/Rigging.cs
@@ -15,112 +15,6 @@
namespace Marknic.TestRunner.Rigging
{
- ///
- /// Tracking object for each test
- ///
- public class Result
- {
- public string MethodName { get; set; }
- public bool Succeeded { get; set; }
- public Exception Exception { get; set; }
- }
-
- ///
- /// Assertions for the test methods
- ///
- public static class Assert
- {
- public static void IsTrue(bool condition, string message)
- {
- if (!condition)
- {
- throw new Exception(message);
- }
- }
-
- public static void IsFalse(bool condition, string message)
- {
- if (condition)
- {
- throw new Exception(message);
- }
- }
-
- public static void IsTrue(bool condition)
- {
- if (!condition)
- {
- throw new Exception("Result should have been true - result was false");
- }
- }
-
- public static void IsFalse(bool condition)
- {
- if (condition)
- {
- throw new Exception("Result should have been false - result was true");
- }
- }
-
- public static void AreEqual(int expected, int actual)
- {
- if (expected != actual)
- {
- throw new Exception("Expected value: " + expected + " - Actual value: " + actual);
- }
- }
-
- public static void AreEqual(long expected, long actual)
- {
- if (expected != actual)
- {
- throw new Exception("Expected value: " + expected + " - Actual value: " + actual);
- }
- }
-
- public static void AreEqual(string expected, string actual)
- {
- if (expected != actual)
- {
- throw new Exception("Expected value: " + expected + " - Actual value: " + actual);
- }
- }
-
- public static void IsNotNull(object actual)
- {
- if (actual == null)
- {
- throw new Exception("Object tested was null");
- }
- }
-
- public static void IsNull(object actual)
- {
- if (actual != null)
- {
- throw new Exception("Object tested was not null");
- }
- }
-
- public static void AreEqual(object expected, object actual)
- {
- if (expected == null)
- {
- throw new Exception("Expected object was null");
- }
-
- if (actual == null)
- {
- throw new Exception("actual object was null");
- }
-
- if (expected != actual)
- {
- throw new Exception("Objects are not the same: " + expected + " - Actual: " + actual);
- }
- }
- }
-
public static class TestRig
{
private static readonly ArrayList ResultList = new ArrayList();
@@ -138,12 +32,20 @@ public static void ExecuteTests(Assembly assembly)
foreach (var type in types)
{
- var methodList = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
+ var methodList = type.GetMethods(BindingFlags.Public | BindingFlags.Instance);
+
+ object instance = null;
foreach (var method in methodList)
{
// Do we have a test?
- if (!method.Name.StartsWith("Test")) continue;
+ if (!method.Name.StartsWith("Test")) continue;
+
+ if (instance == null)
+ {
+ var constructor = type.GetConstructor(new Type[] { });
+ instance = constructor.Invoke(new object[] {});
+ }
_totalCount++;
@@ -156,8 +58,8 @@ public static void ExecuteTests(Assembly assembly)
}
try
- {
- method.Invoke(null, null);
+ {
+ method.Invoke(instance, null);
// If an exception was expected then create one for reporting
if (!result.Succeeded)
@@ -174,6 +76,12 @@ public static void ExecuteTests(Assembly assembly)
if (!result.Succeeded) _failureCount++;
ResultList.Add(result);
+ }
+
+ var disposable = instance as IDisposable;
+ if (disposable != null)
+ {
+ disposable.Dispose();
}
}
diff --git a/NETMFTesting/Marknic.TestRunner/LogicalWithSetup.cs b/NETMFTesting/Marknic.TestRunner/LogicalWithSetup.cs
new file mode 100644
index 0000000..7072447
--- /dev/null
+++ b/NETMFTesting/Marknic.TestRunner/LogicalWithSetup.cs
@@ -0,0 +1,34 @@
+using System;
+using Microsoft.SPOT;
+using Marknic.TestRunner.Rigging;
+
+namespace Marknic.TestRunner
+{
+ public class LogicalWithSetup
+ {
+ private readonly Robot robot;
+
+ public LogicalWithSetup()
+ {
+ robot = new Robot { Name = "I" };
+ }
+
+ public void TestWhenMovingSpeedWillBeGreaterThen0()
+ {
+ robot.StartMoving();
+ Assert.IsTrue(robot.CurrentSpeeed > 0);
+ }
+ }
+
+ internal class Robot{
+
+ public string Name { get; set; }
+
+ public int CurrentSpeeed { get; set; }
+
+ internal void StartMoving()
+ {
+ CurrentSpeeed = 10;
+ }
+ }
+}
diff --git a/NETMFTesting/Marknic.TestRunner/Marknic.TestRunner.csproj b/NETMFTesting/Marknic.TestRunner/Marknic.TestRunner.csproj
index 1bf0c74..3a0c815 100644
--- a/NETMFTesting/Marknic.TestRunner/Marknic.TestRunner.csproj
+++ b/NETMFTesting/Marknic.TestRunner/Marknic.TestRunner.csproj
@@ -1,61 +1,62 @@
-
-
-
- Marknic.TestRunner
- Exe
- Marknic.TestRunner
- {b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
- 9.0.21022
- 2.0
- {31223C89-FC73-49A0-AF84-B4201A4F4384}
- v4.2
- $(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\
-
-
-
-
-
-
-
-
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {3B9F95F2-EACD-4609-A8FA-459A088C081D}
- Marknic.TestRunner.Rigging
-
-
- {5959E7D4-88E9-4CBB-B51B-5FD5EE164065}
- NETMFTesting
-
-
+
+
+
+ Marknic.TestRunner
+ Exe
+ Marknic.TestRunner
+ {b69e3092-b931-443c-abe7-7e7b65f2a37f};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ 9.0.21022
+ 2.0
+ {31223C89-FC73-49A0-AF84-B4201A4F4384}
+ v4.2
+ $(MSBuildExtensionsPath32)\Microsoft\.NET Micro Framework\
+
+
+
+
+
+
+
+
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {3B9F95F2-EACD-4609-A8FA-459A088C081D}
+ Marknic.TestRunner.Rigging
+
+
+ {5959E7D4-88E9-4CBB-B51B-5FD5EE164065}
+ NETMFTesting
+
+
\ No newline at end of file