|
From: Owen R. <exo...@us...> - 2004-06-23 04:45:02
|
Update of /cvsroot/nmock/nmock/test/NMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3533/test/NMock/Dynamic Modified Files: ClassGeneratorTest.cs Added Files: MockTypeIdentifierTest.cs Log Message: committing jim's new fixes for increasing performance and reducing memory requirements Index: ClassGeneratorTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ClassGeneratorTest.cs 21 Aug 2003 00:26:16 -0000 1.16 --- ClassGeneratorTest.cs 23 Jun 2004 04:44:53 -0000 1.17 *************** *** 1,4 **** --- 1,5 ---- using System; using System.Collections; + using System.Reflection; using System.Reflection.Emit; *************** *** 404,407 **** --- 405,446 ---- Assertion.Assert("Should include InternalMethod", methodsToIgnore.Contains("InternalMethod")); } + + [Test] public void OnlyOneAssemblyIsCreated() + { + cg = new ClassGenerator(typeof(IThingy), mock); + cg.Generate(); + + int originalAssemblyCount = AppDomain.CurrentDomain.GetAssemblies().Length; + + cg = new ClassGenerator(typeof(ConcreteThing), mock); + cg.Generate(); + + Assert.AreEqual(originalAssemblyCount, AppDomain.CurrentDomain.GetAssemblies().Length); + } + + [Test] public void MockTypesAreReused() + { + cg = new ClassGenerator(typeof(Exception), mock); + cg.Generate(); + + Assembly mockAssembly = null; + + foreach(Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) + { + if(ass.GetName().Name == "DynamicProxyAssembly") + { + mockAssembly = ass; + } + } + + Assert.IsNotNull(mockAssembly); + + int originalTypeCount = mockAssembly.GetTypes().Length; + + cg = new ClassGenerator(typeof(Exception), mock); + cg.Generate(); + + Assert.AreEqual(originalTypeCount, mockAssembly.GetTypes().Length); + } } } --- NEW FILE: MockTypeIdentifierTest.cs --- using System; using System.Collections; using NMock.Dynamic; using NUnit.Framework; namespace NMock.NMock.Dynamic { [TestFixture] public class MockTypeIdentifierTest { IList someMethodsToIgnore; IList someOtherMethodsToIgnore; Type typeToMock; Type anotherTypeToMock; [SetUp] public void SetUp() { typeToMock = typeof(ConcreteThing); anotherTypeToMock = typeof(AbstractThingy); someMethodsToIgnore = new ArrayList(); someMethodsToIgnore.Add("Eat"); someMethodsToIgnore.Add("Drink"); someOtherMethodsToIgnore = new ArrayList(); someOtherMethodsToIgnore.Add("Barf"); } [Test] public void TwoEqualMockTypesWithSameIgnoredMethodsAreEqual() { MockTypeIdentifier id1 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); MockTypeIdentifier id2 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); Assert.IsTrue(id1.Equals(id2)); } [Test] public void TwoEqualMockTypesWithDifferentIgnoredMethodsAreNotEqual() { MockTypeIdentifier id1 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); MockTypeIdentifier id2 = new MockTypeIdentifier(typeToMock, someOtherMethodsToIgnore); Assert.IsFalse(id1.Equals(id2)); } [Test] public void TwoUnequalMockTypesAreNotEqual() { MockTypeIdentifier id1 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); MockTypeIdentifier id2 = new MockTypeIdentifier(anotherTypeToMock, someMethodsToIgnore); Assert.IsFalse(id1.Equals(id2)); } [Test] public void ComparisonsToSelfIndicateEqualityOhMyGodISoundLikePaulHammant() { MockTypeIdentifier id1 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); Assert.IsTrue(id1.Equals(id1)); } [Test] public void ImplementsGetHashCodeProperly() { MockTypeIdentifier id1 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); MockTypeIdentifier id2 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); Assert.AreEqual(id1.GetHashCode(), id2.GetHashCode()); } [Test] public void IgnoredMethodsAreCopied() { MockTypeIdentifier id1 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); someMethodsToIgnore.Add("SomeOtherMethod"); MockTypeIdentifier id2 = new MockTypeIdentifier(typeToMock, someMethodsToIgnore); Assert.IsFalse(id1.Equals(id2)); } } } |