From: Griffin C. <gc...@us...> - 2006-06-06 03:07:05
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv6076/DotNetMock/TestFramework Modified Files: IStubMaker.cs ImplementationFactory.cs NUnitStubMaker.cs Log Message: - Initial conversion to .NET 2.0 and VIsual Studio 2005 Index: NUnitStubMaker.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework/NUnitStubMaker.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** NUnitStubMaker.cs 29 Jan 2005 09:13:32 -0000 1.2 --- NUnitStubMaker.cs 6 Jun 2006 03:06:52 -0000 1.3 *************** *** 1,48 **** #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports ! using System; using System.Collections; using System.Reflection; using System.Reflection.Emit; #endregion namespace DotNetMock.TestFramework { ! /// <summary> ! /// <see cref="IStubMaker"/> for NUnit. ! /// </summary> ! public class NUnitStubMaker : AbstractStubMaker ! { ! /// <summary> ! /// Create NUnit stub maker. ! /// </summary> ! /// <param name="providerAssembly">nunit.framework assembly</param> ! /// <param name="linker">reflection linkage provider</param> ! public NUnitStubMaker( ! Assembly providerAssembly, ! IDynamicLinker linker ! ) ! : base("NUnit.Framework.Assertion", providerAssembly, linker) ! { ! } ! /// <summary> ! /// Implement stub methods that forward to the ! /// NUnit.Framework.Assertion class. ! /// </summary> ! /// <param name="ilg"><see cref="ILGenerator"/> for the method ! /// we are stubbing</param> ! /// <param name="mi"><see cref="MethodInfo"/> for the method ! /// we are stubbing</param> ! public override void ImplementStubMethod(ILGenerator ilg, MethodInfo mi) ! { ! IList parameterTypes = GetParameterTypes(mi); ! for (int i = 0; i<parameterTypes.Count; ++i) ! { ! EmitLdarg(ilg, i+1); ! } ! EmitProviderCall(ilg, mi.Name, parameterTypes); ! } ! } ! } --- 1,53 ---- #region License + // Copyright (c) 2004 Choy Rim. All rights reserved. + #endregion + #region Imports ! using System.Collections; using System.Reflection; using System.Reflection.Emit; + #endregion namespace DotNetMock.TestFramework { ! /// <summary> ! /// <see cref="IStubMaker"/> for NUnit. ! /// </summary> ! public class NUnitStubMaker : AbstractStubMaker ! { ! /// <summary> ! /// Create NUnit stub maker. ! /// </summary> ! /// <param name="providerAssembly">nunit.framework assembly</param> ! /// <param name="linker">reflection linkage provider</param> ! public NUnitStubMaker( ! Assembly providerAssembly, ! IDynamicLinker linker ! ) ! : base("NUnit.Framework.Assertion", providerAssembly, linker) ! { ! } ! ! /// <summary> ! /// Implement stub methods that forward to the ! /// NUnit.Framework.Assertion class. ! /// </summary> ! /// <param name="ilg"><see cref="ILGenerator"/> for the method ! /// we are stubbing</param> ! /// <param name="mi"><see cref="MethodInfo"/> for the method ! /// we are stubbing</param> ! public override void ImplementStubMethod(ILGenerator ilg, MethodInfo mi) ! { ! IList parameterTypes = GetParameterTypes(mi); ! for (int i = 0; i < parameterTypes.Count; ++i) ! { ! EmitLdarg(ilg, i + 1); ! } ! EmitProviderCall(ilg, mi.Name, parameterTypes); ! } ! } ! } \ No newline at end of file Index: ImplementationFactory.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework/ImplementationFactory.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ImplementationFactory.cs 5 Feb 2005 21:46:27 -0000 1.3 --- ImplementationFactory.cs 6 Jun 2006 03:06:52 -0000 1.4 *************** *** 1,6 **** --- 1,10 ---- #region License + // Copyright (c) 2004 Choy Rim. All rights reserved. + #endregion + #region Imports + using System; using System.Collections; *************** *** 12,125 **** namespace DotNetMock.TestFramework { ! /// <summary> ! /// Creates an implementation of <see cref="ITestFramework"/> ! /// based on settings in the environment. ! /// </summary> ! public class ImplementationFactory ! { ! const string STATIC_IMPLEMENTATION_ASSEMBLY_KEY = ! "DotNetMock_TestingAssembly"; ! const string STATIC_IMPLEMENTATION_TYPE_KEY = ! "DotNetMock_TestingComponent"; ! const string NUNIT_ASSEMBLY_NAME = "nunit.framework"; ! const string MBUNIT_ASSEMBLY_NAME = "MbUnit.Core"; ! const string CSUNIT_ASSEMBLY_NAME = "csUnit"; ! private IDictionary _env; ! private IDynamicLinker _linker; ! /// <summary> ! /// Create an implementation factory. ! /// </summary> ! /// <param name="env"><see cref="IDictionary"/> of environment ! /// variable name value entries</param> ! /// <param name="linker">provider of reflection services</param> ! public ImplementationFactory(IDictionary env, IDynamicLinker linker) ! { ! _env = env; ! _linker = linker; ! } ! /// <summary> ! /// Create an appropriate implementation for the given ! /// environment. ! /// </summary> ! /// <returns>a new <see cref="ITestFramework"/></returns> ! public ITestFramework NewImplementation() ! { ! Type implementationType = getStaticImplementationType(); ! if ( implementationType==null ) ! { ! implementationType = getDynamicImplementationType(); ! } ! if ( implementationType==null ) ! { ! throw new SystemException( ! "Cannot find an appropriate test framework implementation." ! ); ! } ! ITestFramework implementation = (ITestFramework) ! _linker.CreateInstance(implementationType); ! return implementation; ! } ! private Type getStaticImplementationType() ! { ! string assemblyName = (string) ! _env[STATIC_IMPLEMENTATION_ASSEMBLY_KEY]; ! if ( (assemblyName==null) || (assemblyName.Equals(String.Empty)) ) ! { ! return null; ! } ! string typeName = (string) ! _env[STATIC_IMPLEMENTATION_TYPE_KEY]; ! if ( (typeName==null) || (typeName.Equals(String.Empty)) ) ! { ! return null; ! } ! Assembly assembly = ! _linker.LoadAssembly(assemblyName); ! Type type = ! _linker.GetType(typeName, assembly); ! return type; ! } ! private Type getDynamicImplementationType() ! { ! StubClassMaker classMaker = new StubClassMaker(); ! IStubMaker stubMaker = null; ! Assembly assembly = null; ! if ( (assembly=_linker.LoadAssembly(NUNIT_ASSEMBLY_NAME))!=null ) ! { ! stubMaker = new NUnitStubMaker(assembly, _linker); ! } ! else if ( (assembly=_linker.LoadAssembly(MBUNIT_ASSEMBLY_NAME))!=null ) ! { ! stubMaker = new MbUnitStubMaker(assembly, _linker); ! } ! else if ( (assembly=_linker.LoadAssembly(CSUNIT_ASSEMBLY_NAME))!=null ) ! { ! stubMaker = new csUnitStubMaker(assembly, _linker); ! } ! else if ( (assembly=_linker.LoadAssemblyWithPartialName(NUNIT_ASSEMBLY_NAME))!=null ) ! { ! stubMaker = new NUnitStubMaker(assembly, _linker); ! } ! else if ( (assembly=_linker.LoadAssemblyWithPartialName(MBUNIT_ASSEMBLY_NAME))!=null ) ! { ! stubMaker = new MbUnitStubMaker(assembly, _linker); ! } ! else if ( (assembly=_linker.LoadAssemblyWithPartialName(CSUNIT_ASSEMBLY_NAME))!=null ) ! { ! stubMaker = new csUnitStubMaker(assembly, _linker); ! } ! else ! { ! return null; ! } ! Type stubClass = classMaker.MakeStubClass( ! typeof(ITestFramework), ! stubMaker ! ); ! return stubClass; ! } ! } ! } --- 16,133 ---- namespace DotNetMock.TestFramework { ! /// <summary> ! /// Creates an implementation of <see cref="ITestFramework"/> ! /// based on settings in the environment. ! /// </summary> ! public class ImplementationFactory ! { ! private const string STATIC_IMPLEMENTATION_ASSEMBLY_KEY = ! "DotNetMock_TestingAssembly"; ! private const string STATIC_IMPLEMENTATION_TYPE_KEY = ! "DotNetMock_TestingComponent"; ! private const string NUNIT_ASSEMBLY_NAME = "nunit.framework"; ! private const string MBUNIT_ASSEMBLY_NAME = "MbUnit.Core"; ! private const string CSUNIT_ASSEMBLY_NAME = "csUnit"; ! private IDictionary _env; ! private IDynamicLinker _linker; ! ! /// <summary> ! /// Create an implementation factory. ! /// </summary> ! /// <param name="env"><see cref="IDictionary"/> of environment ! /// variable name value entries</param> ! /// <param name="linker">provider of reflection services</param> ! public ImplementationFactory(IDictionary env, IDynamicLinker linker) ! { ! _env = env; ! _linker = linker; ! } ! ! /// <summary> ! /// Create an appropriate implementation for the given ! /// environment. ! /// </summary> ! /// <returns>a new <see cref="ITestFramework"/></returns> ! public ITestFramework NewImplementation() ! { ! Type implementationType = getStaticImplementationType(); ! if (implementationType == null) ! { ! implementationType = getDynamicImplementationType(); ! } ! if (implementationType == null) ! { ! throw new SystemException( ! "Cannot find an appropriate test framework implementation." ! ); ! } ! ITestFramework implementation = (ITestFramework) ! _linker.CreateInstance(implementationType); ! return implementation; ! } ! ! private Type getStaticImplementationType() ! { ! string assemblyName = (string) ! _env[STATIC_IMPLEMENTATION_ASSEMBLY_KEY]; ! if ((assemblyName == null) || (assemblyName.Equals(String.Empty))) ! { ! return null; ! } ! string typeName = (string) ! _env[STATIC_IMPLEMENTATION_TYPE_KEY]; ! if ((typeName == null) || (typeName.Equals(String.Empty))) ! { ! return null; ! } ! Assembly assembly = ! _linker.LoadAssembly(assemblyName); ! Type type = ! _linker.GetType(typeName, assembly); ! return type; ! } ! ! private Type getDynamicImplementationType() ! { ! StubClassMaker classMaker = new StubClassMaker(); ! IStubMaker stubMaker = null; ! Assembly assembly = null; ! if ((assembly = _linker.LoadAssembly(NUNIT_ASSEMBLY_NAME)) != null) ! { ! stubMaker = new NUnitStubMaker(assembly, _linker); ! } ! else if ((assembly = _linker.LoadAssembly(MBUNIT_ASSEMBLY_NAME)) != null) ! { ! stubMaker = new MbUnitStubMaker(assembly, _linker); ! } ! else if ((assembly = _linker.LoadAssembly(CSUNIT_ASSEMBLY_NAME)) != null) ! { ! stubMaker = new csUnitStubMaker(assembly, _linker); ! } ! else if ((assembly = _linker.LoadAssemblyWithPartialName(NUNIT_ASSEMBLY_NAME)) != null) ! { ! stubMaker = new NUnitStubMaker(assembly, _linker); ! } ! else if ((assembly = _linker.LoadAssemblyWithPartialName(MBUNIT_ASSEMBLY_NAME)) != null) ! { ! stubMaker = new MbUnitStubMaker(assembly, _linker); ! } ! else if ((assembly = _linker.LoadAssemblyWithPartialName(CSUNIT_ASSEMBLY_NAME)) != null) ! { ! stubMaker = new csUnitStubMaker(assembly, _linker); ! } ! else ! { ! return null; ! } ! Type stubClass = classMaker.MakeStubClass( ! typeof (ITestFramework), ! stubMaker ! ); ! return stubClass; ! } ! } ! } \ No newline at end of file Index: IStubMaker.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework/IStubMaker.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IStubMaker.cs 29 Jan 2005 09:13:32 -0000 1.2 --- IStubMaker.cs 6 Jun 2006 03:06:52 -0000 1.3 *************** *** 1,27 **** #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports ! using System; using System.Reflection; using System.Reflection.Emit; #endregion namespace DotNetMock.TestFramework { ! /// <summary> ! /// Interface for making method stubs for test framework providers. ! /// </summary> ! public interface IStubMaker ! { ! /// <summary> ! /// Implement one of the methods of the interface we are required ! /// to stub out. ! /// </summary> ! /// <param name="ilg"><see cref="ILGenerator"/> of the method ! /// on the dynamically generated type</param> ! /// <param name="mi"><see cref="MethodInfo"/> of the method ! /// on the interface we want to implement</param> ! void ImplementStubMethod(ILGenerator ilg, MethodInfo mi); ! } ! } --- 1,31 ---- #region License + // Copyright (c) 2004 Choy Rim. All rights reserved. + #endregion + #region Imports ! using System.Reflection; using System.Reflection.Emit; + #endregion namespace DotNetMock.TestFramework { ! /// <summary> ! /// Interface for making method stubs for test framework providers. ! /// </summary> ! public interface IStubMaker ! { ! /// <summary> ! /// Implement one of the methods of the interface we are required ! /// to stub out. ! /// </summary> ! /// <param name="ilg"><see cref="ILGenerator"/> of the method ! /// on the dynamically generated type</param> ! /// <param name="mi"><see cref="MethodInfo"/> of the method ! /// on the interface we want to implement</param> ! void ImplementStubMethod(ILGenerator ilg, MethodInfo mi); ! } ! } \ No newline at end of file |