using System; using System.IO; using System.Collections; using NUnit.Framework; using System.Windows.Forms; namespace counter { /// /// The NUnit test harness (GUI form) runs this test object. /// [TestFixture] public class TestFixtureSetUpAndTearDownTest { private Counter myCounter; private Counter myCounter1; // I'll set this one to null private static Model myModel; [TestFixtureSetUp] public void RunBeforeAllTests() { myModel = Model.GetInstance(); Console.WriteLine("TestFixtureSetUp"); myCounter1 = null; } [TestFixtureTearDown] public void RunAfterAllTests() { Console.WriteLine("TestFixtureTearDown"); } [SetUp] public void RunBeforeEachTest() { myCounter = new Counter(14); Console.WriteLine("SetUp"); } [TearDown] public void RunAfterEachTest() { Console.WriteLine("TearDown"); } [Test] public void Test001IsNull() { Assert.IsNull(myCounter1); Console.WriteLine("Test001IsNull"); } [Test] public void Test002IsNotNull() { Assert.IsNotNull(myCounter); Console.WriteLine("Test002IsNotNull"); } [Test] public void Test003IncrementOrigValue() { Assert.IsTrue(myCounter.CounterValue==14); myCounter.Increment(); Assert.IsTrue(myCounter.CounterValue==15); Console.WriteLine("Test003IncrementOrigValue"); } [Test] public void Test004DecrementOrigValue() { Assert.IsTrue(myCounter.CounterValue==14); myCounter.Decrement(); Assert.IsTrue(myCounter.CounterValue==13); Console.WriteLine("Test004DecrementOrigValue"); } [Test] public void Test005AreSame() { myCounter1 = myCounter; Assert.AreSame(myCounter,myCounter1); Console.WriteLine("Test005AreSame"); } [Test] public void Test006AreEqual() { //myCounter1 = new Counter(14); myCounter1 = myCounter; Assert.AreEqual(myCounter,myCounter1); Console.WriteLine("Test006AreEqual"); } [Test] public void Test007ExceptionThrown() { bool passed = false; //myCounter.ThrowAnException(); try { // put here a call that should throw an Exception myCounter.ThrowAnException(); } catch (Exception e) { e.ToString(); passed = true; } // don’t do anything here Assert.IsTrue(passed); Console.WriteLine("Test007ExceptionThrown"); } [Test] [ExpectedException(typeof(Exception))] public void Test008ExceptionThrown() { Console.WriteLine("Test008ExceptionThrown"); myCounter.ThrowAnException(); } [Test] public void Test009ExceptionThrown() { try { // put here a call that should throw an Exception myCounter.ThrowAnException(); // the following line should be skipped Assert.Fail(); } catch (Exception e) // don’t do anything here that matters { Console.WriteLine("Test009ExceptionThrown: " + e.ToString()); } } [Test] public void Test010FailAnyway() { Console.WriteLine("Test010ExceptionThrown"); Assert.Fail(); //Assert.IsTrue(true); } // Assert.IsTrue( bool ); // Assert.IsFalse( bool ); // Assert.IsNull( bool ); // Assert.IsNotNull( bool ); // Assert.AreSame( object, object ) // Assert.AreEqual( object, object ); // Assert.Fail(); // Assert.AreEqual( int, int ); // Assert.AreEqual( float, float, float ); // Assert.AreEqual( double, double, double ); // // Each method has overloads that take a message // to be displayed as the last argument. } // end class } // end namespace