From: Choy R. <ch...@us...> - 2005-01-29 08:49:22
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9962/DotNetMock.TestFramework.Tests Modified Files: Tag: RFE_1098585 DotNetMock.TestFramework.Tests.csproj MbUnitStubMakerTests.cs NUnitStubMakerTests.cs csUnitStubMakerTests.cs Added Files: Tag: RFE_1098585 ImplementationFactoryTests.cs Log Message: Moved the ITestFramework implementation resolution policy/algorithm into the DotNetMock.TestFramework namespace. Keep it separate and testable. Index: NUnitStubMakerTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests/Attic/NUnitStubMakerTests.cs,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** NUnitStubMakerTests.cs 25 Jan 2005 06:20:49 -0000 1.1.2.1 --- NUnitStubMakerTests.cs 29 Jan 2005 08:49:12 -0000 1.1.2.2 *************** *** 21,25 **** { Assembly providerAssembly = Assembly.Load("nunit.framework"); ! NUnitStubMaker stubMaker = new NUnitStubMaker(providerAssembly); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); --- 21,28 ---- { Assembly providerAssembly = Assembly.Load("nunit.framework"); ! NUnitStubMaker stubMaker = new NUnitStubMaker( ! providerAssembly, ! new SystemDynamicLinker() ! ); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); --- NEW FILE: ImplementationFactoryTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Collections; using System.Reflection; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class ImplementationFactoryTests { const string EXPECTED_STATIC_ASSEMBLY_NAME = "Assembly"; static readonly string EXPECTED_STATIC_TYPE_NAME = typeof(TestStaticImplementation).FullName; MockLinker linker; TestStaticImplementation implementation; Hashtable env; [Test] public void UseStaticImplementation() { linker.ExpectedAssemblyName = EXPECTED_STATIC_ASSEMBLY_NAME; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(TestStaticImplementation); env["DotNetMock_TestingAssembly"] = EXPECTED_STATIC_ASSEMBLY_NAME; env["DotNetMock_TestingComponent"] = EXPECTED_STATIC_TYPE_NAME; ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(1, linker.ActualAssemblyNames.Count); Assert.AreEqual("Assembly", linker.ActualAssemblyNames.Pop()); Assert.AreEqual(EXPECTED_STATIC_TYPE_NAME, linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual(typeof(TestStaticImplementation), linker.ActualType); } [Test] public void UseDynamicNUnitImplementation() { linker.ExpectedAssemblyName = "nunit.framework"; linker.ExpectedAssembly = typeof(NUnit.Framework.Assertion).Module.Assembly; linker.ExpectedType = typeof(NUnit.Framework.Assertion); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(1, linker.ActualAssemblyNames.Count); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("NUnit.Framework.Assertion", linker.ActualTypeName); Assert.AreSame(typeof(NUnit.Framework.Assertion).Module.Assembly, linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicMbUnitImplementation() { linker.ExpectedAssemblyName = "MbUnit.Core"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(MbUnit.Core.Framework.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(2, linker.ActualAssemblyNames.Count); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core.Framework.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicCsUnitImplementation() { linker.ExpectedAssemblyName = "csUnit"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(csUnit.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(3, linker.ActualAssemblyNames.Count); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicNUnitImplementationViaPartialName() { linker.ExpectedAssemblyName = "xxx"; linker.ExpectedPartialAssemblyName = "nunit.framework"; linker.ExpectedAssembly = typeof(NUnit.Framework.Assertion).Module.Assembly; linker.ExpectedType = typeof(NUnit.Framework.Assertion); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(4, linker.ActualAssemblyNames.Count); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("NUnit.Framework.Assertion", linker.ActualTypeName); Assert.AreSame(typeof(NUnit.Framework.Assertion).Module.Assembly, linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicMbUnitImplementationViaPartialName() { linker.ExpectedAssemblyName = "xxx"; linker.ExpectedPartialAssemblyName = "MbUnit.Core"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(MbUnit.Core.Framework.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(5, linker.ActualAssemblyNames.Count); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core.Framework.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [Test] public void UseDynamicCsUnitImplementationViaPartialName() { linker.ExpectedAssemblyName = "xxx"; linker.ExpectedPartialAssemblyName = "csUnit"; linker.ExpectedAssembly = Assembly.GetExecutingAssembly(); linker.ExpectedType = typeof(csUnit.Assert); ImplementationFactory factory = new ImplementationFactory(env, linker); ITestFramework tf = factory.NewImplementation(); Assert.IsNotNull(tf); Assert.AreSame(implementation, tf); Assert.AreEqual(6, linker.ActualAssemblyNames.Count); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("MbUnit.Core", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("nunit.framework", linker.ActualAssemblyNames.Pop()); Assert.AreEqual("csUnit.Assert", linker.ActualTypeName); Assert.AreSame(Assembly.GetExecutingAssembly(), linker.ActualAssembly); Assert.AreEqual("ProviderStub", linker.ActualType.FullName); } [SetUp] public void BeforeEachTest() { linker = new MockLinker(); implementation = new TestStaticImplementation(); env = new Hashtable(); linker.ExpectedInstance = implementation; } public class TestStaticImplementation : ITestFramework { #region ITestFramework Members public void Assert(bool assertion) { // TODO: Add TestStaticImplementation.Assert implementation } void DotNetMock.Core.ITestFramework.Assert(string message, bool assertion) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.Assert implementation } public void AssertNotNull(object assertion) { // TODO: Add TestStaticImplementation.AssertNotNull implementation } void DotNetMock.Core.ITestFramework.AssertNotNull(string message, object assertion) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.AssertNotNull implementation } public void AssertEquals(object expectedObject, object actualObject) { // TODO: Add TestStaticImplementation.AssertEquals implementation } void DotNetMock.Core.ITestFramework.AssertEquals(string message, object expectedObject, object actualObject) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.AssertEquals implementation } public void Fail(string message) { // TODO: Add TestStaticImplementation.Fail implementation } void DotNetMock.Core.ITestFramework.Fail() { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.Fail implementation } public void AssertNull(object assertion) { // TODO: Add TestStaticImplementation.AssertNull implementation } void DotNetMock.Core.ITestFramework.AssertNull(string message, object assertion) { // TODO: Add TestStaticImplementation.DotNetMock.Core.ITestFramework.AssertNull implementation } #endregion } class MockLinker : IDynamicLinker { public Stack ActualAssemblyNames = new Stack(); public string ExpectedAssemblyName = null; public string ExpectedPartialAssemblyName = null; public Assembly ExpectedAssembly = null; public string ActualTypeName = null; public Assembly ActualAssembly = null; public Type ExpectedType = null; public Type ActualType = null; public object ExpectedInstance = null; #region IDynamicLinker Members public Assembly LoadAssembly(string name) { ActualAssemblyNames.Push(name); if ( name!=ExpectedAssemblyName ) { return null; } return ExpectedAssembly; } public Assembly LoadAssemblyWithPartialName(string name) { ActualAssemblyNames.Push(name); if ( name!=ExpectedPartialAssemblyName ) { return null; } return ExpectedAssembly; } public Type GetType(string typeName, Assembly assembly) { ActualTypeName = typeName; ActualAssembly = assembly; return ExpectedType; } public object CreateInstance(Type type) { ActualType = type; return ExpectedInstance; } #endregion } } } Index: DotNetMock.TestFramework.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests/Attic/DotNetMock.TestFramework.Tests.csproj,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** DotNetMock.TestFramework.Tests.csproj 26 Jan 2005 01:24:28 -0000 1.1.2.2 --- DotNetMock.TestFramework.Tests.csproj 29 Jan 2005 08:49:11 -0000 1.1.2.3 *************** *** 111,114 **** --- 111,119 ---- /> <File + RelPath = "ImplementationFactoryTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "MbUnitStubMakerTests.cs" SubType = "Code" Index: csUnitStubMakerTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests/Attic/csUnitStubMakerTests.cs,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** csUnitStubMakerTests.cs 26 Jan 2005 01:24:33 -0000 1.1.2.1 --- csUnitStubMakerTests.cs 29 Jan 2005 08:49:12 -0000 1.1.2.2 *************** *** 143,147 **** ITestFramework MakeProviderStubInstance() { ! csUnitStubMaker stubMaker = new csUnitStubMaker(providerAssembly); StubClassMaker scm = new StubClassMaker(); Type stubClass = --- 143,150 ---- ITestFramework MakeProviderStubInstance() { ! csUnitStubMaker stubMaker = new csUnitStubMaker( ! providerAssembly, ! new SystemDynamicLinker() ! ); StubClassMaker scm = new StubClassMaker(); Type stubClass = Index: MbUnitStubMakerTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests/Attic/MbUnitStubMakerTests.cs,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** MbUnitStubMakerTests.cs 25 Jan 2005 06:20:49 -0000 1.1.2.1 --- MbUnitStubMakerTests.cs 29 Jan 2005 08:49:12 -0000 1.1.2.2 *************** *** 143,147 **** ITestFramework MakeProviderStubInstance() { ! MbUnitStubMaker stubMaker = new MbUnitStubMaker(providerAssembly); StubClassMaker scm = new StubClassMaker(); Type stubClass = --- 143,150 ---- ITestFramework MakeProviderStubInstance() { ! MbUnitStubMaker stubMaker = new MbUnitStubMaker( ! providerAssembly, ! new SystemDynamicLinker() ! ); StubClassMaker scm = new StubClassMaker(); Type stubClass = |