Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory usw-pr-cvs1:/tmp/cvs-serv28945/DotNetMock.Tests Added Files: AssemblyInfo.cs ExpectationArrayListTests.cs ExpectationBoolTests.cs ExpectationCounterTests.cs ExpectationListTest.cs ExpectationStringTests.cs ExpectationTypeTests.cs ExpectationValueTests.cs MockObjectTests.cs NullTests.cs ReturnValueTest.cs VerifierTests.cs Log Message: Moved testdotnetmock -> DotNetMock.Tests --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; // // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. // [assembly: AssemblyTitle("")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("")] [assembly: AssemblyCopyright("")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.*")] // // In order to sign your assembly you must specify a key to use. Refer to the // Microsoft .NET Framework documentation for more information on assembly signing. // // Use the attributes below to control which key is used for signing. // // Notes: // (*) If no key is specified, the assembly is not signed. // (*) KeyName refers to a key that has been installed in the Crypto Service // Provider (CSP) on your machine. KeyFile refers to a file which contains // a key. // (*) If the KeyFile and the KeyName values are both specified, the // following processing occurs: // (1) If the KeyName can be found in the CSP, that key is used. // (2) If the KeyName does not exist and the KeyFile does exist, the key // in the KeyFile is installed into the CSP and used. // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. // When specifying the KeyFile, the location of the KeyFile should be // relative to the project output directory which is // %Project Directory%\obj\<configuration>. For example, if your KeyFile is // located in the project directory, you would specify the AssemblyKeyFile // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework // documentation for more information on this. // [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("")] [assembly: AssemblyKeyName("")] --- NEW FILE: ExpectationArrayListTests.cs --- namespace DotNetMock.tests { using System; using System.Collections; using NUnit.Framework; using DotNetMock; /// <summary> /// Summary description for ExpectationArrayListTests. /// </summary> [TestFixture] public class ExpectationArrayListTests { private ExpectationArrayList _expectationArrayList = null; [SetUp] public void SetUp() { _expectationArrayList = new ExpectationArrayList("ExpectationArrayList"); } [TearDown] public void TearDown() { _expectationArrayList = null; } [Test] public void Empty() { _expectationArrayList.Verify(); } [Test] public void HasExpectations() { ArrayList arrayList3 = new ArrayList(); arrayList3.Add("A"); NUnit.Framework.Assertion.Assert("Should not have expectations.", !_expectationArrayList.HasExpectations); _expectationArrayList.AddExpectedMany(arrayList3); NUnit.Framework.Assertion.Assert("Should have expectations.", _expectationArrayList.HasExpectations); arrayList3 = null; } [Test] public void HasExpectationsFromArray() { string[] strings = new String[3]; strings[0] = "A"; strings[1] = "B"; strings[2] = "C"; NUnit.Framework.Assertion.Assert(!_expectationArrayList.HasExpectations); _expectationArrayList.AddExpectedMany(strings); NUnit.Framework.Assertion.Assert(_expectationArrayList.HasExpectations); } [Test] public void HasExpectationsFromEnumerator() { Hashtable table = new Hashtable(); table.Add("mock", "objects"); NUnit.Framework.Assertion.Assert(!_expectationArrayList.HasExpectations); _expectationArrayList.AddExpectedMany(table); NUnit.Framework.Assertion.Assert(_expectationArrayList.HasExpectations); } [Test] public void HasNotExpectations() { _expectationArrayList.AddActual("A"); NUnit.Framework.Assertion.Assert(!_expectationArrayList.HasExpectations); } [Test] public void Verify() { ArrayList arrayList4 = new ArrayList(); ArrayList arrayList5 = new ArrayList(); ArrayList arrayList6 = new ArrayList(); arrayList4.Add(3); arrayList4.Add(4); arrayList4.Add(5); arrayList5.Add(6); arrayList5.Add(7); arrayList5.Add(8); arrayList6.Add(3); arrayList6.Add(4); arrayList6.Add(5); _expectationArrayList.AddActualMany(arrayList4); _expectationArrayList.AddExpectedMany(arrayList5); try { _expectationArrayList.Verify(); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } _expectationArrayList.ClearExpected(); _expectationArrayList.AddExpectedMany(arrayList6); _expectationArrayList.Verify(); arrayList4 = null; arrayList5 = null; arrayList6 = null; } [Test] public void FailImmediately() { _expectationArrayList.AddExpected("A"); _expectationArrayList.AddExpected("B"); _expectationArrayList.AddActual("A"); try { _expectationArrayList.AddActual("C"); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } } [Test] public void FailImmediatelyTooMany() { _expectationArrayList.AddExpected("A"); _expectationArrayList.AddActual("A"); try { _expectationArrayList.AddActual("C"); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } } [Test] public void FlushExpected() { _expectationArrayList.AddExpected("A"); _expectationArrayList.ExpectNothing(); _expectationArrayList.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void FailingVerify() { _expectationArrayList.AddExpected("A"); _expectationArrayList.AddExpected("B"); _expectationArrayList.AddExpected("C"); _expectationArrayList.AddActual("A"); _expectationArrayList.AddActual("B"); _expectationArrayList.AddActual("B"); _expectationArrayList.Verify(); } [Test] public void AddSingleItem() { int int1 = 2; _expectationArrayList.AddExpected(int1); _expectationArrayList.AddActual(int1); _expectationArrayList.Verify(); } [Test] public void AddManyFromArray() { string[] array = new string[3]; array[0] = "A"; array[1] = "B"; array[2] = "C"; _expectationArrayList.AddExpectedMany(array); _expectationArrayList.AddActualMany(array); _expectationArrayList.Verify(); } [Test] public void AddManyFromEnumerator() { Hashtable hashExpected = new Hashtable(); hashExpected.Add("mock", "objects"); hashExpected.Add("source", "forge"); Hashtable hashActual = new Hashtable(); hashActual.Add("mock", "objects"); hashActual.Add("source", "forge"); _expectationArrayList.AddExpectedMany(hashExpected); _expectationArrayList.AddActualMany(hashActual); _expectationArrayList.Verify(); } } } --- NEW FILE: ExpectationBoolTests.cs --- using System; using NUnit.Framework; namespace DotNetMock.tests { /// <summary> /// Summary description for ExpectationBoolTests. /// </summary> [TestFixture] public class ExpectationBoolTests { private ExpectationBool _expectationBool = null; [SetUp] public void Init() { _expectationBool = new ExpectationBool("ExpectationBool.Tests"); } [TearDown] public void Desstroy() { _expectationBool = null; } [Test] public void SetActual() { NUnit.Framework.Assertion.Assert(!_expectationBool.Actual); _expectationBool.Actual = true; NUnit.Framework.Assertion.Assert(_expectationBool.Actual); _expectationBool.ClearActual(); NUnit.Framework.Assertion.Assert(!_expectationBool.Actual); } [Test] public void SetExpected() { NUnit.Framework.Assertion.Assert(!_expectationBool.Expected); _expectationBool.Expected = true; NUnit.Framework.Assertion.Assert(_expectationBool.Expected); _expectationBool.ClearExpected(); NUnit.Framework.Assertion.Assert(!_expectationBool.Expected); } [Test] public void HasExpectations() { NUnit.Framework.Assertion.Assert(!_expectationBool.Expected); _expectationBool.Expected = true; NUnit.Framework.Assertion.Assert(_expectationBool.Expected); NUnit.Framework.Assertion.Assert(_expectationBool.HasExpectations); } [Test] public void Verify() { _expectationBool.Actual = true; _expectationBool.Expected = false; try { _expectationBool.Verify(); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } _expectationBool.Expected = true; _expectationBool.Verify(); } [Test] public void FailureMode() { _expectationBool.Expected = true; NUnit.Framework.Assertion.Assert(_expectationBool.HasExpectations); NUnit.Framework.Assertion.Assert(!(_expectationBool.ShouldCheckImmediate)); _expectationBool.VerifyImmediate = true; NUnit.Framework.Assertion.Assert(_expectationBool.ShouldCheckImmediate); } [Test] public void ClearActual() { NUnit.Framework.Assertion.Assert(!_expectationBool.Actual); _expectationBool.Actual = true; NUnit.Framework.Assertion.Assert(_expectationBool.Actual); _expectationBool.ClearActual(); NUnit.Framework.Assertion.Assert(!_expectationBool.Actual); } [Test] public void ClearExpected() { NUnit.Framework.Assertion.Assert(!_expectationBool.Expected); _expectationBool.Expected = true; NUnit.Framework.Assertion.Assert(_expectationBool.Expected); _expectationBool.ClearExpected(); NUnit.Framework.Assertion.Assert(!_expectationBool.Expected); } } } --- NEW FILE: ExpectationCounterTests.cs --- namespace DotNetMock.tests { using System; using NUnit.Framework; /// <summary> /// Test case for ExpectationCounter /// </summary> [TestFixture] public class ExpectationCounterTests { private ExpectationCounter _counter; public ExpectationCounterTests(): base() {} public ExpectationCounterTests(String name) : base() {} [SetUp] public void SetUp() { _counter = new ExpectationCounter("ExpectationCounter"); } [TearDown] public void TearDown() { _counter = null; } [Test] public void ExpectNothing() { _counter.ExpectNothing(); Assertion.Assert("Has expectation", _counter.HasExpectations); _counter.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void ExpectNothingFailure() { _counter.ExpectNothing(); _counter.VerifyImmediate = true; Assertion.Assert("Has expectation", _counter.HasExpectations); _counter.Inc(); } [Test] [ExpectedException(typeof(AssertionException))] public void FailImmediately() { _counter.Expected = 1; _counter.VerifyImmediate = true; _counter.Inc(); _counter.Inc(); } [Test] public void FailOnVerify() { _counter.Expected = 1; _counter.Inc(); try { _counter.Inc(); } catch(AssertionException ae) { Assertion.Fail("Should not have thrown an exception"); } try { _counter.Verify(); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch(AssertionException ae) { } } [Test] [ExpectedException(typeof(AssertionException))] public void NotEnoughCalls() { _counter.Expected = 1; _counter.Verify(); } [Test] public void FlushActual() { _counter.Inc(); _counter.ClearActual(); _counter.Expected = 1; _counter.Inc(); _counter.Verify(); } [Test] public void HasNoExpectations() { _counter.Inc(); Assertion.Assert("Should have no expectations", !_counter.HasExpectations); } [Test] public void Success() { _counter.Expected = 1; _counter.Inc(); _counter.Verify(); } } } --- NEW FILE: ExpectationListTest.cs --- namespace DotNetMock.tests { using System; using System.Collections; using NUnit.Framework; [TestFixture] public class ExpectationListTests { private ExpectationList el; [SetUp] public void SetUp() { el = new ExpectationList("Test expectation list"); } [Test] public void testEmpty() { el.verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void testFailImmediately() { el.AddExpected("A"); el.AddExpected("B"); el.verifyImmediate = true; el.AddActual("A"); el.AddActual("C"); } [Test] [ExpectedException(typeof(AssertionException))] public void testFailImmediatelyTooMany() { el.verifyImmediate = true; el.AddExpected("A"); el.AddActual("A"); el.AddActual("A"); } [Test] public void testFailOnVerify() { el.AddExpected("A"); try { el.AddActual("B"); } catch (AssertionException ae) { Assertion.Fail("Exception should not have been thrown yet"); } try { el.verify(); } catch (AssertionException ae) { // Success } } [Test] public void testHasExpectations() { Assertion.Assert("Should not have any expectations", !el.hasExpectations); el.AddExpected("A"); Assertion.Assert("Should have expectation",el.hasExpectations); } [Test] public void testExpectedFromArrayList(){ ArrayList expected = new ArrayList(); expected.Add("A"); expected.Add("B"); el.AddExpectedCollection(expected); el.AddActual("A"); el.AddActual("B"); el.verify(); } [Test] public void testActualFromArrayList(){ ArrayList actual = new ArrayList(); actual.Add("A"); actual.Add("B"); el.AddActualCollection(actual); el.AddExpected("A"); el.AddExpected("B"); el.verify(); } [Test] public void testStringArray() { String[] actual = new String[] {"A", "B"}; el.AddExpected("A"); el.AddExpected("B"); el.AddActualCollection(actual); el.verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void testFailingStringArray() { String[] expected = new String[] {"A", "B"}; el.AddExpectedCollection(expected); el.verifyImmediate = true; el.AddActual("A"); el.AddActual("C"); } [Test] [ExpectedException(typeof(AssertionException))] public void testFailingStringArrayOnVerify() { String[] expected = new String[] {"A", "B", "C"}; el.AddExpectedCollection(expected); el.verifyImmediate = false; el.AddActual("A"); el.AddActual("B"); el.AddActual("D"); el.verify(); } [Test] public void testSorted() { el.AddExpected("A"); el.AddExpected("B"); el.AddActual("A"); el.AddActual("B"); el.verify(); } } } --- NEW FILE: ExpectationStringTests.cs --- namespace DotNetMock.tests { using System; using NUnit.Framework; using DotNetMock; /// <summary> /// Summary description for ExpectationStringTests. /// </summary> [TestFixture] public class ExpectationStringTests { ExpectationString _expectationString = null; public ExpectationStringTests(string name) : base() {} public ExpectationStringTests() : base() {} [SetUp] public void SetUp() { _expectationString = new ExpectationString("ExpectationString"); } [TearDown] public void TearDown() { _expectationString = null; } [Test] public void SetActual() { string test1 = "Mock Objects are Cool"; NUnit.Framework.Assertion.AssertNull(_expectationString.Actual); _expectationString.Actual = test1; NUnit.Framework.Assertion.AssertNotNull(_expectationString.Actual); _expectationString.ClearActual(); NUnit.Framework.Assertion.AssertNull(_expectationString.Actual); } [Test] public void SetExpected() { string test2 = "Unit Testing helps code."; NUnit.Framework.Assertion.AssertNull(_expectationString.Expected); _expectationString.Expected = test2; NUnit.Framework.Assertion.AssertNotNull(_expectationString.Expected); NUnit.Framework.Assertion.AssertEquals(test2, _expectationString.Expected); _expectationString.ClearExpected(); NUnit.Framework.Assertion.AssertNull(_expectationString.Expected); } [Test] public void HasExpectations() { string test3 = "Sourceforge is nice."; NUnit.Framework.Assertion.AssertNull(_expectationString.Expected); _expectationString.Expected = test3; NUnit.Framework.Assertion.AssertNotNull(_expectationString.Expected); NUnit.Framework.Assertion.Assert(_expectationString.HasExpectations); test3 = null; } [Test] public void Verify() { string test4 = "Mock Objects are cool."; string test5 = "Sourceforge is nice."; string test6 = "Mock Objects are cool."; _expectationString.Actual = test4; _expectationString.Expected = test5; try { _expectationString.Verify(); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } _expectationString.Expected = test6; _expectationString.Verify(); test4 = null; test5 = null; test6 = null; } [Test] public void FailureMode() { string test7 = ""; _expectationString.Expected = test7; NUnit.Framework.Assertion.Assert(_expectationString.HasExpectations); NUnit.Framework.Assertion.Assert(!(_expectationString.ShouldCheckImmediate)); _expectationString.VerifyImmediate = true; NUnit.Framework.Assertion.Assert(_expectationString.ShouldCheckImmediate); test7 = null; } [Test] public void ClearActual() { string test8 = "Testing"; NUnit.Framework.Assertion.AssertNull(_expectationString.Actual); _expectationString.Actual = test8; NUnit.Framework.Assertion.AssertNotNull(_expectationString.Actual); _expectationString.ClearActual(); NUnit.Framework.Assertion.AssertNull(_expectationString.Actual); test8 = null; } [Test] public void ClearExpected() { string test9 = "Testing"; NUnit.Framework.Assertion.AssertNull(_expectationString.Expected); _expectationString.Expected = test9; NUnit.Framework.Assertion.AssertNotNull(_expectationString.Expected); _expectationString.ClearExpected(); NUnit.Framework.Assertion.AssertNull(_expectationString.Expected); test9 = null; } } } --- NEW FILE: ExpectationTypeTests.cs --- using System; using DotNetMock; using NUnit.Framework; namespace DotNetMock.tests { /// <summary> /// Summary description for ExpectationTypeTests. /// </summary> [TestFixture] public class ExpectationTypeTests { private ExpectationType _expectationType = null; [SetUp] public void SetUp() { _expectationType = new ExpectationType("ExpectationValue"); } [TearDown] public void TearDown() { _expectationType = null; } [Test] public void SetActual() { Type type1 = typeof(string); NUnit.Framework.Assertion.AssertNull(_expectationType.Actual); _expectationType.Actual = type1; NUnit.Framework.Assertion.AssertEquals(type1, _expectationType.Actual); type1 = null; } [Test] public void SetExpected() { Type type2 = typeof(int); NUnit.Framework.Assertion.AssertNull(_expectationType.Expected); _expectationType.Expected = type2; NUnit.Framework.Assertion.AssertEquals(type2, _expectationType.Expected); type2 = null; } [Test] public void HasExpectations() { Type type3 = typeof(float); _expectationType.Expected = type3; NUnit.Framework.Assertion.Assert(_expectationType.HasExpectations); type3 = null; } [Test] public void Verify() { Type type1 = typeof(string); Type type2 = typeof(int); Type type3 = typeof(string); _expectationType.Actual = type1 ; _expectationType.Expected = type2 ; try { _expectationType.Verify(); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } _expectationType.Expected = type3 ; _expectationType.Verify(); } [Test] public void FailureMode() { Type type4 = typeof(double); _expectationType.Expected = type4; NUnit.Framework.Assertion.Assert(_expectationType.HasExpectations); NUnit.Framework.Assertion.Assert(!(_expectationType.ShouldCheckImmediate)); _expectationType.VerifyImmediate = true; NUnit.Framework.Assertion.Assert(_expectationType.ShouldCheckImmediate); type4 = null; } [Test] public void ClearActual() { Type type5 = typeof(string); NUnit.Framework.Assertion.AssertNull(_expectationType.Actual); _expectationType.Actual = type5; NUnit.Framework.Assertion.AssertNotNull(_expectationType.Actual); _expectationType.ClearActual(); NUnit.Framework.Assertion.AssertNull(_expectationType.Actual); type5 = null; } [Test] public void ClearExpected() { Type type6 = typeof(string); NUnit.Framework.Assertion.AssertNull(_expectationType.Expected); _expectationType.Expected = type6; NUnit.Framework.Assertion.AssertNotNull(_expectationType.Expected); NUnit.Framework.Assertion.Assert(_expectationType.HasExpectations); _expectationType.ClearExpected(); NUnit.Framework.Assertion.AssertNull(_expectationType.Expected); type6 = null; } [Test] public void NullValues() { _expectationType.ExpectNothing(); _expectationType.ClearActual(); _expectationType.Verify(); } } } --- NEW FILE: ExpectationValueTests.cs --- namespace DotNetMock.tests { using System; using NUnit.Framework; using DotNetMock; /// <summary> /// Summary description for ExpectationValueTests. /// </summary> [TestFixture] public class ExpectationValueTests { private ExpectationValue _expectationValue; public ExpectationValueTests(string name) : base() {} public ExpectationValueTests() : base() {} [SetUp] public void SetUp() { _expectationValue = new ExpectationValue("ExpectationValue"); } [TearDown] public void TearDown() { _expectationValue = null; } [Test] public void SetActual() { Object object1 = new Object(); NUnit.Framework.Assertion.AssertNull(_expectationValue.Actual); _expectationValue.Actual = object1; NUnit.Framework.Assertion.AssertEquals(object1, _expectationValue.Actual); object1 = null; } [Test] public void SetExpected() { Object object2 = new Object(); NUnit.Framework.Assertion.AssertNull(_expectationValue.Expected); _expectationValue.Expected = object2; NUnit.Framework.Assertion.AssertEquals(object2, _expectationValue.Expected); object2 = null; } [Test] public void HasExpectations() { Object object3 = new Object(); _expectationValue.Expected = object3; NUnit.Framework.Assertion.Assert(_expectationValue.HasExpectations); object3 = null; } [Test] public void Verify() { int int1 = 3; int int2 = 5; int int3 = 3; _expectationValue.Actual = int1 ; _expectationValue.Expected = int2 ; try { _expectationValue.Verify(); NUnit.Framework.Assertion.Fail("Should have thrown an exception."); } catch (NUnit.Framework.AssertionException ex) { } _expectationValue.Expected = int3 ; _expectationValue.Verify(); } [Test] public void FailureMode() { Object object4 = new Object(); _expectationValue.Expected = object4; NUnit.Framework.Assertion.Assert(_expectationValue.HasExpectations); NUnit.Framework.Assertion.Assert(!(_expectationValue.ShouldCheckImmediate)); _expectationValue.VerifyImmediate = true; NUnit.Framework.Assertion.Assert(_expectationValue.ShouldCheckImmediate); object4 = null; } [Test] public void ClearActual() { Object object5 = new Object(); NUnit.Framework.Assertion.AssertNull(_expectationValue.Actual); _expectationValue.Actual = object5; NUnit.Framework.Assertion.AssertNotNull(_expectationValue.Actual); _expectationValue.ClearActual(); NUnit.Framework.Assertion.AssertNull(_expectationValue.Actual); object5 = null; } [Test] public void ClearExpected() { Object object6 = new Object(); NUnit.Framework.Assertion.AssertNull(_expectationValue.Expected); _expectationValue.Expected = object6; NUnit.Framework.Assertion.AssertNotNull(_expectationValue.Expected); NUnit.Framework.Assertion.Assert(_expectationValue.HasExpectations); _expectationValue.ClearExpected(); NUnit.Framework.Assertion.AssertNull(_expectationValue.Expected); object6 = null; } [Test] public void NullValues() { _expectationValue.ExpectNothing(); _expectationValue.ClearActual(); _expectationValue.Verify(); } } } --- NEW FILE: MockObjectTests.cs --- namespace DotNetMock.tests { using System; using NUnit.Framework; using DotNetMock; /// <summary> /// Summary description for MockObjectTests. /// </summary> [TestFixture] public class MockObjectTests { private MockObject _mockObject; [SetUp] public void SetUp() { _mockObject = new MockObject(); } [ExpectedException(typeof(NotImplementedException))] public void NotImplemented() { _mockObject.NotImplemented("Fake Class Name"); NUnit.Framework.Assertion.Fail("Assertion Failed: NotImplemented"); } public void AssertEquals() { Object object1 = new Object(); Object object2 = object1; _mockObject.AssertEquals("", object1, object2); } [Test] [ExpectedException(typeof(AssertionException))] public void NotAssertEquals() { Object object1 = new Object(); Object object2 = new Object(); _mockObject.AssertEquals("", object1, object2); NUnit.Framework.Assertion.Fail("Assertion Failed: testAssertFalse"); } [Test] public void AssertTrue() { _mockObject.AssertTrue("", true); } [Test] [ExpectedException(typeof(AssertionException))] public void AssertFalse() { _mockObject.AssertTrue("", false); throw new System.ApplicationException("Assertion Failed: testAssertFalse"); } [Test] [ExpectedException(typeof(AssertionException))] public void Fail() { _mockObject.Fail("Failed"); NUnit.Framework.Assertion.Fail("Assertion Failed: testFail"); } [Test] public void Verify() { _mockObject.Verify(); } } } --- NEW FILE: NullTests.cs --- namespace DotNetMock.tests { using System; using NUnit.Framework; using DotNetMock; /// <summary> /// Summary description for Null Class. /// </summary> [TestFixture] public class NullTests { private Null _null = null; public NullTests(string name) : base() {} public NullTests() : base() {} [SetUp] public void SetUp() { _null = new Null(); } [TearDown] public void TearDown() { _null = null; } [Test] public void Null() { NUnit.Framework.Assertion.AssertEquals("null", _null.ToString()); _null = new Null("Null Object"); NUnit.Framework.Assertion.AssertEquals("Null Object", _null.ToString()); Null null2 = new Null(); int int1 = 3; NUnit.Framework.Assertion.Assert(!_null.Equals(int1)); NUnit.Framework.Assertion.Assert(_null.Equals(null2)); } } } --- NEW FILE: ReturnValueTest.cs --- namespace DotNetMock.tests { using System; using System.Collections; using NUnit.Framework; [TestFixture] public class ReturnValueTest { private ReturnValue r; [SetUp] public void SetUp() { r = new ReturnValue("Test Return Value"); } [Test] public void ValidAddAndRetrieve() { r.RepeatFinalValue = false; r.Add("A"); r.Add("B"); Assertion.AssertEquals("A", r.Next()); Assertion.AssertEquals("B", r.Next()); } [Test] public void ValidRepeatedRetrieve() { r.RepeatFinalValue = true; r.Add("A"); r.Add("B"); Assertion.AssertEquals("A", r.Next()); Assertion.AssertEquals("B", r.Next()); Assertion.AssertEquals("B", r.Next()); Assertion.AssertEquals("B", r.Next()); Assertion.AssertEquals("B", r.Next()); } [Test] [ExpectedException(typeof(AssertionException))] public void InvalidRepeatedRetrieve() { r.Add("A"); r.Add("B"); Assertion.AssertEquals("A", r.Next()); Assertion.AssertEquals("B", r.Next()); r.Next(); } [Test] public void AddCollection() { ArrayList args = new ArrayList(); args.Add("A"); args.Add("B"); args.Add("C"); r.AddCollection(args); Assertion.AssertEquals("A", r.Next()); Assertion.AssertEquals("B", r.Next()); Assertion.AssertEquals("C", r.Next()); } [Test] [ExpectedException(typeof(SystemException))] public void ExceptionalValues() { r.Add("A"); r.Add(new SystemException("Deliberate exception")); Assertion.AssertEquals("A", r.Next()); r.Next(); } } } --- NEW FILE: VerifierTests.cs --- namespace DotNetMock.tests { using System; using NUnit.Framework; using DotNetMock; /// <summary> /// Summary description for VerifierTests. /// </summary> [TestFixture] public class VerifierTests { /// /// <summary>Inner class to test single values</summary> /// private class OneVerifiable : MockObject { private ExpectationValue _expectationValue = new ExpectationValue("Should Fail"); // Non-Verifiable fields to check it correctly ignores them. private String _stringField; public int _intField = 5; // Non-Verifiable Property public String StringField { set { _stringField = value; } get { return _stringField; } } public OneVerifiable() : base() { _expectationValue.Expected = "Good"; } public Object ActualValue { set { _expectationValue.Actual = value; } get { return _expectationValue.Actual; } } } ///<summary>Check inheritence works</summary> private class InheritVerifiable : OneVerifiable {} private OneVerifiable _mockObject = null; public VerifierTests(string name) : base() {} public VerifierTests() {} [SetUp] public void SetUp() { _mockObject = new OneVerifiable(); } [TearDown] public void TearDown() {} [Test] public void OneVerifiablePasses() { _mockObject.ActualValue = "Good"; _mockObject.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void OneVerifiableFails() { _mockObject.ActualValue = "bad"; _mockObject.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void InheritVerifiableFails() { InheritVerifiable inheritVerifiable = new InheritVerifiable(); inheritVerifiable.ActualValue = "bad"; inheritVerifiable.Verify(); } [Test] public void InheritVerifiablePasses() { InheritVerifiable inheritVerifiable = new InheritVerifiable(); inheritVerifiable.ActualValue = "Good"; inheritVerifiable.Verify(); } [Test] public void NoVerifiables() { new MockObject().Verify(); } } } |