This list is closed, nobody may subscribe to it.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(99) |
Feb
(163) |
Mar
(3) |
Apr
(33) |
May
(8) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
|
Feb
|
Mar
(10) |
Apr
|
May
|
Jun
(16) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Griffin C. <gc...@us...> - 2005-01-27 04:40:42
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.NUnit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23894/DotNetMock.NUnit Modified Files: AssemblyInfo.cs Log Message: - Added strong naming to assemblies. Used delay signing, so as not to have to distribute the key Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.NUnit/AssemblyInfo.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AssemblyInfo.cs 5 Jan 2005 04:29:15 -0000 1.3 --- AssemblyInfo.cs 27 Jan 2005 04:40:32 -0000 1.4 *************** *** 10,12 **** --- 10,14 ---- [assembly: AssemblyCompany("DotNetMock")] [assembly: AssemblyVersion("0.7.3.0")] + [assembly: AssemblyDelaySign(true)] + [assembly: AssemblyKeyFile("dotnetmock.key")] |
From: Griffin C. <gc...@us...> - 2005-01-27 04:40:42
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.csUnitNamespace In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23894/DotNetMock.csUnitNamespace Modified Files: AssemblyInfo.cs Log Message: - Added strong naming to assemblies. Used delay signing, so as not to have to distribute the key Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.csUnitNamespace/AssemblyInfo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssemblyInfo.cs 5 Jan 2005 04:29:16 -0000 1.4 --- AssemblyInfo.cs 27 Jan 2005 04:40:33 -0000 1.5 *************** *** 10,11 **** --- 10,14 ---- [assembly: AssemblyCompany("DotNetMock")] [assembly: AssemblyVersion("0.7.3.0")] + + [assembly: AssemblyDelaySign(true)] + [assembly: AssemblyKeyFile("dotnetmock.key")] |
From: Griffin C. <gc...@us...> - 2005-01-27 04:40:42
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23894/DotNetMock.Framework Modified Files: AssemblyInfo.cs Log Message: - Added strong naming to assemblies. Used delay signing, so as not to have to distribute the key Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/AssemblyInfo.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AssemblyInfo.cs 5 Jan 2005 04:29:15 -0000 1.5 --- AssemblyInfo.cs 27 Jan 2005 04:40:32 -0000 1.6 *************** *** 11,21 **** [assembly: AssemblyTitle("DotNetMock")] ! [assembly: AssemblyDescription(".NET Implementation of Mock Objects")] ! [assembly: AssemblyConfiguration("")] ! [assembly: AssemblyCompany("")] ! [assembly: AssemblyProduct("")] ! [assembly: AssemblyCopyright("")] ! [assembly: AssemblyTrademark("")] ! [assembly: AssemblyCulture("")] [assembly: AssemblyVersion("0.7.3.0")] --- 11,17 ---- [assembly: AssemblyTitle("DotNetMock")] ! [assembly: AssemblyDescription(".NET Implementation of Mock Objects")] [assembly: AssemblyVersion("0.7.3.0")] + [assembly: AssemblyDelaySign(true)] + [assembly: AssemblyKeyFile("dotnetmock.key")] |
From: Griffin C. <gc...@us...> - 2005-01-27 04:40:42
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23894/DotNetMock.Core Modified Files: AssemblyInfo.cs Log Message: - Added strong naming to assemblies. Used delay signing, so as not to have to distribute the key Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Core/AssemblyInfo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssemblyInfo.cs 5 Jan 2005 04:29:14 -0000 1.4 --- AssemblyInfo.cs 27 Jan 2005 04:40:31 -0000 1.5 *************** *** 10,11 **** --- 10,14 ---- [assembly: AssemblyCompany("DotNetMock")] [assembly: AssemblyVersion("0.7.3.0")] + + [assembly: AssemblyDelaySign(true)] + [assembly: AssemblyKeyFile("dotnetmock.key")] \ No newline at end of file |
From: Griffin C. <gc...@us...> - 2005-01-27 04:40:42
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.MbUnitNamespace In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23894/DotNetMock.MbUnitNamespace Modified Files: AssemblyInfo.cs Log Message: - Added strong naming to assemblies. Used delay signing, so as not to have to distribute the key Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.MbUnitNamespace/AssemblyInfo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssemblyInfo.cs 5 Jan 2005 04:29:15 -0000 1.4 --- AssemblyInfo.cs 27 Jan 2005 04:40:32 -0000 1.5 *************** *** 10,11 **** --- 10,13 ---- [assembly: AssemblyCompany("DotNetMock")] [assembly: AssemblyVersion("0.7.3.0")] + [assembly: AssemblyDelaySign(true)] + [assembly: AssemblyKeyFile("dotnetmock.key")] \ No newline at end of file |
From: Choy R. <ch...@us...> - 2005-01-26 06:24:16
|
Update of /cvsroot/dotnetmock/dotnetmock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6485 Modified Files: Tag: RFE_1098585 DotNetMock.build Log Message: Added DotNetMock.TestFramework.Tests to build an tests. Index: DotNetMock.build =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.build,v retrieving revision 1.13 retrieving revision 1.13.2.1 diff -C2 -d -r1.13 -r1.13.2.1 *** DotNetMock.build 5 Jan 2005 14:03:32 -0000 1.13 --- DotNetMock.build 26 Jan 2005 06:24:05 -0000 1.13.2.1 *************** *** 36,39 **** --- 36,40 ---- <test assemblyname="${build.dir}/DotNetMock.Framework.Tests.dll"/> <test assemblyname="${build.dir}/DotNetMock.Examples.dll"/> + <test assemblyname="${build.dir}/DotNetMock.TestFramework.Tests.dll"/> </nunit2> </target> *************** *** 131,135 **** </fileset> </copy> ! </target> <target name="package" description="Collects and packs up the distribution" depends="buildMSDN"> <mkdir dir="${dist.dir}" failonerror="false"/> --- 132,146 ---- </fileset> </copy> ! <csc target="library" output="${build.dir}/DotNetMock.TestFramework.Tests.dll" debug="${debug}"> ! <sources basedir="."> ! <includes name="DotNetMock.TestFramework.Tests/**/*.cs"/> ! </sources> ! <references basedir="."> ! <includes name="lib/nunit.framework.dll"/> ! <includes name="build/DotNetMock.dll"/> ! <includes name="build/DotNetMock.Core.dll"/> ! </references> ! </csc> ! </target> <target name="package" description="Collects and packs up the distribution" depends="buildMSDN"> <mkdir dir="${dist.dir}" failonerror="false"/> |
From: Choy R. <ch...@us...> - 2005-01-26 01:37:10
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22814/DotNetMock Modified Files: Tag: RFE_1098585 Assertion.cs Log Message: Cleaned up headers and comments. Index: Assertion.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Assertion.cs,v retrieving revision 1.5.4.2 retrieving revision 1.5.4.3 diff -C2 -d -r1.5.4.2 -r1.5.4.3 *** Assertion.cs 26 Jan 2005 01:24:34 -0000 1.5.4.2 --- Assertion.cs 26 Jan 2005 01:36:41 -0000 1.5.4.3 *************** *** 1,2 **** --- 1,6 ---- + #region License + // Copyright (c) 2004, 2005 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Configuration; *************** *** 4,16 **** using System.Reflection; using System.Runtime.Remoting; using DotNetMock.Core; using DotNetMock.TestFramework; namespace DotNetMock { /// <summary> ! /// Assertion class used throughout the DotNetMock framework to encapsulate specific testing frameworks. ! /// NOTE: All exceptions will be caught, and rethrown as DotNetMock.AssertionException. /// </summary> public class Assertion { --- 8,28 ---- using System.Reflection; using System.Runtime.Remoting; + using DotNetMock.Core; using DotNetMock.TestFramework; + #endregion namespace DotNetMock { /// <summary> ! /// Access point to underlying testing framework. /// </summary> + /// <author>Griffin Caprio</author> + /// <author>Choy Rim</author> + /// <remarks> + /// Assertion class used throughout the DotNetMock framework to + /// encapsulate specific testing frameworks. + /// NOTE: All exceptions will be caught, and rethrown as DotNetMock.AssertionException. + /// </remarks> public class Assertion { |
From: Choy R. <ch...@us...> - 2005-01-26 01:25:54
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20700/DotNetMock.TestFramework.Tests Modified Files: Tag: RFE_1098585 DotNetMock.TestFramework.Tests.csproj Added Files: Tag: RFE_1098585 csUnitStubMakerTests.cs Log Message: Added support for dynamically generated binding for csUnit. Index: DotNetMock.TestFramework.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests/Attic/DotNetMock.TestFramework.Tests.csproj,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** DotNetMock.TestFramework.Tests.csproj 25 Jan 2005 06:20:49 -0000 1.1.2.1 --- DotNetMock.TestFramework.Tests.csproj 26 Jan 2005 01:24:28 -0000 1.1.2.2 *************** *** 106,109 **** --- 106,114 ---- /> <File + RelPath = "csUnitStubMakerTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "MbUnitStubMakerTests.cs" SubType = "Code" --- NEW FILE: csUnitStubMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class csUnitStubMakerTests { static readonly Assembly providerAssembly = Assembly.GetExecutingAssembly(); const string EXPECTED_MESSAGE = "MESSAGE"; const string NOT_NULL = "NOT-NULL"; ITestFramework tf; static string MethodName { get { return csUnit.Assert.MethodName; } } static object[] Arguments { get { return csUnit.Assert.Arguments; } } [Test] public void CheckAssert() { tf.Assert(true); Assert.AreEqual("True", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(true, Arguments[0]); tf.Assert(false); Assert.AreEqual("True", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(false, Arguments[0]); } [Test] public void CheckAssertWithMessage() { tf.Assert(EXPECTED_MESSAGE, true); Assert.AreEqual("True", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(true, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.Assert(EXPECTED_MESSAGE, false); Assert.AreEqual("True", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(false, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNotNull() { tf.AssertNotNull(NOT_NULL); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNotNull(null); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNotNullWithMessage() { tf.AssertNotNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNotNull(EXPECTED_MESSAGE, null); Assert.AreEqual("NotNull", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNull() { tf.AssertNull(NOT_NULL); Assert.AreEqual("Null", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNull(null); Assert.AreEqual("Null", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNullWithMessage() { tf.AssertNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("Null", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNull(EXPECTED_MESSAGE, null); Assert.AreEqual("Null", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckFail() { tf.Fail(); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(0, Arguments.Length); } [Test] public void CheckFailWithMessage() { tf.Fail(EXPECTED_MESSAGE); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[0]); } [Test] public void CheckAssertEquals() { tf.AssertEquals(1, 1); Assert.AreEqual("Equals", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); } [Test] public void CheckAssertEqualsWithMessage() { tf.AssertEquals(EXPECTED_MESSAGE, 1, 1); Assert.AreEqual("Equals", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[2]); } [SetUp] public void BeforeEachTest() { // reset mock csUnit implementation csUnit.Assert.Reset(); // make provider stub instance tf = MakeProviderStubInstance(); } ITestFramework MakeProviderStubInstance() { csUnitStubMaker stubMaker = new csUnitStubMaker(providerAssembly); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); ITestFramework stub = (ITestFramework) Activator.CreateInstance(stubClass); return stub; } } } namespace csUnit { /// <summary> /// Mock implementation of csUnit.Assert for testing. /// </summary> public class Assert { static string _methodName; static object[] _args = null; public static string MethodName { get { return _methodName; } } public static object[] Arguments { get { return _args; } } public static void Reset() { _methodName = null; _args = null; } public static void True(bool expression) { _methodName = "True"; _args = new object[] { expression }; } public static void True(bool expression, string message) { _methodName = "True"; _args = new object[] { expression, message }; } public static void NotNull(object obj) { _methodName = "NotNull"; _args = new object[] { obj }; } public static void NotNull(object obj, string message) { _methodName = "NotNull"; _args = new object[] { obj, message }; } public static new void Equals(object expected, object actual) { _methodName = "Equals"; _args = new object[] { expected, actual }; } public static void Equals( object expected, object actual, string message ) { _methodName = "Equals"; _args = new object[] { expected, actual, message }; } public static void Fail() { _methodName = "Fail"; _args = new object[0]; } public static void Fail(string message) { _methodName = "Fail"; _args = new object[] { message }; } public static void Null(object obj) { _methodName = "Null"; _args = new object[] { obj }; } public static void Null(object obj, string message) { _methodName = "Null"; _args = new object[] { obj, message }; } } } |
From: Choy R. <ch...@us...> - 2005-01-26 01:25:53
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20700/DotNetMock Modified Files: Tag: RFE_1098585 Assertion.cs DotNetMock.csproj Log Message: Added support for dynamically generated binding for csUnit. Index: Assertion.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Assertion.cs,v retrieving revision 1.5.4.1 retrieving revision 1.5.4.2 diff -C2 -d -r1.5.4.1 -r1.5.4.2 *** Assertion.cs 25 Jan 2005 06:20:49 -0000 1.5.4.1 --- Assertion.cs 26 Jan 2005 01:24:34 -0000 1.5.4.2 *************** *** 41,44 **** --- 41,48 ---- stubMaker = new MbUnitStubMaker(providerAssembly); } + else if ( (providerAssembly = TryToLoadAssembly("csUnit"))!=null ) + { + stubMaker = new csUnitStubMaker(providerAssembly); + } if ( stubMaker==null ) { Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.30.2.1 retrieving revision 1.30.2.2 diff -C2 -d -r1.30.2.1 -r1.30.2.2 *** DotNetMock.csproj 25 Jan 2005 06:20:49 -0000 1.30.2.1 --- DotNetMock.csproj 26 Jan 2005 01:24:56 -0000 1.30.2.2 *************** *** 355,358 **** --- 355,363 ---- /> <File + RelPath = "TestFramework\csUnitStubMaker.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TestFramework\IStubMaker.cs" SubType = "Code" |
From: Choy R. <ch...@us...> - 2005-01-26 01:25:08
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20700/DotNetMock/TestFramework Added Files: Tag: RFE_1098585 csUnitStubMaker.cs Log Message: Added support for dynamically generated binding for csUnit. --- NEW FILE: csUnitStubMaker.cs --- #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 csUnit. /// </summary> public class csUnitStubMaker : AbstractStubMaker { /// <summary> /// Create csUnit stub maker. /// </summary> /// <param name="providerAssembly">csUnit assembly</param> public csUnitStubMaker( Assembly providerAssembly ) : base(providerAssembly, "csUnit.Assert") { } /// <summary> /// Implement stub methods that forward to the /// csUnit.Assert 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); // take message parameter and put it at end of parameter list bool hasMessageParameter = parameterTypes.Count>0 && typeof(string).Equals(parameterTypes[0]) ; if ( hasMessageParameter ) { parameterTypes.RemoveAt(0); parameterTypes.Add(typeof(string)); for (int i = 1; i<parameterTypes.Count; ++i) { EmitLdarg(ilg, i+1); } EmitLdarg(ilg, 1); } else { for (int i = 0; i<parameterTypes.Count; ++i) { EmitLdarg(ilg, i+1); } } string methodName = MapMethod(mi); EmitProviderCall(ilg, methodName, parameterTypes); } private string MapMethod(MethodInfo mi) { switch ( mi.Name ) { case "Assert": return "True"; case "AssertNotNull": return "NotNull"; case "AssertEquals": return "Equals"; case "Fail": return "Fail"; case "AssertNull": return "Null"; default: throw new ArgumentException(String.Format( "Cannot map method name {0}", mi.Name )); } } } } |
From: Choy R. <ch...@us...> - 2005-01-26 01:22:28
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20333/DotNetMock/TestFramework Modified Files: Tag: RFE_1098585 MbUnitStubMaker.cs Log Message: Corrected comments Index: MbUnitStubMaker.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework/Attic/MbUnitStubMaker.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 *** MbUnitStubMaker.cs 25 Jan 2005 06:20:50 -0000 1.1.2.1 --- MbUnitStubMaker.cs 26 Jan 2005 01:21:36 -0000 1.1.2.2 *************** *** 12,21 **** { /// <summary> ! /// <see cref="IStubMaker"/> for NUnit. /// </summary> public class MbUnitStubMaker : AbstractStubMaker { /// <summary> ! /// Create NUnit stub maker. /// </summary> /// <param name="providerAssembly">MbUnit.Core assembly</param> --- 12,21 ---- { /// <summary> ! /// <see cref="IStubMaker"/> for MbUnit. /// </summary> public class MbUnitStubMaker : AbstractStubMaker { /// <summary> ! /// Create MbUnit stub maker. /// </summary> /// <param name="providerAssembly">MbUnit.Core assembly</param> *************** *** 26,30 **** /// <summary> /// Implement stub methods that forward to the ! /// NUnit.Framework.Assertion class. /// </summary> /// <param name="ilg"><see cref="ILGenerator"/> for the method --- 26,30 ---- /// <summary> /// Implement stub methods that forward to the ! /// MbUnit.Core.Framework.Assert class. /// </summary> /// <param name="ilg"><see cref="ILGenerator"/> for the method |
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22568/DotNetMock/TestFramework Added Files: Tag: RFE_1098585 AbstractStubMaker.cs IStubMaker.cs MbUnitStubMaker.cs NUnitStubMaker.cs StubClassBuilder.cs Log Message: Initial implementation of dynamically generating implementations of ITestFramework on startup. So far created impls for NUnit and MbUnit. Needs some cleanup. --- NEW FILE: NUnitStubMaker.cs --- #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> public NUnitStubMaker( Assembly providerAssembly ) : base(providerAssembly, "NUnit.Framework.Assertion") { } /// <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); } } } --- NEW FILE: StubClassBuilder.cs --- #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> /// Creates stub classes that implement an interface. /// </summary> /// <author>Choy Rim</author> public class StubClassMaker { AssemblyBuilder _assemblyBuilder = null; ModuleBuilder _moduleBuilder = null; /// <summary> /// Create stub class maker. /// </summary> public StubClassMaker() { _assemblyBuilder = newAssemblyBuilder(AssemblyBuilderAccess.Run); _moduleBuilder = _assemblyBuilder.DefineDynamicModule("ProviderStub"); } /// <summary> /// /// </summary> /// <param name="supportedInterface">interface which the stub /// class will support</param> /// <param name="stubMaker">object which will generate /// method bodies</param> /// <returns>new stub class</returns> public Type MakeStubClass(Type supportedInterface, IStubMaker stubMaker) { if ( ! supportedInterface.IsInterface ) { throw new ArgumentException( "Can only stub interfaces.", "supportedInterface" ); } TypeBuilder typeBuilder = _moduleBuilder.DefineType( "ProviderStub", TypeAttributes.Public, null, new Type[] { supportedInterface } ); defineAndImplementStubMethods(typeBuilder, supportedInterface, stubMaker); Type stubClass = typeBuilder.CreateType(); return stubClass; } /// <summary> /// Define stub methods through <see cref="IStubMaker"/> /// </summary> /// <param name="typeBuilder">where to add methods</param> /// <param name="supportedInterface">interface which the stub /// class will support</param> /// <param name="stubMaker">object which will generate /// method bodies</param> private static void defineAndImplementStubMethods( TypeBuilder typeBuilder, Type supportedInterface, IStubMaker stubMaker ) { ArrayList methods = new ArrayList(); getMethodsForInterface(supportedInterface, methods); foreach (MethodInfo mi in methods) { MethodBuilder methodBuilder = typeBuilder.DefineMethod( mi.Name, MethodAttributes.Public | MethodAttributes.Virtual, mi.ReturnType, getParameterTypes(mi) ); ILGenerator ilg = methodBuilder.GetILGenerator(); stubMaker.ImplementStubMethod(ilg, mi); ilg.Emit(OpCodes.Ret); } } /// <summary> /// Returns the array of parameters types given a /// <see cref="MethodInfo"/> /// </summary> /// <param name="mi">method we want the parameter types of</param> /// <returns>array of parameter types in method signature</returns> private static Type[] getParameterTypes(MethodInfo mi) { ArrayList types = new ArrayList(); foreach (ParameterInfo pi in mi.GetParameters()) { types.Add(pi.ParameterType); } return (Type[]) types.ToArray(typeof(Type)); } private static void getMethodsForInterface(Type type, ArrayList list) { list.AddRange(type.GetMethods()); foreach (Type interfaceType in type.GetInterfaces()) { getMethodsForInterface(interfaceType, list); } } private static AssemblyBuilder newAssemblyBuilder(AssemblyBuilderAccess access) { AppDomain appDomain = AppDomain.CurrentDomain; AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "ProviderStubAssembly"; return appDomain.DefineDynamicAssembly( assemblyName, access ); } } } --- NEW FILE: AbstractStubMaker.cs --- #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> /// Abstract base class for implementations of <see cref="IStubMaker"/>. /// </summary> public abstract class AbstractStubMaker : IStubMaker { private Type _providerClass; /// <summary> /// Initialize stub maker. /// </summary> /// <param name="providerClass">class that we will /// forward all methods to</param> public AbstractStubMaker( Type providerClass ) { if ( providerClass==null ) { throw new ArgumentNullException( "providerClass", "Cannot specify null provider class" ); } _providerClass = providerClass; } /// <summary> /// Initialize a stub maker. /// </summary> /// <param name="providerAssembly">Assembly that provides /// assertion class</param> /// <param name="_providerClassName">name of assertion /// class</param> public AbstractStubMaker( Assembly providerAssembly, string _providerClassName ) : this(providerAssembly.GetType(_providerClassName, true)) { } #region IStubMaker Members /// <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> public abstract void ImplementStubMethod(ILGenerator ilg, MethodInfo mi); #endregion /// <summary> /// Get list of parameter types on a <see cref="MethodInfo"/>. /// </summary> /// <param name="mi"><see cref="MethodInfo"/> of method we're /// interested in</param> /// <returns><see cref="IList"/> of parameter types.</returns> protected static IList GetParameterTypes( MethodInfo mi ) { ArrayList types = new ArrayList(); foreach (ParameterInfo pi in mi.GetParameters()) { types.Add(pi.ParameterType); } return types; } /// <summary> /// Emit IL Call to method. /// </summary> /// <param name="ilg"><see cref="ILGenerator"/> of the method /// on the dynamically generated type</param> /// <param name="methodName">name of method to call</param> /// <param name="parameterTypeList"><see cref="IList"/> /// of parameters in method we want to call</param> protected void EmitProviderCall( ILGenerator ilg, string methodName, IList parameterTypeList ) { Type[] parameterTypes = new Type[parameterTypeList.Count]; for (int i = 0; i<parameterTypeList.Count; ++i) { parameterTypes[i] = (Type) parameterTypeList[i]; } MethodInfo mi = _providerClass.GetMethod(methodName, parameterTypes); if ( mi==null ) { throw new ArgumentException(String.Format( "Cannot find method named {0}", methodName )); } ilg.EmitCall(OpCodes.Call, mi, null); } /// <summary> /// Emit IL ldarg /// </summary> /// <param name="ilg"><see cref="ILGenerator"/> of the method /// on the dynamically generated type</param> /// <param name="argIndex">index of argument to put on /// the stack</param> protected static void EmitLdarg( ILGenerator ilg, int argIndex ) { if ( argIndex>0xff ) { ilg.Emit(OpCodes.Ldarg, (short) argIndex); return; } switch (argIndex) { case 0: ilg.Emit(OpCodes.Ldarg_0); break; case 1: ilg.Emit(OpCodes.Ldarg_1); break; case 2: ilg.Emit(OpCodes.Ldarg_2); break; case 3: ilg.Emit(OpCodes.Ldarg_3); break; default: ilg.Emit(OpCodes.Ldarg_S, (sbyte) argIndex); break; } } } } --- NEW FILE: IStubMaker.cs --- #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); } } --- NEW FILE: MbUnitStubMaker.cs --- #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 MbUnitStubMaker : AbstractStubMaker { /// <summary> /// Create NUnit stub maker. /// </summary> /// <param name="providerAssembly">MbUnit.Core assembly</param> public MbUnitStubMaker( Assembly providerAssembly ) : base(providerAssembly, "MbUnit.Core.Framework.Assert") { } /// <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); // take message parameter and put it at end of parameter list bool hasMessageParameter = parameterTypes.Count>0 && typeof(string).Equals(parameterTypes[0]) ; if ( hasMessageParameter ) { parameterTypes.RemoveAt(0); parameterTypes.Add(typeof(string)); for (int i = 1; i<parameterTypes.Count; ++i) { EmitLdarg(ilg, i+1); } EmitLdarg(ilg, 1); parameterTypes.Add(typeof(object[])); ilg.Emit(OpCodes.Ldnull); } else { for (int i = 0; i<parameterTypes.Count; ++i) { EmitLdarg(ilg, i+1); } } string methodName = MapMethod(mi); EmitProviderCall(ilg, methodName, parameterTypes); } private string MapMethod(MethodInfo mi) { switch ( mi.Name ) { case "Assert": return "IsTrue"; case "AssertNotNull": return "IsNotNull"; case "AssertEquals": return "AreEqual"; case "Fail": return "Fail"; case "AssertNull": return "IsNull"; default: throw new ArgumentException(String.Format( "Cannot map method name {0}", mi.Name )); } } } } |
From: Choy R. <ch...@us...> - 2005-01-25 06:21:03
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22568/DotNetMock Modified Files: Tag: RFE_1098585 Assertion.cs DotNetMock.csproj Log Message: Initial implementation of dynamically generating implementations of ITestFramework on startup. So far created impls for NUnit and MbUnit. Needs some cleanup. Index: Assertion.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Assertion.cs,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -C2 -d -r1.5 -r1.5.4.1 *** Assertion.cs 9 Oct 2004 21:14:12 -0000 1.5 --- Assertion.cs 25 Jan 2005 06:20:49 -0000 1.5.4.1 *************** *** 1,7 **** --- 1,9 ---- using System; using System.Configuration; + using System.IO; using System.Reflection; using System.Runtime.Remoting; using DotNetMock.Core; + using DotNetMock.TestFramework; namespace DotNetMock *************** *** 28,39 **** if ( ( iTestFrameworkAssembly == null ) || ( iTestFrameworkAssembly.Equals( String.Empty ) ) ) { ! iTestFrameworkAssembly = "DotNetMock.NUnit"; ! } ! if ( ( iTestFrameworkComponent == null ) || ( iTestFrameworkComponent.Equals( String.Empty ) ) ) { ! iTestFrameworkComponent = "DotNetMock.NUnit.NUnitTestFramework"; } - ObjectHandle concreteObject = Activator.CreateInstance( iTestFrameworkAssembly, iTestFrameworkComponent ); - _testFramework = (ITestFramework)concreteObject.Unwrap(); } /// <summary> --- 30,62 ---- if ( ( iTestFrameworkAssembly == null ) || ( iTestFrameworkAssembly.Equals( String.Empty ) ) ) { ! StubClassMaker classMaker = new StubClassMaker(); ! IStubMaker stubMaker = null; ! Assembly providerAssembly = null; ! if ( (providerAssembly = TryToLoadAssembly("nunit.framework"))!=null ) ! { ! stubMaker = new NUnitStubMaker(providerAssembly); ! } ! else if ( (providerAssembly = TryToLoadAssembly("MbUnit.Core"))!=null ) ! { ! stubMaker = new MbUnitStubMaker(providerAssembly); ! } ! if ( stubMaker==null ) ! { ! throw new InvalidOperationException( ! "Cannot find a testing framework" ! ); ! } ! Type stubClass = classMaker.MakeStubClass( ! typeof(ITestFramework), ! stubMaker ! ); ! _testFramework = (ITestFramework) ! Activator.CreateInstance(stubClass); ! } ! else { ! ObjectHandle concreteObject = Activator.CreateInstance( iTestFrameworkAssembly, iTestFrameworkComponent ); ! _testFramework = (ITestFramework)concreteObject.Unwrap(); } } /// <summary> *************** *** 179,182 **** --- 202,217 ---- } } + + private static Assembly TryToLoadAssembly(string assemblyName) + { + try + { + return Assembly.LoadWithPartialName(assemblyName); + } + catch (FileNotFoundException) + { + return null; + } + } } } Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.30 retrieving revision 1.30.2.1 diff -C2 -d -r1.30 -r1.30.2.1 *** DotNetMock.csproj 9 Jan 2005 06:48:35 -0000 1.30 --- DotNetMock.csproj 25 Jan 2005 06:20:49 -0000 1.30.2.1 *************** *** 40,44 **** RegisterForComInterop = "false" RemoveIntegerChecks = "false" ! TreatWarningsAsErrors = "true" WarningLevel = "4" /> --- 40,44 ---- RegisterForComInterop = "false" RemoveIntegerChecks = "false" ! TreatWarningsAsErrors = "false" WarningLevel = "4" /> *************** *** 349,352 **** --- 349,377 ---- BuildAction = "Compile" /> + <File + RelPath = "TestFramework\AbstractStubMaker.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TestFramework\IStubMaker.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TestFramework\MbUnitStubMaker.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TestFramework\NUnitStubMaker.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "TestFramework\StubClassBuilder.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> |
From: Choy R. <ch...@us...> - 2005-01-25 06:21:03
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22568/DotNetMock.TestFramework.Tests Added Files: Tag: RFE_1098585 .cvsignore AssemblyInfo.cs DotNetMock.TestFramework.Tests.csproj MbUnitStubMakerTests.cs NUnitStubMakerTests.cs StubClassMakerTests.cs Log Message: Initial implementation of dynamically generating implementations of ITestFramework on startup. So far created impls for NUnit and MbUnit. Needs some cleanup. --- NEW FILE: .cvsignore --- bin obj *.csproj.user --- NEW FILE: NUnitStubMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class NUnitStubMakerTests { [Test] public void Basic() { Assembly providerAssembly = Assembly.Load("nunit.framework"); NUnitStubMaker stubMaker = new NUnitStubMaker(providerAssembly); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); ITestFramework tf = (ITestFramework) Activator.CreateInstance(stubClass); tf.Assert(true); tf.AssertEquals(1, 1); } } } --- NEW FILE: DotNetMock.TestFramework.Tests.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "DotNetMock.TestFramework.Tests" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "DotNetMock.TestFramework.Tests" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "DotNetMock.Core" Project = "{5666DF57-5109-4C5F-967D-EEDC554B8E55}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "DotNetMock" Project = "{1AD0CD00-16FA-4456-B2ED-A47406957228}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "nunit.framework" AssemblyName = "nunit.framework" HintPath = "..\lib\nunit.framework.dll" Private = "True" /> </References> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "MbUnitStubMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "NUnitStubMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "StubClassMakerTests.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: MbUnitStubMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; using DotNetMock.Core; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class MbUnitStubMakerTests { static readonly Assembly providerAssembly = Assembly.GetExecutingAssembly(); const string EXPECTED_MESSAGE = "MESSAGE"; const string NOT_NULL = "NOT-NULL"; ITestFramework tf; static string MethodName { get { return MbUnit.Core.Framework.Assert.MethodName; } } static object[] Arguments { get { return MbUnit.Core.Framework.Assert.Arguments; } } [Test] public void CheckAssert() { tf.Assert(true); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(true, Arguments[0]); tf.Assert(false); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreEqual(false, Arguments[0]); } [Test] public void CheckAssertWithMessage() { tf.Assert(EXPECTED_MESSAGE, true); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreEqual(true, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.Assert(EXPECTED_MESSAGE, false); Assert.AreEqual("IsTrue", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreEqual(false, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNotNull() { tf.AssertNotNull(NOT_NULL); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNotNull(null); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNotNullWithMessage() { tf.AssertNotNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNotNull(EXPECTED_MESSAGE, null); Assert.AreEqual("IsNotNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckAssertNull() { tf.AssertNull(NOT_NULL); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); tf.AssertNull(null); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(1, Arguments.Length); Assert.IsNull(Arguments[0]); } [Test] public void CheckAssertNullWithMessage() { tf.AssertNull(EXPECTED_MESSAGE, NOT_NULL); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.AreSame(NOT_NULL, Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); tf.AssertNull(EXPECTED_MESSAGE, null); Assert.AreEqual("IsNull", MethodName); Assert.AreEqual(3, Arguments.Length); Assert.IsNull(Arguments[0]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[1]); } [Test] public void CheckFail() { tf.Fail(); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(0, Arguments.Length); } [Test] public void CheckFailWithMessage() { tf.Fail(EXPECTED_MESSAGE); Assert.AreEqual("Fail", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[0]); } [Test] public void CheckAssertEquals() { tf.AssertEquals(1, 1); Assert.AreEqual("AreEqual", MethodName); Assert.AreEqual(2, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); } [Test] public void CheckAssertEqualsWithMessage() { tf.AssertEquals(EXPECTED_MESSAGE, 1, 1); Assert.AreEqual("AreEqual", MethodName); Assert.AreEqual(4, Arguments.Length); Assert.AreEqual(1, Arguments[0]); Assert.AreEqual(1, Arguments[1]); Assert.AreEqual(EXPECTED_MESSAGE, Arguments[2]); } [SetUp] public void BeforeEachTest() { // reset mock MbUnit implementation MbUnit.Core.Framework.Assert.Reset(); // make provider stub instance tf = MakeProviderStubInstance(); } ITestFramework MakeProviderStubInstance() { MbUnitStubMaker stubMaker = new MbUnitStubMaker(providerAssembly); StubClassMaker scm = new StubClassMaker(); Type stubClass = scm.MakeStubClass(typeof(ITestFramework), stubMaker); ITestFramework stub = (ITestFramework) Activator.CreateInstance(stubClass); return stub; } } } namespace MbUnit.Core.Framework { /// <summary> /// Mock implementation of MbUnit.Core.Framework.Assert for testing. /// </summary> public class Assert { static string _methodName; static object[] _args = null; public static string MethodName { get { return _methodName; } } public static object[] Arguments { get { return _args; } } public static void Reset() { _methodName = null; _args = null; } public static void IsTrue(bool assertion) { _methodName = "IsTrue"; _args = new object[] { assertion }; } public static void IsTrue(bool assertion, string format, params object[] args) { _methodName = "IsTrue"; _args = new object[] { assertion, format, args }; } public static void IsNotNull(object nullable) { _methodName = "IsNotNull"; _args = new object[] { nullable }; } public static void IsNotNull(object nullable, string format, params object[] args) { _methodName = "IsNotNull"; _args = new object[] { nullable, format, args }; } public static void AreEqual(object expected, object actual) { _methodName = "AreEqual"; _args = new object[] { expected, actual }; } public static void AreEqual( object expected, object actual, string format, params object[] args ) { _methodName = "AreEqual"; _args = new object[] { expected, actual, format, args }; } public static void Fail() { _methodName = "Fail"; _args = new object[0]; } public static void Fail(string format, params object[] args) { _methodName = "Fail"; _args = new object[] { format, args }; } public static void IsNull(object nullable) { _methodName = "IsNull"; _args = new object[] { nullable }; } public static void IsNull(object nullable, string format, params object[] args) { _methodName = "IsNull"; _args = new object[] { nullable, format, args }; } } } --- NEW FILE: StubClassMakerTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using DotNetMock.TestFramework; #endregion namespace DotNetMock.TestFramework.Tests { [TestFixture] public class StubClassMakerTests { static bool CalledMethod1; interface ITrivialProvider { void Method1(); } class TrivialStubMaker : AbstractStubMaker { public TrivialStubMaker() : base(typeof(StubClassMakerTests)) { } public override void ImplementStubMethod(ILGenerator ilg, MethodInfo mi) { EmitProviderCall(ilg, "RealMethod1", new Type[0]); } } public static void RealMethod1() { CalledMethod1 = true; } [Test] public void TrivialProviderInterface() { StubClassMaker classBuilder = new StubClassMaker(); TrivialStubMaker tsm = new TrivialStubMaker(); Type stubClass = classBuilder.MakeStubClass( typeof(ITrivialProvider), tsm ); ITrivialProvider provider = (ITrivialProvider) Activator.CreateInstance(stubClass); provider.Method1(); Assert.IsTrue(CalledMethod1); } [SetUp] public void BeforeEachTest() { CalledMethod1 = false; } } } --- 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("")] |
From: Choy R. <ch...@us...> - 2005-01-25 06:21:02
|
Update of /cvsroot/dotnetmock/dotnetmock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22568 Modified Files: Tag: RFE_1098585 DotNetMock.sln Log Message: Initial implementation of dynamically generating implementations of ITestFramework on startup. So far created impls for NUnit and MbUnit. Needs some cleanup. Index: DotNetMock.sln =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.sln,v retrieving revision 1.14 retrieving revision 1.14.4.1 diff -C2 -d -r1.14 -r1.14.4.1 *** DotNetMock.sln 10 Oct 2004 07:56:43 -0000 1.14 --- DotNetMock.sln 25 Jan 2005 06:20:49 -0000 1.14.4.1 *************** *** 36,39 **** --- 36,43 ---- EndProjectSection EndProject + Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetMock.TestFramework.Tests", "DotNetMock.TestFramework.Tests\DotNetMock.TestFramework.Tests.csproj", "{6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection + EndProject Global GlobalSection(SolutionConfiguration) = preSolution *************** *** 78,81 **** --- 82,89 ---- {C7009DB3-7238-4608-AB9A-DB4927361898}.Release.ActiveCfg = Release|.NET {C7009DB3-7238-4608-AB9A-DB4927361898}.Release.Build.0 = Release|.NET + {6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}.Debug.ActiveCfg = Debug|.NET + {6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}.Debug.Build.0 = Debug|.NET + {6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}.Release.ActiveCfg = Release|.NET + {6C2904D4-ADCC-4980-AED0-64A8C6F3AF69}.Release.Build.0 = Release|.NET EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution |
From: Choy R. <ch...@us...> - 2005-01-25 06:21:02
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22568/DotNetMock.Tests Modified Files: Tag: RFE_1098585 DotNetMock.Tests.csproj Log Message: Initial implementation of dynamically generating implementations of ITestFramework on startup. So far created impls for NUnit and MbUnit. Needs some cleanup. Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.15 retrieving revision 1.15.2.1 diff -C2 -d -r1.15 -r1.15.2.1 *** DotNetMock.Tests.csproj 9 Jan 2005 21:05:05 -0000 1.15 --- DotNetMock.Tests.csproj 25 Jan 2005 06:20:48 -0000 1.15.2.1 *************** *** 89,92 **** --- 89,93 ---- AssemblyName = "nunit.framework" HintPath = "..\lib\nunit.framework.dll" + Private = "False" /> </References> |
From: Choy R. <ch...@us...> - 2005-01-25 06:11:23
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21176/TestFramework Log Message: Directory /cvsroot/dotnetmock/dotnetmock/DotNetMock/TestFramework added to the repository --> Using per-directory sticky tag `RFE_1098585' |
From: Choy R. <ch...@us...> - 2005-01-25 06:11:00
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21081/DotNetMock.TestFramework.Tests Log Message: Directory /cvsroot/dotnetmock/dotnetmock/DotNetMock.TestFramework.Tests added to the repository --> Using per-directory sticky tag `RFE_1098585' |
From: Choy R. <ch...@us...> - 2005-01-09 21:05:17
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7705/DotNetMock.Tests Modified Files: DotNetMock.Tests.csproj Log Message: Factored out common tests from the two DynamicMock classes. Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** DotNetMock.Tests.csproj 5 Jan 2005 00:29:17 -0000 1.14 --- DotNetMock.Tests.csproj 9 Jan 2005 21:05:05 -0000 1.15 *************** *** 160,163 **** --- 160,168 ---- /> <File + RelPath = "Dynamic\AbstractDynamicMockTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\AssignTests.cs" SubType = "Code" |
From: Choy R. <ch...@us...> - 2005-01-09 21:05:17
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7705/DotNetMock.Tests/Dynamic Modified Files: DynamicMockTests.cs DynamicOrderedMockTests.cs Added Files: AbstractDynamicMockTests.cs Log Message: Factored out common tests from the two DynamicMock classes. Index: DynamicMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicMockTests.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** DynamicMockTests.cs 1 Jan 2005 22:57:51 -0000 1.17 --- DynamicMockTests.cs 9 Jan 2005 21:05:05 -0000 1.18 *************** *** 1,4 **** #region License ! // need license #endregion #region Imports --- 1,4 ---- #region License ! // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports *************** *** 14,78 **** { [TestFixture] ! public class DynamicMockTests { ! private IDynamicMock mock; ! private MethodInfo myMethod; ! private MethodInfo myMethod1; ! private MethodInfo myMethod2; ! private MethodInfo myMethod3; ! private MethodInfo anotherMethod; ! ! interface IBlah { ! object DoStuff(string name); ! object DoStuffWithParams( string id, params string[] names ); ! bool DoStuffBooleanStyle( bool flag ); ! void MethodWithOutParameter(out string p1); ! void MethodWithRefParameter(ref string p1); ! ! void myMethod(); ! void myMethod1(); ! void myMethod2(); ! void myMethod3(); ! void anotherMethod(); } ! ! [SetUp] public void BeforeEachTest() { ! mock = new DynamicMock("mymock"); ! myMethod = typeof(IBlah).GetMethod("myMethod", new Type[0]); ! myMethod1 = typeof(IBlah).GetMethod("myMethod1", new Type[0]); ! myMethod2 = typeof(IBlah).GetMethod("myMethod2", new Type[0]); ! myMethod3 = typeof(IBlah).GetMethod("myMethod3", new Type[0]); ! anotherMethod = typeof(IBlah).GetMethod("anotherMethod", new Type[0]); } [Test] ! public void SetsRefParameter() { ! IDynamicMock mock = new DynamicMock(typeof(IBlah)); ! IBlah blah = (IBlah) mock.Object; ! string p1 = "hello"; ! mock.Expect("MethodWithRefParameter", ! new Assign("goodbye").AndRequire(new IsEqual("hello")) ! ); ! ! blah.MethodWithRefParameter(ref p1); ! Assertion.AssertEquals("goodbye", p1); mock.Verify(); } [Test] ! public void SetsOutParameter() { ! IDynamicMock mock = new DynamicMock(typeof(IBlah)); ! IBlah blah = (IBlah) mock.Object; ! string p1 = null; ! mock.Expect("MethodWithOutParameter", ! new Assign("hello") ! ); ! ! blah.MethodWithOutParameter(out p1); ! Assertion.AssertEquals("hello", p1); mock.Verify(); } --- 14,49 ---- { [TestFixture] ! public class DynamicMockTests : AbstractDynamicMockTests { ! protected override IDynamicMock newDynamicMock(Type type, string name) { ! return new DynamicMock(type, name); } ! protected override IDynamicMock newDynamicMock(Type type) { ! return new DynamicMock(type); ! } ! protected override IDynamicMock newDynamicMock(string name) ! { ! return new DynamicMock(name); } [Test] ! public void CallMultipleMethodsInWrongOrder() { ! mock.Expect("myMethod1"); ! mock.Expect("myMethod2"); ! mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod3); ! mock.Call(myMethod2); mock.Verify(); } [Test] ! [ExpectedException(typeof(AssertionException), "1 more call(s) were expected for myMethod")] ! public void NoCallToVoidMethodWithReason() { ! mock.Expect("myMethod"); mock.Verify(); } *************** *** 82,86 **** public void ThrowsIfUnexpectedMethodCalled() { ! IDynamicMock mock = new DynamicMock(typeof(IBlah)); IBlah blah = (IBlah) mock.Object; mock.Strict = true; --- 53,57 ---- public void ThrowsIfUnexpectedMethodCalled() { ! IDynamicMock mock = newDynamicMock(typeof(IBlah)); IBlah blah = (IBlah) mock.Object; mock.Strict = true; *************** *** 92,117 **** } - [Test] - public void DefaultDynamicMock() - { - IDynamicMock mock = new DynamicMock(typeof(IBlah)); - Assertion.AssertEquals("MockBlah", mock.MockName); - - mock.ExpectAndReturn("DoStuff", "world", "hello"); - - IBlah blah = (IBlah)mock.Object; - Assertion.AssertEquals("world", blah.DoStuff("hello")); - - mock.Verify(); - } - - [Test] - public void NamedDynamicMock() - { - IDynamicMock mock = new DynamicMock(typeof(IBlah), "XBlah"); - Assertion.AssertEquals("XBlah", mock.MockName); - mock.Verify(); - } - [Test] public void CustomDynamicMock() --- 63,66 ---- *************** *** 122,157 **** mock.Verify(); } - [Test] - public void CustomDynamicMockWithBool() - { - IDynamicMock mock = new DynamicMock( typeof(IBlah), "XBlah" ); - mock.ExpectAndReturn( "DoStuffBooleanStyle", false, true ); - IBlah blah = (IBlah) mock.Object; - Assertion.AssertEquals( false, blah.DoStuffBooleanStyle( true ) ); - mock.Verify(); - } - [Test] - public void DynamicMockWithParams() - { - IDynamicMock mock = new DynamicMock(typeof(IBlah)); - mock.ExpectAndReturn( "DoStuffWithParams", "world2", "12345", new string[] {"hello" } ); - - IBlah blah = (IBlah)mock.Object; - - Assertion.AssertEquals( "world2", blah.DoStuffWithParams("12345", "hello") ); - mock.Verify(); - - } - [Test] - public void DynamicMockWithManyParams() - { - IDynamicMock mock = new DynamicMock(typeof(IBlah)); - mock.ExpectAndReturn( "DoStuffWithParams", "world2", "12345", new string[] { "hello", "dotnetmock" } ); - - IBlah blah = (IBlah)mock.Object; - - Assertion.AssertEquals( "world2", blah.DoStuffWithParams("12345", "hello", "dotnetmock") ); - mock.Verify(); - } private class CustomMock : DynamicMock { --- 71,74 ---- *************** *** 163,377 **** } } - [Test] - public void Name() - { - Assertion.AssertEquals("mymock", mock.MockName); - } - - [Test] - public void NewMockVerifies() - { - mock.Verify(); - } - - [Test] - public void CallToVoidMethod() - { - mock.Expect("myMethod"); - mock.Call(myMethod); - mock.Verify(); - } - [Test] - [ExpectedException(typeof(AssertionException))] - public void NoCallToVoidMethod() - { - mock.Expect("myMethod"); - mock.Verify(); - } - [Test] - [ExpectedException(typeof(AssertionException), "1 more call(s) were expected for myMethod")] - public void NoCallToVoidMethodWithReason() - { - mock.Expect("myMethod"); - mock.Verify(); - } - - [Test] - [ExpectedException(typeof(AssertionException))] - public void TooManyCallsToVoidMethod() - { - mock.Expect("myMethod"); - mock.Call(myMethod); - mock.Call(myMethod); - } - - [Test] - public void ManyCallsToVoidMethod() - { - mock.Expect("myMethod"); - mock.Expect("myMethod"); - mock.Expect("myMethod"); - mock.Call(myMethod); - mock.Call(myMethod); - mock.Call(myMethod); - mock.Verify(); - } - - [Test] - public void CallToMethodWithParams() - { - mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); - mock.Call(myMethod, "hello", null); - mock.Verify(); - } - [Test] - [ExpectedException(typeof(DotNetMock.AssertionException))] - public void CallToMethodWithInvalidParams() - { - mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); - mock.Call(myMethod, "world", null); - } - - [Test] - public void CallToMethodWithParamsButNotCheckingValues() - { - mock.Expect("myMethod"); - mock.Call(myMethod, "world", null); - mock.Verify(); - } - - [Test] - public void CallMultipleMethods() - { - mock.Expect("myMethod1"); - mock.Expect("myMethod2"); - mock.Expect("myMethod3"); - mock.Call(myMethod1); - mock.Call(myMethod2); - mock.Call(myMethod3); - mock.Verify(); - } - - [Test] - public void CallMultipleMethodsInWrongOrder() - { - mock.Expect("myMethod1"); - mock.Expect("myMethod2"); - mock.Expect("myMethod3"); - mock.Call(myMethod1); - mock.Call(myMethod3); - mock.Call(myMethod2); - mock.Verify(); - } - - [Test] - public void CallToNonVoidMethod() - { - object something = new object(); - mock.ExpectAndReturn("myMethod", something); - object result = mock.Call(myMethod); - mock.Verify(); - Assertion.AssertEquals(something, result); - } - - [Test] - public void CallToNonVoidMethodWithParams() - { - object something = new object(); - mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); - object result = mock.Call(myMethod, "hello"); - mock.Verify(); - Assertion.AssertEquals(something, result); - } - - [Test] - [ExpectedException(typeof(AssertionException))] - public void CallToNonVoidMethodWithWrongParams() - { - object something = new object(); - mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); - object result = mock.Call(myMethod, "bye"); - mock.Verify(); - Assertion.AssertEquals(something, result); - } - - [Test] - public void MultipleCallToNonVoidMethod() - { - object something = new object(); - object anotherthing = new object(); - int x = 3; - mock.ExpectAndReturn("myMethod", something); - mock.ExpectAndReturn("myMethod", anotherthing); - mock.ExpectAndReturn("myMethod", x); - Assertion.AssertEquals(something, mock.Call(myMethod)); - Assertion.AssertEquals(anotherthing, mock.Call(myMethod)); - Assertion.AssertEquals(x, mock.Call(myMethod)); - mock.Verify(); - } - - [Test] - public void CallToNonVoidMethodReturningNull() - { - mock.ExpectAndReturn("myMethod", null); - Assertion.AssertNull(mock.Call(myMethod)); - mock.Verify(); - } - - [Test] - public void DefaultEqualsPredicates() - { - object o = new object(); - mock.Expect("myMethod", o); - mock.Call(myMethod, o); - } - - [Test] - [ExpectedException(typeof(AssertionException))] - public void DefaultEqualsPredicatesFailure() - { - mock.Expect("myMethod", new object()); - mock.Call(myMethod, new object()); - } - - [Test] - public void DefaultAnythingPredicates() - { - mock.Expect("myMethod", null, null); - mock.Expect("myMethod", null, "zzz"); - mock.Expect("myMethod", "zzz", null); - mock.Call(myMethod, "???", "???"); - mock.Call(myMethod, "???", "zzz"); - mock.Call(myMethod, "zzz", "???"); - } - - [Test] - public void FixedValue() - { - mock.SetValue("myMethod", "hello"); - mock.SetValue("anotherMethod", "world"); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("world", mock.Call(anotherMethod)); - Assertion.AssertEquals("world", mock.Call(anotherMethod)); - mock.SetValue("myMethod", "bye"); - Assertion.AssertEquals("bye", mock.Call(myMethod)); - Assertion.AssertEquals("bye", mock.Call(myMethod)); - Assertion.AssertEquals("world", mock.Call(anotherMethod)); - mock.SetValue("myMethod", null); - Assertion.AssertNull(mock.Call(myMethod)); - Assertion.AssertNull(mock.Call(myMethod)); - mock.Verify(); - } - - [Test] - [ExpectedException(typeof(System.IO.IOException))] - public void CallThrowingException() - { - mock.ExpectAndThrow("myMethod", new System.IO.IOException()); - mock.Call(myMethod); - } } } --- 80,83 ---- Index: DynamicOrderedMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicOrderedMockTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** DynamicOrderedMockTests.cs 1 Jan 2005 22:57:51 -0000 1.5 --- DynamicOrderedMockTests.cs 9 Jan 2005 21:05:06 -0000 1.6 *************** *** 1,2 **** --- 1,6 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Reflection; *************** *** 4,125 **** using NUnit.Framework; using DotNetMock.Dynamic; namespace DotNetMock.Tests.Dynamic { [TestFixture] ! public class DynamicOrderedMockTest { ! private MethodInfo myMethod; ! private MethodInfo myMethod1; ! private MethodInfo myMethod2; ! private MethodInfo myMethod3; ! private MethodInfo anotherMethod; ! ! interface IBlah ! { ! object DoStuff(string name); ! ! void myMethod(); ! void myMethod1(); ! void myMethod2(); ! void myMethod3(); ! void anotherMethod(); ! } ! private IDynamicMock mock; ! ! [SetUp] ! public void SetUp() ! { ! mock = new DynamicOrderedMock("mymock"); ! myMethod = typeof(IBlah).GetMethod("myMethod", new Type[0]); ! myMethod1 = typeof(IBlah).GetMethod("myMethod1", new Type[0]); ! myMethod2 = typeof(IBlah).GetMethod("myMethod2", new Type[0]); ! myMethod3 = typeof(IBlah).GetMethod("myMethod3", new Type[0]); ! anotherMethod = typeof(IBlah).GetMethod("anotherMethod", new Type[0]); ! } ! ! [Test] ! public void Name() ! { ! Assertion.AssertEquals("mymock", mock.MockName); ! } ! ! [Test] ! public void NewMockVerifies() ! { ! mock.Verify(); ! } ! ! [Test] ! public void CallToVoidMethod() ! { ! mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Verify(); ! } ! ! [Test] ! [ExpectedException(typeof(AssertionException))] ! public void NoCallToVoidMethod() ! { ! mock.Expect("myMethod"); ! mock.Verify(); ! } ! ! [Test] ! [ExpectedException(typeof(AssertionException))] ! public void TooManyCallsToVoidMethod() ! { ! mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Call(myMethod); ! } ! ! [Test] ! public void ManyCallsToVoidMethod() ! { ! mock.Expect("myMethod"); ! mock.Expect("myMethod"); ! mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Call(myMethod); ! mock.Call(myMethod); ! mock.Verify(); ! } ! ! [Test] ! public void CallToMethodWithParams() ! { ! mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call(myMethod, "hello", null); ! mock.Verify(); ! } ! ! [Test] ! [ExpectedException(typeof(DotNetMock.AssertionException))] ! public void CallToMethodWithInvalidParams() { ! mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call(myMethod, "world", null); } ! ! [Test] ! public void CallToMethodWithParamsButNotCheckingValues() { ! mock.Expect("myMethod"); ! mock.Call(myMethod, "world", null); ! mock.Verify(); } ! ! [Test] ! public void CallMultipleMethods() { ! mock.Expect("myMethod1"); ! mock.Expect("myMethod2"); ! mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod2); ! mock.Call(myMethod3); ! mock.Verify(); } --- 8,29 ---- using NUnit.Framework; using DotNetMock.Dynamic; + #endregion namespace DotNetMock.Tests.Dynamic { [TestFixture] ! public class DynamicOrderedMockTests : AbstractDynamicMockTests { ! protected override IDynamicMock newDynamicMock(Type type, string name) { ! return new DynamicOrderedMock(type, name); } ! protected override IDynamicMock newDynamicMock(Type type) { ! return new DynamicOrderedMock(type); } ! protected override IDynamicMock newDynamicMock(string name) { ! return new DynamicOrderedMock(name); } *************** *** 137,271 **** } - [Test] - public void CallToNonVoidMethod() - { - object something = new object(); - mock.ExpectAndReturn("myMethod", something); - object result = mock.Call(myMethod); - mock.Verify(); - Assertion.AssertEquals(something, result); - } - - [Test] - public void CallToNonVoidMethodWithParams() - { - object something = new object(); - mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); - object result = mock.Call(myMethod, "hello"); - mock.Verify(); - Assertion.AssertEquals(something, result); - } - - [Test] - [ExpectedException(typeof(AssertionException))] - public void CallToNonVoidMethodWithWrongParams() - { - object something = new object(); - mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); - object result = mock.Call(myMethod, "bye"); - mock.Verify(); - Assertion.AssertEquals(something, result); - } - - [Test] - public void MultipleCallToNonVoidMethod() - { - object something = new object(); - object anotherthing = new object(); - int x = 3; - mock.ExpectAndReturn("myMethod", something); - mock.ExpectAndReturn("myMethod", anotherthing); - mock.ExpectAndReturn("myMethod", x); - Assertion.AssertEquals(something, mock.Call(myMethod)); - Assertion.AssertEquals(anotherthing, mock.Call(myMethod)); - Assertion.AssertEquals(x, mock.Call(myMethod)); - mock.Verify(); - } - - [Test] - public void CallToNonVoidMethodReturningNull() - { - mock.ExpectAndReturn("myMethod", null); - Assertion.AssertNull(mock.Call(myMethod)); - mock.Verify(); - } - - [Test] - public void DefaultEqualsPredicates() - { - object o = new object(); - mock.Expect("myMethod", o); - mock.Call(myMethod, o); - } - - [Test] - [ExpectedException(typeof(AssertionException))] - public void DefaultEqualsPredicatesFailure() - { - mock.Expect("myMethod", new object()); - mock.Call(myMethod, new object()); - } - - [Test] - public void DefaultAnythingPredicates() - { - mock.Expect("myMethod", null, null); - mock.Expect("myMethod", null, "zzz"); - mock.Expect("myMethod", "zzz", null); - mock.Call(myMethod, "???", "???"); - mock.Call(myMethod, "???", "zzz"); - mock.Call(myMethod, "zzz", "???"); - } - - [Test] - public void FixedValue() - { - mock.SetValue("myMethod", "hello"); - mock.SetValue("anotherMethod", "world"); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("hello", mock.Call(myMethod)); - Assertion.AssertEquals("world", mock.Call(anotherMethod)); - Assertion.AssertEquals("world", mock.Call(anotherMethod)); - mock.SetValue("myMethod", "bye"); - Assertion.AssertEquals("bye", mock.Call(myMethod)); - Assertion.AssertEquals("bye", mock.Call(myMethod)); - Assertion.AssertEquals("world", mock.Call(anotherMethod)); - mock.SetValue("myMethod", null); - Assertion.AssertNull(mock.Call(myMethod)); - Assertion.AssertNull(mock.Call(myMethod)); - mock.Verify(); - } - - [Test] - [ExpectedException(typeof(System.IO.IOException))] - public void CallThrowingException() - { - mock.ExpectAndThrow("myMethod", new System.IO.IOException()); - mock.Call(myMethod); - } - [Test] - public void DefaultDynamicMock() - { - IDynamicMock mock = new DynamicOrderedMock(typeof(IBlah)); - Assertion.AssertEquals("MockBlah", mock.MockName); - - mock.ExpectAndReturn("DoStuff", "world", "hello"); - - IBlah blah = (IBlah)mock.Object; - Assertion.AssertEquals("world", blah.DoStuff("hello")); - - mock.Verify(); - } - - [Test] - public void NamedDynamicMock() - { - IDynamicMock mock = new DynamicOrderedMock(typeof(IBlah), "XBlah"); - Assertion.AssertEquals("XBlah", mock.MockName); - mock.Verify(); - } - [Test] public void CustomDynamicMock() --- 41,44 ---- --- NEW FILE: AbstractDynamicMockTests.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; using DotNetMock.Dynamic; using NUnit.Framework; using DotNetMock.Dynamic.Predicates; #endregion namespace DotNetMock.Tests.Dynamic { [TestFixture] public abstract class AbstractDynamicMockTests { protected IDynamicMock mock; protected MethodInfo myMethod; protected MethodInfo myMethod1; protected MethodInfo myMethod2; protected MethodInfo myMethod3; protected MethodInfo anotherMethod; /// <summary> /// Create instance of <see cref="IDynamicMock"/> to test. /// </summary> protected abstract IDynamicMock newDynamicMock(Type type, string name); protected abstract IDynamicMock newDynamicMock(Type type); protected abstract IDynamicMock newDynamicMock(string name); protected interface IBlah { object DoStuff(string name); object DoStuffWithParams( string id, params string[] names ); bool DoStuffBooleanStyle( bool flag ); void MethodWithOutParameter(out string p1); void MethodWithRefParameter(ref string p1); void myMethod(); void myMethod1(); void myMethod2(); void myMethod3(); void anotherMethod(); } [SetUp] public void BeforeEachTest() { mock = newDynamicMock("mymock"); myMethod = typeof(IBlah).GetMethod("myMethod", new Type[0]); myMethod1 = typeof(IBlah).GetMethod("myMethod1", new Type[0]); myMethod2 = typeof(IBlah).GetMethod("myMethod2", new Type[0]); myMethod3 = typeof(IBlah).GetMethod("myMethod3", new Type[0]); anotherMethod = typeof(IBlah).GetMethod("anotherMethod", new Type[0]); } [Test] public void SetsRefParameter() { IDynamicMock mock = newDynamicMock(typeof(IBlah)); IBlah blah = (IBlah) mock.Object; string p1 = "hello"; mock.Expect("MethodWithRefParameter", new Assign("goodbye").AndRequire(new IsEqual("hello")) ); blah.MethodWithRefParameter(ref p1); Assertion.AssertEquals("goodbye", p1); mock.Verify(); } [Test] public void SetsOutParameter() { IDynamicMock mock = newDynamicMock(typeof(IBlah)); IBlah blah = (IBlah) mock.Object; string p1 = null; mock.Expect("MethodWithOutParameter", new Assign("hello") ); blah.MethodWithOutParameter(out p1); Assertion.AssertEquals("hello", p1); mock.Verify(); } [Test] public void DefaultDynamicMock() { IDynamicMock mock = newDynamicMock(typeof(IBlah)); Assertion.AssertEquals("MockBlah", mock.MockName); mock.ExpectAndReturn("DoStuff", "world", "hello"); IBlah blah = (IBlah)mock.Object; Assertion.AssertEquals("world", blah.DoStuff("hello")); mock.Verify(); } [Test] public void NamedDynamicMock() { IDynamicMock mock = newDynamicMock(typeof(IBlah), "XBlah"); Assertion.AssertEquals("XBlah", mock.MockName); mock.Verify(); } [Test] public void CustomDynamicMockWithBool() { IDynamicMock mock = newDynamicMock( typeof(IBlah), "XBlah" ); mock.ExpectAndReturn( "DoStuffBooleanStyle", false, true ); IBlah blah = (IBlah) mock.Object; Assertion.AssertEquals( false, blah.DoStuffBooleanStyle( true ) ); mock.Verify(); } [Test] public void DynamicMockWithParams() { IDynamicMock mock = newDynamicMock(typeof(IBlah)); mock.ExpectAndReturn( "DoStuffWithParams", "world2", "12345", new string[] {"hello" } ); IBlah blah = (IBlah)mock.Object; Assertion.AssertEquals( "world2", blah.DoStuffWithParams("12345", "hello") ); mock.Verify(); } [Test] public void DynamicMockWithManyParams() { IDynamicMock mock = newDynamicMock(typeof(IBlah)); mock.ExpectAndReturn( "DoStuffWithParams", "world2", "12345", new string[] { "hello", "dotnetmock" } ); IBlah blah = (IBlah)mock.Object; Assertion.AssertEquals( "world2", blah.DoStuffWithParams("12345", "hello", "dotnetmock") ); mock.Verify(); } [Test] public void Name() { Assertion.AssertEquals("mymock", mock.MockName); } [Test] public void NewMockVerifies() { mock.Verify(); } [Test] public void CallToVoidMethod() { mock.Expect("myMethod"); mock.Call(myMethod); mock.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void NoCallToVoidMethod() { mock.Expect("myMethod"); mock.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] public void TooManyCallsToVoidMethod() { mock.Expect("myMethod"); mock.Call(myMethod); mock.Call(myMethod); } [Test] public void ManyCallsToVoidMethod() { mock.Expect("myMethod"); mock.Expect("myMethod"); mock.Expect("myMethod"); mock.Call(myMethod); mock.Call(myMethod); mock.Call(myMethod); mock.Verify(); } [Test] public void CallToMethodWithParams() { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); mock.Call(myMethod, "hello", null); mock.Verify(); } [Test] [ExpectedException(typeof(DotNetMock.AssertionException))] public void CallToMethodWithInvalidParams() { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); mock.Call(myMethod, "world", null); } [Test] public void CallToMethodWithParamsButNotCheckingValues() { mock.Expect("myMethod"); mock.Call(myMethod, "world", null); mock.Verify(); } [Test] public void CallMultipleMethods() { mock.Expect("myMethod1"); mock.Expect("myMethod2"); mock.Expect("myMethod3"); mock.Call(myMethod1); mock.Call(myMethod2); mock.Call(myMethod3); mock.Verify(); } [Test] public void CallToNonVoidMethod() { object something = new object(); mock.ExpectAndReturn("myMethod", something); object result = mock.Call(myMethod); mock.Verify(); Assertion.AssertEquals(something, result); } [Test] public void CallToNonVoidMethodWithParams() { object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); object result = mock.Call(myMethod, "hello"); mock.Verify(); Assertion.AssertEquals(something, result); } [Test] [ExpectedException(typeof(AssertionException))] public void CallToNonVoidMethodWithWrongParams() { object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); object result = mock.Call(myMethod, "bye"); mock.Verify(); Assertion.AssertEquals(something, result); } [Test] public void MultipleCallToNonVoidMethod() { object something = new object(); object anotherthing = new object(); int x = 3; mock.ExpectAndReturn("myMethod", something); mock.ExpectAndReturn("myMethod", anotherthing); mock.ExpectAndReturn("myMethod", x); Assertion.AssertEquals(something, mock.Call(myMethod)); Assertion.AssertEquals(anotherthing, mock.Call(myMethod)); Assertion.AssertEquals(x, mock.Call(myMethod)); mock.Verify(); } [Test] public void CallToNonVoidMethodReturningNull() { mock.ExpectAndReturn("myMethod", null); Assertion.AssertNull(mock.Call(myMethod)); mock.Verify(); } [Test] public void DefaultEqualsPredicates() { object o = new object(); mock.Expect("myMethod", o); mock.Call(myMethod, o); } [Test] [ExpectedException(typeof(AssertionException))] public void DefaultEqualsPredicatesFailure() { mock.Expect("myMethod", new object()); mock.Call(myMethod, new object()); } [Test] public void DefaultAnythingPredicates() { mock.Expect("myMethod", null, null); mock.Expect("myMethod", null, "zzz"); mock.Expect("myMethod", "zzz", null); mock.Call(myMethod, "???", "???"); mock.Call(myMethod, "???", "zzz"); mock.Call(myMethod, "zzz", "???"); } [Test] public void FixedValue() { mock.SetValue("myMethod", "hello"); mock.SetValue("anotherMethod", "world"); Assertion.AssertEquals("hello", mock.Call(myMethod)); Assertion.AssertEquals("hello", mock.Call(myMethod)); Assertion.AssertEquals("hello", mock.Call(myMethod)); Assertion.AssertEquals("hello", mock.Call(myMethod)); Assertion.AssertEquals("world", mock.Call(anotherMethod)); Assertion.AssertEquals("world", mock.Call(anotherMethod)); mock.SetValue("myMethod", "bye"); Assertion.AssertEquals("bye", mock.Call(myMethod)); Assertion.AssertEquals("bye", mock.Call(myMethod)); Assertion.AssertEquals("world", mock.Call(anotherMethod)); mock.SetValue("myMethod", null); Assertion.AssertNull(mock.Call(myMethod)); Assertion.AssertNull(mock.Call(myMethod)); mock.Verify(); } [Test] [ExpectedException(typeof(System.IO.IOException))] public void CallThrowingException() { mock.ExpectAndThrow("myMethod", new System.IO.IOException()); mock.Call(myMethod); } } } |
From: Choy R. <ch...@us...> - 2005-01-09 06:48:44
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25106/DotNetMock/Dynamic/Generate Modified Files: ClassGenerator.cs Added Files: MockClassBuilder.cs Log Message: Factored out mock class builder to improve clarity. --- NEW FILE: MockClassBuilder.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Collections; using System.Reflection; using System.Reflection.Emit; using DotNetMock.Dynamic; #endregion namespace DotNetMock.Dynamic.Generate { /// <summary> /// Builds mock classes dynamically. /// </summary> /// <author>Griffin Caprio</author> /// <author>Choy Rim</author> public class MockClassBuilder { private const string HANDLER_FIELD_NAME = "_mockedCallHandler"; private static readonly Type HANDLER_TYPE = typeof(IMockedCallHandler); private static readonly MethodInfo CALL_HANDLING_METHOD = HANDLER_TYPE.GetMethod( "Call", new Type[] { typeof(MethodInfo), typeof(object[]) } ); TypeBuilder _typeBuilder; FieldBuilder _handlerFieldBuilder; Type _mockClass = null; /// <summary> /// Create instance of mock class builder. /// </summary> /// <param name="moduleBuilder"><see cref="ModuleBuilder"/> that /// we'll define new type in</param> /// <param name="mockClassName">name of mock class that we are /// making</param> /// <param name="superClass">base class that we are extending /// to implement our mock class</param> /// <param name="interfaces">interfaces that our mock class /// will (declare that we) implement</param> public MockClassBuilder( ModuleBuilder moduleBuilder, string mockClassName, Type superClass, Type[] interfaces ) { _typeBuilder = moduleBuilder.DefineType( mockClassName, TypeAttributes.Public, superClass, interfaces ); _handlerFieldBuilder = _typeBuilder.DefineField( HANDLER_FIELD_NAME, HANDLER_TYPE, FieldAttributes.Public ); } /// <summary> /// The mock class we've built. /// </summary> public Type MockClass { get { if ( ! IsCompiled ) { throw new InvalidOperationException( "Must compile before accessing the MockClass" ); } return _mockClass; } } /// <summary> /// The field that holds our <see cref="IMockedCallHandler"/> /// which will receive all calls to this type. /// </summary> public FieldInfo HandlerField { get { if ( ! IsCompiled ) { throw new InvalidOperationException( "Must compile before accessing the HandlerField" ); } return _mockClass.GetField(HANDLER_FIELD_NAME); } } /// <summary> /// Has this class been compiled into a usable type? /// </summary> public bool IsCompiled { get { return _mockClass!=null; } } /// <summary> /// Compile the implemented methods so far into a real /// type. /// </summary> public void Compile() { if ( IsCompiled ) { throw new InvalidOperationException( "Cannot compile class more than once." ); } _mockClass = _typeBuilder.CreateType(); } /// <summary> /// Define a mock implementation method on our mock class given /// a <see cref="MethodInfo"/>. /// </summary> /// <param name="mi"><see cref="MethodInfo"/> describing /// the method we must mock</param> public void ImplementMockedMethod(MethodInfo mi) { ImplementMockedMethod(mi.Name, mi.ReturnType, getParameterTypes(mi)); } /// <summary> /// Define a mock implementation of a method. /// </summary> /// <param name="methodName">name of method to mock</param> /// <param name="returnType">return <see cref="Type"/> of method /// to mock</param> /// <param name="parameterTypes">array of <see cref="Type"/>s in /// the method signature</param> public void ImplementMockedMethod(string methodName, Type returnType, Type[] parameterTypes) { if ( IsCompiled ) { throw new InvalidOperationException( "Cannot add methods after class has been compiled." ); } MethodBuilder methodBuilder = _typeBuilder.DefineMethod( methodName, MethodAttributes.Public | MethodAttributes.Virtual, returnType, parameterTypes ); ILGenerator il = methodBuilder.GetILGenerator(); il.DeclareLocal(typeof(object[])); il.Emit(OpCodes.Ldarg_0); // stack: this il.Emit(OpCodes.Ldfld, _handlerFieldBuilder); // stack: this handler // emit call to get current method il.EmitCall( OpCodes.Call, typeof(MethodBase).GetMethod("GetCurrentMethod", new Type[0]), null ); // stack: this handler methodinfo // assert parameterTypes.Length<128 il.Emit(OpCodes.Ldc_I4_S, (sbyte) parameterTypes.Length); il.Emit(OpCodes.Newarr, typeof(object)); il.Emit(OpCodes.Dup); // store args array in local var il.Emit(OpCodes.Stloc_0); // stack: this handler methodinfo args[] // fill args array with arguments of call if (parameterTypes.Length > 0) { for(int i = 0; i < parameterTypes.Length; i++) { Type parameterType = parameterTypes[i]; Type elementType = parameterType; // push array ref onto stack il.Emit(OpCodes.Ldloc_0); // push array index onto stack il.Emit(OpCodes.Ldc_I4_S, (sbyte) i); // load corresponding argument il.Emit(OpCodes.Ldarg_S, (sbyte) (i + 1)); // dereference if necessary if ( parameterType.IsByRef ) { elementType = parameterType.GetElementType(); ILUtils.EmitTypedLdind(il, elementType); } if ( elementType.IsValueType ) { il.Emit(OpCodes.Box, elementType); } il.Emit(OpCodes.Stelem_Ref); } } il.EmitCall(OpCodes.Callvirt, CALL_HANDLING_METHOD, null); if (returnType == typeof(void)) { il.Emit(OpCodes.Pop); } else { if (returnType.IsValueType) { il.Emit(OpCodes.Unbox, returnType); // load boxed value from heap ILUtils.EmitTypedLdind(il, returnType); } } // load out/ref parameter values if (parameterTypes.Length > 0) { for(int i = 0; i < parameterTypes.Length; i++) { Type parameterType = parameterTypes[i]; if ( parameterType.IsByRef ) { Type elementType = parameterType.GetElementType(); // address of byref arg il.Emit(OpCodes.Ldarg_S, (sbyte) (i+1)); // fetch value from args array il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldc_I4_S, (sbyte) i); il.Emit(OpCodes.Ldelem_Ref); // unbox if necessary if ( elementType.IsValueType ) { il.Emit(OpCodes.Unbox, elementType); ILUtils.EmitTypedLdind(il, elementType); } // store indirectly into ref arg ILUtils.EmitTypedStind(il, elementType); } } } il.Emit(OpCodes.Ret); } /// <summary> /// Returns the array of parameters types given a /// <see cref="MethodInfo"/> /// </summary> /// <param name="mi">method we want the parameter types of</param> /// <returns>array of parameter types in method signature</returns> private static Type[] getParameterTypes(MethodInfo mi) { ArrayList types = new ArrayList(); foreach (ParameterInfo pi in mi.GetParameters()) { types.Add(pi.ParameterType); } return (Type[]) types.ToArray(typeof(Type)); } } } Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/ClassGenerator.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ClassGenerator.cs 8 Jan 2005 20:24:22 -0000 1.9 --- ClassGenerator.cs 9 Jan 2005 06:48:35 -0000 1.10 *************** *** 41,67 **** } /// <summary> ! /// Generates proxy mock object for the input type using the parameters from the <see cref="IMockedCallHandler"/> /// </summary> /// <param name="type">type to generate proxy for.</param> ! /// <param name="mock"><see cref="IMockedCallHandler"/> containg parameters for proxy object.</param> /// <returns>proxy mock object for input type.</returns> ! public object Generate(Type type, IMockedCallHandler mock) { ! TypeBuilder typeBuilder = getTypeBuilder("Mock" + type.Name, type); ! FieldBuilder mockFieldBuilder = typeBuilder.DefineField("underlyingMock", typeof(IMockedCallHandler), FieldAttributes.Public); IList methods = getMethods(type); ! foreach ( MethodInfo m in methods ) { ! implementMethod(typeBuilder, m, mockFieldBuilder); } ! Type proxyType = typeBuilder.CreateType(); ! object result = Activator.CreateInstance(proxyType); ! FieldInfo underlyingMock = proxyType.GetField("underlyingMock"); ! underlyingMock.SetValue(result, mock); if ( _assemblyFilename!=null ) { _assemblyBuilder.Save(_assemblyFilename); } ! return result; } private IList getMethods(Type type) --- 41,82 ---- } /// <summary> ! /// Generates a mock object for the specified type. /// </summary> /// <param name="type">type to generate proxy for.</param> ! /// <param name="handler"><see cref="IMockedCallHandler"/> which ! /// will handle all calls to the generated mock object.</param> /// <returns>proxy mock object for input type.</returns> ! public object Generate(Type type, IMockedCallHandler handler) { ! string mockClassName = "Mock" + type.Name; ! Type superClass; ! Type[] interfaces; ! determineSuperClassAndInterfaces( ! type, ! out superClass, out interfaces ! ); ! MockClassBuilder classBuilder = new MockClassBuilder( ! _moduleBuilder, ! mockClassName, ! superClass, ! interfaces ! ); IList methods = getMethods(type); ! foreach (MethodInfo mi in methods) { ! classBuilder.ImplementMockedMethod(mi); } ! // create type ! classBuilder.Compile(); ! object newMockObject = ! Activator.CreateInstance(classBuilder.MockClass); ! // set handler field ! classBuilder.HandlerField.SetValue(newMockObject, handler); ! // save if necessary if ( _assemblyFilename!=null ) { _assemblyBuilder.Save(_assemblyFilename); } ! return newMockObject; } private IList getMethods(Type type) *************** *** 89,208 **** } } ! private TypeBuilder getTypeBuilder(string name, Type originalType) { ! Type superClass; ! Type[] interfaces; ! if (originalType.IsInterface) { superClass = null; ! interfaces = new Type[] {originalType}; } else { ! superClass = originalType; interfaces = new Type[0]; } - return _moduleBuilder.DefineType(name, TypeAttributes.Public, superClass, interfaces); - } - - private void implementMethod(TypeBuilder typeBuilder, MethodInfo m, FieldBuilder mockFieldBuilder) - { - Type returnType = m.ReturnType; - ArrayList types = new ArrayList(); - foreach (ParameterInfo param in m.GetParameters()) - { - types.Add(param.ParameterType); - } - Type[] paramTypes = (Type[])types.ToArray(typeof(Type)); - MethodBuilder methodBuilder = typeBuilder.DefineMethod(m.Name, MethodAttributes.Public | MethodAttributes.Virtual, returnType, paramTypes); - - ILGenerator il = methodBuilder.GetILGenerator(); - - il.DeclareLocal(typeof(object[])); - - il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Ldfld, mockFieldBuilder); - // emit call to get current method - il.EmitCall( - OpCodes.Call, - typeof(MethodBase).GetMethod("GetCurrentMethod", new Type[0]), - null - ); - // assert paramTypes.Length<128 - il.Emit(OpCodes.Ldc_I4_S, (sbyte) paramTypes.Length); - il.Emit(OpCodes.Newarr, typeof(object)); - il.Emit(OpCodes.Dup); - il.Emit(OpCodes.Stloc_0); - - if (paramTypes.Length > 0) - { - for(int i = 0; i < paramTypes.Length; i++) - { - Type paramType = paramTypes[i]; - Type elementType = paramType; - // push array ref onto stack - il.Emit(OpCodes.Ldloc_0); - // push array index onto stack - il.Emit(OpCodes.Ldc_I4_S, (sbyte) i); - // load corresponding argument - il.Emit(OpCodes.Ldarg_S, (sbyte) (i + 1)); - // dereference if necessary - if ( paramType.IsByRef ) - { - elementType = paramType.GetElementType(); - ILUtils.EmitTypedLdind(il, elementType); - } - if ( elementType.IsValueType ) - { - il.Emit(OpCodes.Box, elementType); - } - il.Emit(OpCodes.Stelem_Ref); - } - } - - MethodInfo call = typeof(IMockedCallHandler).GetMethod("Call", new Type[] {typeof(MethodInfo), typeof(object[]) } ); - il.EmitCall(OpCodes.Callvirt, call, null); - - if (returnType == typeof(void)) - { - il.Emit(OpCodes.Pop); - } - else - { - if (returnType.IsValueType) - { - il.Emit(OpCodes.Unbox, returnType); - // load boxed value from heap - ILUtils.EmitTypedLdind(il, returnType); - } - } - // load out/ref parameter values - if (paramTypes.Length > 0) - { - for(int i = 0; i < paramTypes.Length; i++) - { - Type paramType = paramTypes[i]; - if ( paramType.IsByRef ) - { - Type elementType = paramType.GetElementType(); - // address of byref arg - il.Emit(OpCodes.Ldarg_S, (sbyte) (i+1)); - // fetch value from args array - il.Emit(OpCodes.Ldloc_0); - il.Emit(OpCodes.Ldc_I4_S, (sbyte) i); - il.Emit(OpCodes.Ldelem_Ref); - // unbox if necessary - if ( elementType.IsValueType ) - { - il.Emit(OpCodes.Unbox, elementType); - ILUtils.EmitTypedLdind(il, elementType); - } - // store indirectly into ref arg - ILUtils.EmitTypedStind(il, elementType); - } - } - } - - il.Emit(OpCodes.Ret); } private static AssemblyBuilder newAssemblyBuilder(AssemblyBuilderAccess access) --- 104,119 ---- } } ! private static void determineSuperClassAndInterfaces(Type targetType, out Type superClass, out Type[] interfaces) { ! if (targetType.IsInterface) { superClass = null; ! interfaces = new Type[] { targetType }; } else { ! superClass = targetType; interfaces = new Type[0]; } } private static AssemblyBuilder newAssemblyBuilder(AssemblyBuilderAccess access) |
From: Choy R. <ch...@us...> - 2005-01-09 06:48:43
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25106/DotNetMock Modified Files: DotNetMock.csproj Log Message: Factored out mock class builder to improve clarity. Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** DotNetMock.csproj 5 Jan 2005 00:29:19 -0000 1.29 --- DotNetMock.csproj 9 Jan 2005 06:48:35 -0000 1.30 *************** *** 265,268 **** --- 265,273 ---- /> <File + RelPath = "Dynamic\Generate\MockClassBuilder.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\Predicates\AndPredicate.cs" SubType = "Code" |
From: Choy R. <ch...@us...> - 2005-01-08 20:24:31
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3547/DotNetMock/Dynamic/Generate Modified Files: ClassGenerator.cs Log Message: Remove declaration of unused local variables in emitted code. Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/ClassGenerator.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ClassGenerator.cs 1 Jan 2005 22:58:08 -0000 1.8 --- ClassGenerator.cs 8 Jan 2005 20:24:22 -0000 1.9 *************** *** 121,130 **** il.DeclareLocal(typeof(object[])); - // TODO: why are we declaring all these locals? - foreach (ParameterInfo param in m.GetParameters()) - { - il.DeclareLocal(param.ParameterType); - } - il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldfld, mockFieldBuilder); --- 121,124 ---- |
From: Griffin C. <gc...@us...> - 2005-01-05 14:43:33
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30231/DotNetMock.Tests Modified Files: AbstractIListExpectationTests.cs ExpectationBoolTests.cs ExpectationCounterTests.cs ExpectationStringTests.cs ExpectationTypeTests.cs ExpectationValueTests.cs NullTests.cs Log Message: - Added tests to round out code coverage Index: NullTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/NullTests.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NullTests.cs 9 Oct 2004 21:14:12 -0000 1.6 --- NullTests.cs 5 Jan 2005 14:43:17 -0000 1.7 *************** *** 1,3 **** - using System; using NUnit.Framework; using DotNetMock; --- 1,2 ---- *************** *** 38,41 **** --- 37,46 ---- Assertion.AssertEquals("null".GetHashCode(), _null.GetHashCode()); } + [Test] + public void NullName() + { + _null = new NullObject("null"); + Assert.AreEqual( "null", _null.Name ); + } } } Index: ExpectationBoolTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/ExpectationBoolTests.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ExpectationBoolTests.cs 10 Oct 2004 07:25:05 -0000 1.4 --- ExpectationBoolTests.cs 5 Jan 2005 14:43:17 -0000 1.5 *************** *** 1,3 **** - using System; using NUnit.Framework; --- 1,2 ---- *************** *** 103,106 **** --- 102,112 ---- NUnit.Framework.Assertion.Assert(!_expectationBool.Expected); } + [Test] + public void ShouldCheckImmediate() + { + _expectationBool.Expected = false; + _expectationBool.VerifyImmediate = true; + _expectationBool.Actual = false; + } } } Index: ExpectationCounterTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/ExpectationCounterTests.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ExpectationCounterTests.cs 10 Oct 2004 07:53:31 -0000 1.8 --- ExpectationCounterTests.cs 5 Jan 2005 14:43:17 -0000 1.9 *************** *** 1,3 **** - using System; using NUnit.Framework; --- 1,2 ---- *************** *** 88,91 **** --- 87,98 ---- } [Test] + public void NonStrictCallsNoExpectations() + { + _counter.Strict = false; + _counter.Inc(); + _counter.Inc(); + _counter.Verify(); + } + [Test] public void FlushActual() { Index: ExpectationTypeTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/ExpectationTypeTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExpectationTypeTests.cs 9 Oct 2004 21:14:12 -0000 1.5 --- ExpectationTypeTests.cs 5 Jan 2005 14:43:17 -0000 1.6 *************** *** 129,132 **** --- 129,144 ---- _expectationType.Verify(); } + [Test] + public void ShouldCheckImmediate() + { + _expectationType.Expected = typeof(string); + _expectationType.VerifyImmediate = true; + _expectationType.Actual = typeof(string); + } + [Test] + public void NoExpectations() + { + _expectationType.Verify(); + } } } Index: AbstractIListExpectationTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/AbstractIListExpectationTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AbstractIListExpectationTests.cs 10 Oct 2004 06:52:32 -0000 1.1 --- AbstractIListExpectationTests.cs 5 Jan 2005 14:43:17 -0000 1.2 *************** *** 62,65 **** --- 62,73 ---- ExpectedCollection.Add( null ); Verify(); + + ClearActual(); + try + { + Verify(); + Assertion.Fail( "should throw an exception." ); + } + catch {} } private void setGeneralExpectations() *************** *** 67,71 **** this.HasExpectations = true; } ! public override System.Collections.IList ActualCollection { get --- 75,79 ---- this.HasExpectations = true; } ! public override IList ActualCollection { get *************** *** 80,84 **** } ! public override System.Collections.IList ExpectedCollection { get --- 88,92 ---- } ! public override IList ExpectedCollection { get Index: ExpectationValueTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/ExpectationValueTests.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ExpectationValueTests.cs 9 Oct 2004 21:14:12 -0000 1.7 --- ExpectationValueTests.cs 5 Jan 2005 14:43:17 -0000 1.8 *************** *** 1,10 **** namespace DotNetMock.Tests { - using System; - using NUnit.Framework; - using DotNetMock; - /// <summary> - /// Summary description for ExpectationValueTests. - /// </summary> [TestFixture] public class ExpectationValueTests --- 1,8 ---- + using System; + using NUnit.Framework; + using DotNetMock; + namespace DotNetMock.Tests { [TestFixture] public class ExpectationValueTests *************** *** 114,118 **** object6 = null; } ! [Test] public void NullValues() --- 112,123 ---- object6 = null; } ! [Test] ! public void ShouldCheckImmediate() ! { ! object object7 = new object(); ! _expectationValue.Expected = object7; ! _expectationValue.VerifyImmediate = true; ! _expectationValue.Actual = object7; ! } [Test] public void NullValues() Index: ExpectationStringTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/ExpectationStringTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ExpectationStringTests.cs 22 Mar 2004 03:51:48 -0000 1.5 --- ExpectationStringTests.cs 5 Jan 2005 14:43:17 -0000 1.6 *************** *** 1,10 **** namespace DotNetMock.Tests { - using System; - using NUnit.Framework; - using DotNetMock; - /// <summary> - /// Summary description for ExpectationStringTests. - /// </summary> [TestFixture] public class ExpectationStringTests --- 1,7 ---- + using NUnit.Framework; + using DotNetMock; + namespace DotNetMock.Tests { [TestFixture] public class ExpectationStringTests *************** *** 132,135 **** --- 129,140 ---- test9 = null; } + [Test] + public void ShouldCheckImmediate() + { + string test10 = "Testing"; + _expectationString.Expected = test10; + _expectationString.VerifyImmediate = true; + _expectationString.Actual = test10; + } } } |
From: Griffin C. <gc...@us...> - 2005-01-05 14:43:33
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30231/DotNetMock Modified Files: AbstractStaticExpectation.cs Log Message: - Added tests to round out code coverage Index: AbstractStaticExpectation.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/AbstractStaticExpectation.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AbstractStaticExpectation.cs 10 Oct 2004 06:53:38 -0000 1.3 --- AbstractStaticExpectation.cs 5 Jan 2005 14:43:18 -0000 1.4 *************** *** 1,4 **** - using System; - namespace DotNetMock { --- 1,2 ---- |