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-05 14:22:18
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25388/DotNetMock Modified Files: Verifier.cs Log Message: - Removed Static Type initializer from Verifier class. Moved initialization to declaring fields. Index: Verifier.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Verifier.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** Verifier.cs 5 Jan 2005 14:19:44 -0000 1.19 --- Verifier.cs 5 Jan 2005 14:22:10 -0000 1.20 *************** *** 8,15 **** /// Verifies objects that implement the IVerifiable interface. /// </summary> - /// <remarks> - /// Currently, no protection is offered to prevent reentry. So, two mock objects - /// that have a circular reference to each other will create an endless loop. - /// </remarks> public sealed class Verifier { --- 8,11 ---- *************** *** 28,40 **** /// Keeps a list of objects that have been verified /// </summary> ! private static IList _verifiedObjects = null; ! ! /// <summary> ! /// Static type initialization. Creates a new instance of the verified objects list. ! /// </summary> ! static Verifier() ! { ! _verifiedObjects = new ArrayList(); ! } #region Static --- 24,28 ---- /// Keeps a list of objects that have been verified /// </summary> ! private static IList _verifiedObjects = new ArrayList(); #region Static *************** *** 111,115 **** } #endregion - } } --- 99,102 ---- |
From: Griffin C. <gc...@us...> - 2005-01-05 14:19:55
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24873/DotNetMock Modified Files: Verifier.cs Log Message: - Added tests for IsCloseTo IPredicate - Removed private constructor from Verifier Index: Verifier.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Verifier.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Verifier.cs 18 Jul 2004 17:49:11 -0000 1.18 --- Verifier.cs 5 Jan 2005 14:19:44 -0000 1.19 *************** *** 37,44 **** _verifiedObjects = new ArrayList(); } - - private Verifier() { - } - #region Static --- 37,40 ---- |
From: Griffin C. <gc...@us...> - 2005-01-05 14:19:55
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24873/DotNetMock.Tests/Dynamic Modified Files: PredicateTests.cs Log Message: - Added tests for IsCloseTo IPredicate - Removed private constructor from Verifier Index: PredicateTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/PredicateTests.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PredicateTests.cs 1 Jan 2005 21:13:46 -0000 1.10 --- PredicateTests.cs 5 Jan 2005 14:19:44 -0000 1.11 *************** *** 238,241 **** --- 238,254 ---- } + [Test] + public void IsCloseTo() + { + p = new IsCloseTo(3.0, 0.5); + Assert.IsTrue( p.Eval( 3.0 ) ); + Assert.IsTrue( p.Eval( 3.5 ) ); + Assert.IsFalse( p.Eval( 3.6 ) ); + Assert.IsTrue( p.Eval( 3.2 ) ); + Assert.IsFalse( p.Eval( 2.0 ) ); + Assert.IsTrue( p.Eval( 3.4 ) ); + Assert.IsFalse( p.Eval( null ) ); + Assert.IsFalse( p.Eval( "mock" ) ); + } private bool myFlag; |
From: Griffin C. <gc...@us...> - 2005-01-05 14:10:41
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23091/DotNetMock.Tests/Dynamic/Generate Modified Files: ClassGeneratorTests.cs Log Message: - Added test for persistent assemblies Index: ClassGeneratorTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate/ClassGeneratorTests.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ClassGeneratorTests.cs 5 Jan 2005 04:25:39 -0000 1.14 --- ClassGeneratorTests.cs 5 Jan 2005 14:10:33 -0000 1.15 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.IO; using NUnit.Framework; using DotNetMock.Dynamic; *************** *** 114,118 **** public void GeneratePersistentAssembly() { ! } [Test] public void TestInParameters() --- 115,131 ---- public void GeneratePersistentAssembly() { ! if ( File.Exists( "test.dll" ) ) ! { ! File.Delete( "test.dll" ); ! } ! cg = new ClassGenerator("test.dll"); ! DirectionalMockedCallHandler dmch = ! new DirectionalMockedCallHandler(); ! cg.Generate(typeof(IDirectionalParameters), dmch); ! Assert.IsTrue( File.Exists( "test.dll" ) ); ! if ( File.Exists( "test.dll" ) ) ! { ! File.Delete( "test.dll" ); ! } } [Test] public void TestInParameters() |
From: Griffin C. <gc...@us...> - 2005-01-05 14:03:41
|
Update of /cvsroot/dotnetmock/dotnetmock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21699 Modified Files: DotNetMock.build Log Message: - Updated version number to latest version Index: DotNetMock.build =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.build,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DotNetMock.build 12 Nov 2004 16:03:29 -0000 1.12 --- DotNetMock.build 5 Jan 2005 14:03:32 -0000 1.13 *************** *** 5,9 **** <property name="VisualStudioTemplates2003" value="VisualStudioTemplates2003"/> <property name="project.name" value="DotNetMock"/> ! <property name="version" value="0.7.2"/> <property name="build.dir" value="build/"/> <property name="dist.dir" value="dist"/> --- 5,9 ---- <property name="VisualStudioTemplates2003" value="VisualStudioTemplates2003"/> <property name="project.name" value="DotNetMock"/> ! <property name="version" value="0.7.3"/> <property name="build.dir" value="build/"/> <property name="dist.dir" value="dist"/> |
From: Griffin C. <gc...@us...> - 2005-01-05 04:29:28
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.csUnitNamespace In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5572/DotNetMock.csUnitNamespace Modified Files: AssemblyInfo.cs Log Message: - Updated AssemblyInfo for new release Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.csUnitNamespace/AssemblyInfo.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AssemblyInfo.cs 10 Oct 2004 07:56:43 -0000 1.3 --- AssemblyInfo.cs 5 Jan 2005 04:29:16 -0000 1.4 *************** *** 1,5 **** using System; using System.Reflection; - using System.Runtime.CompilerServices; using System.Runtime.InteropServices; --- 1,4 ---- *************** *** 10,12 **** [assembly: AssemblyDescription("Assembly containing csUnit specific classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.1.0")] --- 9,11 ---- [assembly: AssemblyDescription("Assembly containing csUnit specific classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.3.0")] |
From: Griffin C. <gc...@us...> - 2005-01-05 04:29:27
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.MbUnitNamespace In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5572/DotNetMock.MbUnitNamespace Modified Files: AssemblyInfo.cs Log Message: - Updated AssemblyInfo for new release Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.MbUnitNamespace/AssemblyInfo.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AssemblyInfo.cs 10 Oct 2004 07:56:43 -0000 1.3 --- AssemblyInfo.cs 5 Jan 2005 04:29:15 -0000 1.4 *************** *** 1,5 **** using System; using System.Reflection; - using System.Runtime.CompilerServices; using System.Runtime.InteropServices; --- 1,4 ---- *************** *** 10,12 **** [assembly: AssemblyDescription("Assembly contained MbUnit specific classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.1.0")] --- 9,11 ---- [assembly: AssemblyDescription("Assembly contained MbUnit specific classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.3.0")] |
From: Griffin C. <gc...@us...> - 2005-01-05 04:29:26
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5572/DotNetMock Modified Files: AssemblyInfo.cs Log Message: - Updated AssemblyInfo for new release Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/AssemblyInfo.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** AssemblyInfo.cs 10 Oct 2004 07:56:43 -0000 1.11 --- AssemblyInfo.cs 5 Jan 2005 04:29:16 -0000 1.12 *************** *** 1,5 **** using System; using System.Reflection; - using System.Runtime.CompilerServices; using System.Runtime.InteropServices; --- 1,4 ---- *************** *** 14,16 **** [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.1.0")] --- 13,15 ---- [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.3.0")] |
From: Griffin C. <gc...@us...> - 2005-01-05 04:29:26
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.NUnit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5572/DotNetMock.NUnit Modified Files: AssemblyInfo.cs Log Message: - Updated AssemblyInfo for new release Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.NUnit/AssemblyInfo.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AssemblyInfo.cs 26 May 2004 23:33:31 -0000 1.2 --- AssemblyInfo.cs 5 Jan 2005 04:29:15 -0000 1.3 *************** *** 1,5 **** using System; using System.Reflection; - using System.Runtime.CompilerServices; using System.Runtime.InteropServices; --- 1,4 ---- *************** *** 10,13 **** [assembly: AssemblyDescription("Assembly contained NUnit specific classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.5.0.0")] --- 9,12 ---- [assembly: AssemblyDescription("Assembly contained NUnit specific classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.3.0")] |
From: Griffin C. <gc...@us...> - 2005-01-05 04:29:25
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5572/DotNetMock.Framework Modified Files: AssemblyInfo.cs Log Message: - Updated AssemblyInfo for new release Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/AssemblyInfo.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssemblyInfo.cs 10 Oct 2004 07:56:43 -0000 1.4 --- AssemblyInfo.cs 5 Jan 2005 04:29:15 -0000 1.5 *************** *** 18,21 **** [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] ! [assembly: AssemblyVersion("0.7.1.0")] --- 18,21 ---- [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] ! [assembly: AssemblyVersion("0.7.3.0")] |
From: Griffin C. <gc...@us...> - 2005-01-05 04:29:24
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5572/DotNetMock.Core Modified Files: AssemblyInfo.cs Log Message: - Updated AssemblyInfo for new release Index: AssemblyInfo.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Core/AssemblyInfo.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** AssemblyInfo.cs 10 Oct 2004 07:56:43 -0000 1.3 --- AssemblyInfo.cs 5 Jan 2005 04:29:14 -0000 1.4 *************** *** 1,5 **** using System; using System.Reflection; - using System.Runtime.CompilerServices; using System.Runtime.InteropServices; --- 1,4 ---- *************** *** 10,12 **** [assembly: AssemblyDescription("Assembly contained core DotNetMock interfaces & classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.1.0")] --- 9,11 ---- [assembly: AssemblyDescription("Assembly contained core DotNetMock interfaces & classes")] [assembly: AssemblyCompany("DotNetMock")] ! [assembly: AssemblyVersion("0.7.3.0")] |
From: Griffin C. <gc...@us...> - 2005-01-05 04:25:49
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4496/DotNetMock.Tests/Dynamic/Generate Modified Files: ClassGeneratorTests.cs Log Message: - Minor region additions Index: ClassGeneratorTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate/ClassGeneratorTests.cs,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ClassGeneratorTests.cs 1 Jan 2005 22:57:51 -0000 1.13 --- ClassGeneratorTests.cs 5 Jan 2005 04:25:39 -0000 1.14 *************** *** 6,14 **** using System.Collections; using System.Reflection; - using System.Reflection.Emit; - using System.Diagnostics; namespace DotNetMock.Tests.Dynamic.Generate { public interface IThingy { --- 6,13 ---- using System.Collections; using System.Reflection; namespace DotNetMock.Tests.Dynamic.Generate { + #region Dummy Test Structures public interface IThingy { *************** *** 59,66 **** } [TestFixture] public class ClassGeneratorTest { - private ClassGenerator cg; private IDynamicMock mock; --- 58,66 ---- } + #endregion + [TestFixture] public class ClassGeneratorTest { private ClassGenerator cg; private IDynamicMock mock; *************** *** 111,115 **** private MethodInfo _methodInfo = null; } ! [Test] public void TestInParameters() { --- 111,119 ---- private MethodInfo _methodInfo = null; } ! [Test] ! public void GeneratePersistentAssembly() ! { ! ! } [Test] public void TestInParameters() { |
From: Choy R. <ch...@us...> - 2005-01-05 00:30:25
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25159/DotNetMock Modified Files: DotNetMock.csproj Log Message: Make the AndRequire a bit more consistent by allowing it to automatically convert object -> IPredicate. Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** DotNetMock.csproj 1 Jan 2005 22:58:07 -0000 1.28 --- DotNetMock.csproj 5 Jan 2005 00:29:19 -0000 1.29 *************** *** 250,253 **** --- 250,258 ---- /> <File + RelPath = "Dynamic\PredicateUtils.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\Generate\ClassGenerator.cs" SubType = "Code" |
From: Choy R. <ch...@us...> - 2005-01-05 00:30:18
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25159/DotNetMock.Tests/Dynamic Modified Files: AssignTests.cs Added Files: PredicateUtilsTests.cs Log Message: Make the AndRequire a bit more consistent by allowing it to automatically convert object -> IPredicate. --- NEW FILE: PredicateUtilsTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using NUnit.Framework; using DotNetMock.Dynamic; using DotNetMock.Dynamic.Predicates; #endregion namespace DotNetMock.Tests.Dynamic { [TestFixture] public class PredicateUtilsTests { [Test] public void PredicateRemainsPredicate() { IPredicate predicate = PredicateUtils.ConvertFrom(new IsAnything()); Assert.IsTrue(predicate is IsAnything); } [Test] public void NullConvertedToIsAnything() { IPredicate predicate = PredicateUtils.ConvertFrom(null); Assert.IsTrue(predicate is IsAnything); } [Test] public void DefaultConvertedToIsAnything() { IPredicate predicate = PredicateUtils.ConvertFrom("whatever"); Assert.IsTrue(predicate is IsEqual); Assert.IsTrue(predicate.Eval("whatever")); } } } Index: AssignTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/AssignTests.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AssignTests.cs 1 Jan 2005 22:57:51 -0000 1.2 --- AssignTests.cs 5 Jan 2005 00:29:19 -0000 1.3 *************** *** 14,17 **** --- 14,28 ---- public class AssignTests { + [Test] public void SetAndRequireEqualImplied() + { + object av = new Assign("hello").AndRequire("goodbye"); + object pv = "goodbye"; + IPredicate predicate = av as IPredicate; + Assert.IsNotNull(predicate); + Assert.IsTrue(predicate.Eval(pv)); + IArgumentMutator am = av as IArgumentMutator; + am.Mutate(ref pv); + Assert.AreEqual("hello", (string) pv); + } [Test] public void SetAndRequireEqual() { |
From: Choy R. <ch...@us...> - 2005-01-05 00:30:14
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25159/DotNetMock/Dynamic Modified Files: AbstractArgumentMutator.cs ExpectationMethod.cs Added Files: PredicateUtils.cs Log Message: Make the AndRequire a bit more consistent by allowing it to automatically convert object -> IPredicate. Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ExpectationMethod.cs 1 Jan 2005 22:58:07 -0000 1.9 --- ExpectationMethod.cs 5 Jan 2005 00:29:36 -0000 1.10 *************** *** 136,160 **** for (int i = 0; i < _expectedMethodArguments.Length; i++) { ! object expectedArg = _expectedMethodArguments[i]; object actualArg = _methodArguments[i]; ! ! IPredicate predicate = expectedArg as IPredicate; ! ! // if expectedArg is not an IPredicate, use default ! // behavior of IsEqual or IsAnything ! if (predicate == null) ! { ! if (expectedArg == null) ! { ! predicate = new IsAnything(); ! } ! else ! { ! predicate = new IsEqual(expectedArg); ! } ! } Assertion.Assert(predicate.Eval(actualArg)); ! // then handle mutators if any ! IArgumentMutator mutator = expectedArg as IArgumentMutator; if ( mutator!=null ) { --- 136,149 ---- for (int i = 0; i < _expectedMethodArguments.Length; i++) { ! object argumentExpectation = _expectedMethodArguments[i]; object actualArg = _methodArguments[i]; ! ! // evaluate whether input expectations have been met ! IPredicate predicate = ! PredicateUtils.ConvertFrom(argumentExpectation); Assertion.Assert(predicate.Eval(actualArg)); ! // return output expectations if specified ! IArgumentMutator mutator = ! argumentExpectation as IArgumentMutator; if ( mutator!=null ) { Index: AbstractArgumentMutator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/AbstractArgumentMutator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractArgumentMutator.cs 1 Jan 2005 22:58:07 -0000 1.2 --- AbstractArgumentMutator.cs 5 Jan 2005 00:29:34 -0000 1.3 *************** *** 3,7 **** #endregion #region Imports ! #endregion --- 3,7 ---- #endregion #region Imports ! using DotNetMock.Dynamic.Predicates; #endregion *************** *** 15,19 **** public abstract class AbstractArgumentMutator : IArgumentMutator, IPredicate { ! private IPredicate _predicate = null; /// <summary> /// Abstract method representing the exchanging of parameters --- 15,20 ---- public abstract class AbstractArgumentMutator : IArgumentMutator, IPredicate { ! private static IPredicate DEFAULT_PREDICATE = new IsAnything(); ! private IPredicate _predicate = DEFAULT_PREDICATE; /// <summary> /// Abstract method representing the exchanging of parameters *************** *** 22,46 **** public abstract void Mutate(ref object argument); /// <summary> ! /// Chains the current instance to another predicate to evaluate when exchanging parameters /// </summary> ! /// <param name="predicate"><see cref="IPredicate"/> to use for evaluation</param> /// <returns>reference to this instance</returns> ! public object AndRequire(IPredicate predicate) { ! _predicate = predicate; return this; } /// <summary> ! /// If there is no predicate associate with this mutator, returns true. Otherwise, evaluates the ! /// input value according to the predicate. /// </summary> /// <param name="inputValue">Value to evaluate</param> ! /// <returns>The Result of the predicate evaluation, or true if no predicate is assigned to this instance.</returns> public virtual bool Eval(object inputValue) { - if ( _predicate==null ) - { - return true; - } return _predicate.Eval(inputValue); } --- 23,44 ---- public abstract void Mutate(ref object argument); /// <summary> ! /// Chains the current instance to another predicate to evaluate when ! /// exchanging parameters /// </summary> ! /// <param name="requirement">object requirement that can be converted ! /// to a <see cref="IPredicate"/></param> /// <returns>reference to this instance</returns> ! public object AndRequire(object requirement) { ! _predicate = PredicateUtils.ConvertFrom(requirement); return this; } /// <summary> ! /// Evaluates the input value according to the contained predicate. /// </summary> /// <param name="inputValue">Value to evaluate</param> ! /// <returns>Result of the predicate evaluation</returns> public virtual bool Eval(object inputValue) { return _predicate.Eval(inputValue); } --- NEW FILE: PredicateUtils.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using DotNetMock.Dynamic.Predicates; #endregion namespace DotNetMock.Dynamic { /// <summary> /// Utilities that for working with predicates. /// </summary> public class PredicateUtils { /// <summary> /// Create an appropriate <see cref="IPredicate"/> given an /// abitrary object. /// </summary> /// <param name="expectation">argument expectation</param> /// <returns><see cref="IPredicate"/> that is appropriate for /// the specified object</returns> public static IPredicate ConvertFrom(object expectation) { IPredicate predicate = expectation as IPredicate; if ( predicate==null ) { if ( expectation==null ) { predicate = new IsAnything(); } else { predicate = new IsEqual(expectation); } } return predicate; } } } |
From: Choy R. <ch...@us...> - 2005-01-05 00:30:07
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25159/DotNetMock.Tests Modified Files: DotNetMock.Tests.csproj Log Message: Make the AndRequire a bit more consistent by allowing it to automatically convert object -> IPredicate. Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** DotNetMock.Tests.csproj 1 Jan 2005 22:57:51 -0000 1.13 --- DotNetMock.Tests.csproj 5 Jan 2005 00:29:17 -0000 1.14 *************** *** 185,188 **** --- 185,193 ---- /> <File + RelPath = "Dynamic\PredicateUtilsTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\Generate\ClassGeneratorTests.cs" SubType = "Code" |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:43
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock.Tests/Dynamic Modified Files: DynamicMockTests.cs DynamicOrderedMockTests.cs Added Files: AssignTests.cs Log Message: - Merged branch RFE_1001778 into head Index: DynamicMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicMockTests.cs,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** DynamicMockTests.cs 12 Nov 2004 16:03:29 -0000 1.16 --- DynamicMockTests.cs 1 Jan 2005 22:57:51 -0000 1.17 *************** *** 1,6 **** using System; ! using NUnit.Framework; using DotNetMock.Dynamic; using DotNetMock.Dynamic.Predicates; namespace DotNetMock.Tests.Dynamic --- 1,13 ---- + #region License + // need license + #endregion + #region Imports using System; ! using System.Reflection; using DotNetMock.Dynamic; + using NUnit.Framework; + using DotNetMock.Dynamic.Predicates; + #endregion namespace DotNetMock.Tests.Dynamic *************** *** 10,13 **** --- 17,26 ---- { private IDynamicMock mock; + private MethodInfo myMethod; + private MethodInfo myMethod1; + private MethodInfo myMethod2; + private MethodInfo myMethod3; + private MethodInfo anotherMethod; + interface IBlah { *************** *** 15,19 **** --- 28,81 ---- 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(); } + [Test] [ExpectedException(typeof(VerifyException))] *************** *** 96,110 **** public CustomMock(Type t) : base(t) {} ! public override object Call(string name, params object[] args) { return "CUSTOM"; } } - [SetUp] - public void SetUp() - { - mock = new DynamicMock("mymock"); - } - [Test] public void Name() --- 158,166 ---- public CustomMock(Type t) : base(t) {} ! public override object Call(MethodInfo mi, params object[] args) { return "CUSTOM"; } } [Test] public void Name() *************** *** 123,130 **** { mock.Expect("myMethod"); ! mock.Call("myMethod"); mock.Verify(); } - [Test] [ExpectedException(typeof(AssertionException))] --- 179,185 ---- { mock.Expect("myMethod"); ! mock.Call(myMethod); mock.Verify(); } [Test] [ExpectedException(typeof(AssertionException))] *************** *** 147,152 **** { mock.Expect("myMethod"); ! mock.Call("myMethod"); ! mock.Call("myMethod"); } --- 202,207 ---- { mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Call(myMethod); } *************** *** 157,163 **** mock.Expect("myMethod"); mock.Expect("myMethod"); ! mock.Call("myMethod"); ! mock.Call("myMethod"); ! mock.Call("myMethod"); mock.Verify(); } --- 212,218 ---- mock.Expect("myMethod"); mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Call(myMethod); ! mock.Call(myMethod); mock.Verify(); } *************** *** 167,174 **** { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call("myMethod", "hello", null); mock.Verify(); } - [Test] [ExpectedException(typeof(DotNetMock.AssertionException))] --- 222,228 ---- { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call(myMethod, "hello", null); mock.Verify(); } [Test] [ExpectedException(typeof(DotNetMock.AssertionException))] *************** *** 176,180 **** { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call("myMethod", "world", null); } --- 230,234 ---- { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call(myMethod, "world", null); } *************** *** 183,187 **** { mock.Expect("myMethod"); ! mock.Call("myMethod", "world", null); mock.Verify(); } --- 237,241 ---- { mock.Expect("myMethod"); ! mock.Call(myMethod, "world", null); mock.Verify(); } *************** *** 193,199 **** mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call("myMethod1"); ! mock.Call("myMethod2"); ! mock.Call("myMethod3"); mock.Verify(); } --- 247,253 ---- mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod2); ! mock.Call(myMethod3); mock.Verify(); } *************** *** 205,211 **** mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call("myMethod1"); ! mock.Call("myMethod3"); ! mock.Call("myMethod2"); mock.Verify(); } --- 259,265 ---- mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod3); ! mock.Call(myMethod2); mock.Verify(); } *************** *** 216,220 **** object something = new object(); mock.ExpectAndReturn("myMethod", something); ! object result = mock.Call("myMethod"); mock.Verify(); Assertion.AssertEquals(something, result); --- 270,274 ---- object something = new object(); mock.ExpectAndReturn("myMethod", something); ! object result = mock.Call(myMethod); mock.Verify(); Assertion.AssertEquals(something, result); *************** *** 226,230 **** object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call("myMethod", "hello"); mock.Verify(); Assertion.AssertEquals(something, result); --- 280,284 ---- object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call(myMethod, "hello"); mock.Verify(); Assertion.AssertEquals(something, result); *************** *** 237,241 **** object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call("myMethod", "bye"); mock.Verify(); Assertion.AssertEquals(something, result); --- 291,295 ---- object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call(myMethod, "bye"); mock.Verify(); Assertion.AssertEquals(something, result); *************** *** 251,257 **** 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(); } --- 305,311 ---- 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(); } *************** *** 261,265 **** { mock.ExpectAndReturn("myMethod", null); ! Assertion.AssertNull(mock.Call("myMethod")); mock.Verify(); } --- 315,319 ---- { mock.ExpectAndReturn("myMethod", null); ! Assertion.AssertNull(mock.Call(myMethod)); mock.Verify(); } *************** *** 270,274 **** object o = new object(); mock.Expect("myMethod", o); ! mock.Call("myMethod", o); } --- 324,328 ---- object o = new object(); mock.Expect("myMethod", o); ! mock.Call(myMethod, o); } *************** *** 278,282 **** { mock.Expect("myMethod", new object()); ! mock.Call("myMethod", new object()); } --- 332,336 ---- { mock.Expect("myMethod", new object()); ! mock.Call(myMethod, new object()); } *************** *** 287,293 **** mock.Expect("myMethod", null, "zzz"); mock.Expect("myMethod", "zzz", null); ! mock.Call("myMethod", "???", "???"); ! mock.Call("myMethod", "???", "zzz"); ! mock.Call("myMethod", "zzz", "???"); } --- 341,347 ---- mock.Expect("myMethod", null, "zzz"); mock.Expect("myMethod", "zzz", null); ! mock.Call(myMethod, "???", "???"); ! mock.Call(myMethod, "???", "zzz"); ! mock.Call(myMethod, "zzz", "???"); } *************** *** 297,313 **** 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(); } --- 351,367 ---- 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(); } *************** *** 318,322 **** { mock.ExpectAndThrow("myMethod", new System.IO.IOException()); ! mock.Call("myMethod"); } } --- 372,376 ---- { mock.ExpectAndThrow("myMethod", new System.IO.IOException()); ! mock.Call(myMethod); } } Index: DynamicOrderedMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicOrderedMockTests.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DynamicOrderedMockTests.cs 9 Oct 2004 21:14:12 -0000 1.4 --- DynamicOrderedMockTests.cs 1 Jan 2005 22:57:51 -0000 1.5 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Reflection; using DotNetMock.Dynamic.Predicates; using NUnit.Framework; *************** *** 9,15 **** --- 10,28 ---- 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; *************** *** 19,22 **** --- 32,40 ---- { 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]); } *************** *** 37,41 **** { mock.Expect("myMethod"); ! mock.Call("myMethod"); mock.Verify(); } --- 55,59 ---- { mock.Expect("myMethod"); ! mock.Call(myMethod); mock.Verify(); } *************** *** 54,59 **** { mock.Expect("myMethod"); ! mock.Call("myMethod"); ! mock.Call("myMethod"); } --- 72,77 ---- { mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Call(myMethod); } *************** *** 64,70 **** mock.Expect("myMethod"); mock.Expect("myMethod"); ! mock.Call("myMethod"); ! mock.Call("myMethod"); ! mock.Call("myMethod"); mock.Verify(); } --- 82,88 ---- mock.Expect("myMethod"); mock.Expect("myMethod"); ! mock.Call(myMethod); ! mock.Call(myMethod); ! mock.Call(myMethod); mock.Verify(); } *************** *** 74,78 **** { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call("myMethod", "hello", null); mock.Verify(); } --- 92,96 ---- { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call(myMethod, "hello", null); mock.Verify(); } *************** *** 83,87 **** { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call("myMethod", "world", null); } --- 101,105 ---- { mock.Expect("myMethod", new IsEqual("hello"), new IsAnything()); ! mock.Call(myMethod, "world", null); } *************** *** 90,94 **** { mock.Expect("myMethod"); ! mock.Call("myMethod", "world", null); mock.Verify(); } --- 108,112 ---- { mock.Expect("myMethod"); ! mock.Call(myMethod, "world", null); mock.Verify(); } *************** *** 100,106 **** mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call("myMethod1"); ! mock.Call("myMethod2"); ! mock.Call("myMethod3"); mock.Verify(); } --- 118,124 ---- mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod2); ! mock.Call(myMethod3); mock.Verify(); } *************** *** 113,119 **** mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call("myMethod1"); ! mock.Call("myMethod3"); ! mock.Call("myMethod2"); mock.Verify(); } --- 131,137 ---- mock.Expect("myMethod2"); mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod3); ! mock.Call(myMethod2); mock.Verify(); } *************** *** 124,128 **** object something = new object(); mock.ExpectAndReturn("myMethod", something); ! object result = mock.Call("myMethod"); mock.Verify(); Assertion.AssertEquals(something, result); --- 142,146 ---- object something = new object(); mock.ExpectAndReturn("myMethod", something); ! object result = mock.Call(myMethod); mock.Verify(); Assertion.AssertEquals(something, result); *************** *** 134,138 **** object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call("myMethod", "hello"); mock.Verify(); Assertion.AssertEquals(something, result); --- 152,156 ---- object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call(myMethod, "hello"); mock.Verify(); Assertion.AssertEquals(something, result); *************** *** 145,149 **** object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call("myMethod", "bye"); mock.Verify(); Assertion.AssertEquals(something, result); --- 163,167 ---- object something = new object(); mock.ExpectAndReturn("myMethod", something, new IsEqual("hello")); ! object result = mock.Call(myMethod, "bye"); mock.Verify(); Assertion.AssertEquals(something, result); *************** *** 159,165 **** 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(); } --- 177,183 ---- 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(); } *************** *** 169,173 **** { mock.ExpectAndReturn("myMethod", null); ! Assertion.AssertNull(mock.Call("myMethod")); mock.Verify(); } --- 187,191 ---- { mock.ExpectAndReturn("myMethod", null); ! Assertion.AssertNull(mock.Call(myMethod)); mock.Verify(); } *************** *** 178,182 **** object o = new object(); mock.Expect("myMethod", o); ! mock.Call("myMethod", o); } --- 196,200 ---- object o = new object(); mock.Expect("myMethod", o); ! mock.Call(myMethod, o); } *************** *** 186,190 **** { mock.Expect("myMethod", new object()); ! mock.Call("myMethod", new object()); } --- 204,208 ---- { mock.Expect("myMethod", new object()); ! mock.Call(myMethod, new object()); } *************** *** 195,201 **** mock.Expect("myMethod", null, "zzz"); mock.Expect("myMethod", "zzz", null); ! mock.Call("myMethod", "???", "???"); ! mock.Call("myMethod", "???", "zzz"); ! mock.Call("myMethod", "zzz", "???"); } --- 213,219 ---- mock.Expect("myMethod", null, "zzz"); mock.Expect("myMethod", "zzz", null); ! mock.Call(myMethod, "???", "???"); ! mock.Call(myMethod, "???", "zzz"); ! mock.Call(myMethod, "zzz", "???"); } *************** *** 205,221 **** 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(); } --- 223,239 ---- 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(); } *************** *** 226,230 **** { mock.ExpectAndThrow("myMethod", new System.IO.IOException()); ! mock.Call("myMethod"); } [Test] --- 244,248 ---- { mock.ExpectAndThrow("myMethod", new System.IO.IOException()); ! mock.Call(myMethod); } [Test] *************** *** 263,267 **** public CustomMock(Type t) : base(t) {} ! public override object Call(string name, params object[] args) { return "CUSTOM"; --- 281,285 ---- public CustomMock(Type t) : base(t) {} ! public override object Call(MethodInfo mi, params object[] args) { return "CUSTOM"; --- NEW FILE: AssignTests.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using DotNetMock.Dynamic; using NUnit.Framework; using DotNetMock.Dynamic.Predicates; #endregion namespace DotNetMock.Tests.Dynamic { [TestFixture] public class AssignTests { [Test] public void SetAndRequireEqual() { object av = new Assign("hello").AndRequire(new IsEqual("goodbye")); object pv = "goodbye"; IPredicate predicate = av as IPredicate; Assert.IsNotNull(predicate); Assert.IsTrue(predicate.Eval(pv)); IArgumentMutator am = av as IArgumentMutator; am.Mutate(ref pv); Assert.AreEqual("hello", (string) pv); } [Test] public void SetString() { Assign av = new Assign("hello"); object pv = "goodbye"; av.Mutate(ref pv); Assert.AreEqual("hello", (string) pv); } [Test] public void SetInt32() { Assign av = new Assign(123); object pv = 234; av.Mutate(ref pv); Assert.AreEqual(123, (int) pv); } [Test] public void SetInt32OfArray() { Assign av = new Assign(123); object[] pvs = new object[] { 234 }; av.Mutate(ref pvs[0]); Assert.AreEqual(123, (int) pvs[0]); } } } |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:40
|
Update of /cvsroot/dotnetmock/dotnetmock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588 Modified Files: .cvsignore Log Message: - Merged branch RFE_1001778 into head Index: .cvsignore =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** .cvsignore 31 Dec 2004 17:48:12 -0000 1.2 --- .cvsignore 1 Jan 2005 22:57:50 -0000 1.3 *************** *** 5,7 **** dist report ! DotNetMock.resharperoptions \ No newline at end of file --- 5,7 ---- dist report ! DotNetMock.resharperoptions |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:36
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock.Tests Modified Files: DotNetMock.Tests.csproj Log Message: - Merged branch RFE_1001778 into head Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DotNetMock.Tests.csproj 10 Oct 2004 06:52:32 -0000 1.12 --- DotNetMock.Tests.csproj 1 Jan 2005 22:57:51 -0000 1.13 *************** *** 160,163 **** --- 160,168 ---- /> <File + RelPath = "Dynamic\AssignTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\DynamicMockTests.cs" SubType = "Code" *************** *** 184,187 **** --- 189,197 ---- BuildAction = "Compile" /> + <File + RelPath = "Dynamic\Generate\ILUtilsTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> </Include> </Files> |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:26
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock Modified Files: DotNetMock.csproj Log Message: - Merged branch RFE_1001778 into head Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** DotNetMock.csproj 1 Jan 2005 01:44:49 -0000 1.27 --- DotNetMock.csproj 1 Jan 2005 22:58:07 -0000 1.28 *************** *** 205,208 **** --- 205,218 ---- /> <File + RelPath = "Dynamic\AbstractArgumentMutator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Dynamic\Assign.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\DynamicMock.cs" SubType = "Code" *************** *** 220,223 **** --- 230,238 ---- /> <File + RelPath = "Dynamic\IArgumentMutator.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\IDynamicMock.cs" SubType = "Code" *************** *** 225,228 **** --- 240,248 ---- /> <File + RelPath = "Dynamic\IMockedCallHandler.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\IPredicate.cs" SubType = "Code" *************** *** 235,238 **** --- 255,263 ---- /> <File + RelPath = "Dynamic\Generate\ILUtils.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Dynamic\Predicates\AndPredicate.cs" SubType = "Code" |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:25
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock/Dynamic Modified Files: DynamicMock.cs DynamicOrderedMock.cs ExpectationMethod.cs IDynamicMock.cs IPredicate.cs Added Files: AbstractArgumentMutator.cs Assign.cs IArgumentMutator.cs IMockedCallHandler.cs Log Message: - Merged branch RFE_1001778 into head --- NEW FILE: Assign.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports #endregion namespace DotNetMock.Dynamic { /// <summary> /// An argument expectation that assigns a new value to ref/out /// parameters. /// </summary> public class Assign : AbstractArgumentMutator { private object _newValue; /// <summary> /// Default constructor. /// </summary> /// <param name="newValue">Value to assgin when Mutate calls are performed.</param> public Assign(object newValue) { _newValue = newValue; } /// <summary> /// Exchanges the input parameter with the value originally associate with this instance. /// </summary> /// <param name="parameterValue">argument to change</param> public override void Mutate(ref object parameterValue) { parameterValue = _newValue; } } } --- NEW FILE: IArgumentMutator.cs --- #region License // need license #endregion #region Imports #endregion namespace DotNetMock.Dynamic { /// <summary> /// Interface for specifying an expected modification to an argument. /// </summary> /// <remarks> /// This interface is delegate-like but since we can't extend /// delegates, we need to go with this. /// </remarks> /// <author>Choy Rim</author> public interface IArgumentMutator { /// <summary> /// Mutate the argument value. /// </summary> /// <param name="argument">reference to argument that must be modified</param> void Mutate(ref object argument); } } Index: IDynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/IDynamicMock.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** IDynamicMock.cs 23 Aug 2004 02:36:01 -0000 1.4 --- IDynamicMock.cs 1 Jan 2005 22:58:07 -0000 1.5 *************** *** 8,12 **** /// </summary> /// <see cref="DynamicMock"/> ! public interface IDynamicMock : IMockObject { /// <summary> --- 8,12 ---- /// </summary> /// <see cref="DynamicMock"/> ! public interface IDynamicMock : IMockObject, IMockedCallHandler { /// <summary> *************** *** 49,57 **** /// </summary> void SetValue(string methodName, object returnVal); - - /// <summary> - /// Make a call to a mocked up method name to check it meets its expectations. - /// </summary> - object Call(string methodName, params object[] args); } } --- 49,52 ---- Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** DynamicMock.cs 1 Jan 2005 21:13:47 -0000 1.12 --- DynamicMock.cs 1 Jan 2005 22:58:07 -0000 1.13 *************** *** 1,11 **** using System; using System.Collections; using DotNetMock.Dynamic.Generate; namespace DotNetMock.Dynamic { /// <summary> ! /// Basic Dynamic Mock object /// </summary> public class DynamicMock : IDynamicMock { --- 1,20 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; using System.Collections; + using System.Reflection; + using DotNetMock.Dynamic.Generate; + #endregion namespace DotNetMock.Dynamic { /// <summary> ! /// Control class for creating mock objects during runtime. /// </summary> + /// <author>Griffin Caprio</author> + /// <author>Choy Rim</author> public class DynamicMock : IDynamicMock { *************** *** 168,179 **** } /// <summary> ! /// Method embedded into the generated mock object. Calls the method with the expected arguments, ! /// and verfies the method call against the set of expected methods. /// </summary> ! /// <param name="methodName">Method name to call</param> ! /// <param name="args">input arguments</param> ! /// <returns>Return value from method call, if any.</returns> ! public virtual object Call( string methodName, params object[] args ) { if (values.Contains(methodName)) { --- 177,188 ---- } /// <summary> ! /// Uses the given method to verify expectations for the method. /// </summary> ! /// <param name="mi">mathod called</param> ! /// <param name="args">arguments to the method</param> ! /// <returns>Return value, if any, from method call.</returns> ! public virtual object Call(MethodInfo mi, params object[] args) { + string methodName = getMethodName(mi); if (values.Contains(methodName)) { *************** *** 214,217 **** --- 223,241 ---- list.Add(e); } + /// <summary> + /// Returns the method name for the input <see cref="MethodInfo"/>. Accounts for property get and set methods. + /// </summary> + /// <param name="mi">method to get name from</param> + /// <returns>methond name for input method.</returns> + protected static string getMethodName( MethodInfo mi ) + { + string methodName = mi.Name; + if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) + { + methodName = methodName.Substring(4); + } + return methodName; + } + private void generate() { Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ExpectationMethod.cs 1 Jan 2005 21:13:50 -0000 1.8 --- ExpectationMethod.cs 1 Jan 2005 22:58:07 -0000 1.9 *************** *** 155,158 **** --- 155,164 ---- } Assertion.Assert(predicate.Eval(actualArg)); + // then handle mutators if any + IArgumentMutator mutator = expectedArg as IArgumentMutator; + if ( mutator!=null ) + { + mutator.Mutate(ref _methodArguments[i]); + } } Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DynamicOrderedMock.cs 1 Jan 2005 21:13:50 -0000 1.4 --- DynamicOrderedMock.cs 1 Jan 2005 22:58:07 -0000 1.5 *************** *** 1,4 **** --- 1,11 ---- + #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports using System; + using System.Reflection; + using System.Collections; + #endregion namespace DotNetMock.Dynamic *************** *** 37,47 **** } /// <summary> ! /// Calls the method on the mock object. /// </summary> ! /// <param name="methodName">Method name to call</param> ! /// <param name="args">Arguments to pass to the method</param> ! /// <returns>Return value, if any.</returns> ! public override object Call(string methodName, params object[] args) { if (values.Contains(methodName)) { --- 44,55 ---- } /// <summary> ! /// Uses the given method to verify expectations for the method. Also verifies method call order. /// </summary> ! /// <param name="mi">mathod called</param> ! /// <param name="args">arguments to the method</param> ! /// <returns>Return value, if any, from method call.</returns> ! public override object Call(MethodInfo mi, params object[] args) { + string methodName = getMethodName(mi); if (values.Contains(methodName)) { Index: IPredicate.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/IPredicate.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** IPredicate.cs 23 Aug 2004 02:36:01 -0000 1.5 --- IPredicate.cs 1 Jan 2005 22:58:07 -0000 1.6 *************** *** 10,16 **** /// A boolean result /// </summary> ! /// <param name="currentValue"></param> ! /// <returns></returns> ! bool Eval(object currentValue); } } --- 10,16 ---- /// A boolean result /// </summary> ! /// <param name="inputValue">Value to evaluate against</param> ! /// <returns>True/False if the current value equals the input value </returns> ! bool Eval(object inputValue); } } --- NEW FILE: IMockedCallHandler.cs --- #region License // Copyright (c) 2004 Choy Rim. All rights reserved. #endregion #region Imports using System.Reflection; #endregion namespace DotNetMock.Dynamic { /// <summary> /// Interface for handling mocked calls. /// </summary> /// <author>Choy Rim</author> public interface IMockedCallHandler { /// <summary> /// Mocked object calls this on any method call so that we can /// verify that the calls meet the expectations. /// </summary> object Call(MethodInfo mi, params object[] args); } } --- NEW FILE: AbstractArgumentMutator.cs --- #region License // need license #endregion #region Imports #endregion namespace DotNetMock.Dynamic { /// <summary> /// Abstract base class for all argument mutators. /// </summary> /// <author>Griffin Caprio</author> /// <author>Choy Rim</author> public abstract class AbstractArgumentMutator : IArgumentMutator, IPredicate { private IPredicate _predicate = null; /// <summary> /// Abstract method representing the exchanging of parameters /// </summary> /// <param name="argument">argument to change</param> public abstract void Mutate(ref object argument); /// <summary> /// Chains the current instance to another predicate to evaluate when exchanging parameters /// </summary> /// <param name="predicate"><see cref="IPredicate"/> to use for evaluation</param> /// <returns>reference to this instance</returns> public object AndRequire(IPredicate predicate) { _predicate = predicate; return this; } /// <summary> /// If there is no predicate associate with this mutator, returns true. Otherwise, evaluates the /// input value according to the predicate. /// </summary> /// <param name="inputValue">Value to evaluate</param> /// <returns>The Result of the predicate evaluation, or true if no predicate is assigned to this instance.</returns> public virtual bool Eval(object inputValue) { if ( _predicate==null ) { return true; } return _predicate.Eval(inputValue); } } } |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:21
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock.Tests/Dynamic/Generate Modified Files: ClassGeneratorTests.cs Added Files: ILUtilsTests.cs Log Message: - Merged branch RFE_1001778 into head Index: ClassGeneratorTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate/ClassGeneratorTests.cs,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ClassGeneratorTests.cs 9 Oct 2004 21:14:12 -0000 1.12 --- ClassGeneratorTests.cs 1 Jan 2005 22:57:51 -0000 1.13 *************** *** 7,10 **** --- 7,11 ---- using System.Reflection; using System.Reflection.Emit; + using System.Diagnostics; namespace DotNetMock.Tests.Dynamic.Generate *************** *** 74,77 **** --- 75,172 ---- } + interface IDirectionalParameters + { + void DoWithInParameters(int a, string b); + void DoWithRefParameters(ref int a, ref string b); + void DoWithOutParameters(out int a, out string b, out TimeSpan c); + } + + class DirectionalMockedCallHandler : + IMockedCallHandler + { + public MethodInfo MethodInfo + { + get { return _methodInfo; } + } + public object Call(MethodInfo mi, params object[] args) + { + _methodInfo = mi; + this.MethodName = mi.Name; + this.IncomingArgs = (object[]) args.Clone(); + if ( this.OutgoingArgs!=null ) + { + this.OutgoingArgs.CopyTo(args, 0); + } + return null; + } + + public object Call( string methodName, params object[] args ) + { + return null; + } + + public object[] IncomingArgs = null; + public object[] OutgoingArgs = null; + public string MethodName = null; + private MethodInfo _methodInfo = null; + } + + [Test] public void TestInParameters() + { + DirectionalMockedCallHandler dmch = + new DirectionalMockedCallHandler(); + IDirectionalParameters dp = (IDirectionalParameters) + cg.Generate(typeof(IDirectionalParameters), dmch); + dp.DoWithInParameters(1, "what"); + Assert.AreEqual("DoWithInParameters", dmch.MethodInfo.Name); + Assert.AreEqual("DoWithInParameters", dmch.MethodName); + Assert.AreEqual(2, dmch.IncomingArgs.Length); + Assert.AreEqual(1, dmch.IncomingArgs[0]); + Assert.AreEqual("what", dmch.IncomingArgs[1]); + } + + [Test] public void TestOutParameters() + { + DirectionalMockedCallHandler dmch = + new DirectionalMockedCallHandler(); + dmch.OutgoingArgs + = new object[] { + 2, + "when", + TimeSpan.FromSeconds(123) + }; + IDirectionalParameters dp = (IDirectionalParameters) + cg.Generate(typeof(IDirectionalParameters), dmch); + int a = 1; + string b = "what"; + TimeSpan c = TimeSpan.FromSeconds(321); + dp.DoWithOutParameters(out a, out b, out c); + Assert.AreEqual("DoWithOutParameters", dmch.MethodInfo.Name); + Assert.AreEqual("when", b); + Assert.AreEqual(TimeSpan.FromSeconds(123), c); + Assert.AreEqual(2, a); + Assert.AreEqual("DoWithOutParameters", dmch.MethodName); + Assert.AreEqual(3, dmch.IncomingArgs.Length); + } + + [Test] public void TestRefParameters() + { + DirectionalMockedCallHandler dmch = + new DirectionalMockedCallHandler(); + dmch.OutgoingArgs = new object[] { 2, "when" }; + IDirectionalParameters dp = (IDirectionalParameters) + cg.Generate(typeof(IDirectionalParameters), dmch); + int a = 1; + string b = "what"; + dp.DoWithRefParameters(ref a, ref b); + Assert.AreEqual("DoWithRefParameters", dmch.MethodInfo.Name); + Assert.AreEqual("DoWithRefParameters", dmch.MethodName); + Assert.AreEqual(2, dmch.IncomingArgs.Length); + Assert.AreEqual(1, dmch.IncomingArgs[0]); + Assert.AreEqual("what", dmch.IncomingArgs[1]); + Assert.AreEqual("when", b); + Assert.AreEqual(2, a); + } + [Test] public void CallMethodIsCalled() *************** *** 266,288 **** mock.Verify(); } ! ! [Test] ! public void BoxingOpCodes() ! { ! Assertion.AssertEquals( OpCodes.Ldind_I1, cg.GetBoxingOpCode(typeof(sbyte)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I2, cg.GetBoxingOpCode(typeof(short)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I4, cg.GetBoxingOpCode(typeof(int)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I8, cg.GetBoxingOpCode(typeof(long)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U1, cg.GetBoxingOpCode(typeof(byte)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U2, cg.GetBoxingOpCode(typeof(ushort)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U4, cg.GetBoxingOpCode(typeof(uint)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I8, cg.GetBoxingOpCode(typeof(ulong)) ); ! Assertion.AssertEquals( OpCodes.Ldind_R4, cg.GetBoxingOpCode(typeof(float)) ); ! Assertion.AssertEquals( OpCodes.Ldind_R8, cg.GetBoxingOpCode(typeof(double)) ); ! Assertion.AssertEquals( OpCodes.Ldind_U2, cg.GetBoxingOpCode(typeof(char)) ); ! Assertion.AssertEquals( OpCodes.Ldind_I1, cg.GetBoxingOpCode(typeof(bool)) ); ! Assertion.AssertEquals( OpCodes.Ldobj, cg.GetBoxingOpCode(typeof(Guid)) ); ! } ! [Test] public void ValueTypeParameter() --- 361,365 ---- mock.Verify(); } ! [Test] public void ValueTypeParameter() --- NEW FILE: ILUtilsTests.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. // until we agree on which open-source licnese to use. #endregion #region Imports using System; using System.Collections; using System.Reflection.Emit; using DotNetMock.Dynamic.Generate; using NUnit.Framework; #endregion namespace DotNetMock.Tests.Dynamic.Generate { [TestFixture] public class ILUtilsTests { [Test] public void LdindOpcodes() { Assert.AreEqual( OpCodes.Ldind_I1, ILUtils.GetLdindOpCodeForType(typeof(sbyte)) ); Assert.AreEqual( OpCodes.Ldind_I2, ILUtils.GetLdindOpCodeForType(typeof(short)) ); Assert.AreEqual( OpCodes.Ldind_I4, ILUtils.GetLdindOpCodeForType(typeof(int)) ); Assert.AreEqual( OpCodes.Ldind_I8, ILUtils.GetLdindOpCodeForType(typeof(long)) ); Assert.AreEqual( OpCodes.Ldind_U1, ILUtils.GetLdindOpCodeForType(typeof(byte)) ); Assert.AreEqual( OpCodes.Ldind_U2, ILUtils.GetLdindOpCodeForType(typeof(ushort)) ); Assert.AreEqual( OpCodes.Ldind_U4, ILUtils.GetLdindOpCodeForType(typeof(uint)) ); Assert.AreEqual( OpCodes.Ldind_I8, ILUtils.GetLdindOpCodeForType(typeof(ulong)) ); Assert.AreEqual( OpCodes.Ldind_R4, ILUtils.GetLdindOpCodeForType(typeof(float)) ); Assert.AreEqual( OpCodes.Ldind_R8, ILUtils.GetLdindOpCodeForType(typeof(double)) ); Assert.AreEqual( OpCodes.Ldind_U2, ILUtils.GetLdindOpCodeForType(typeof(char)) ); Assert.AreEqual( OpCodes.Ldind_I1, ILUtils.GetLdindOpCodeForType(typeof(bool)) ); Assert.AreEqual( OpCodes.Ldobj, ILUtils.GetLdindOpCodeForType(typeof(Guid)) ); Assert.AreEqual( OpCodes.Ldind_Ref, ILUtils.GetLdindOpCodeForType(typeof(object)) ); } [Test] public void StindOpcodes() { Assert.AreEqual( OpCodes.Stind_I1, ILUtils.GetStindOpCodeForType(typeof(sbyte)) ); Assert.AreEqual( OpCodes.Stind_I2, ILUtils.GetStindOpCodeForType(typeof(short)) ); Assert.AreEqual( OpCodes.Stind_I4, ILUtils.GetStindOpCodeForType(typeof(int)) ); Assert.AreEqual( OpCodes.Stind_I8, ILUtils.GetStindOpCodeForType(typeof(long)) ); Assert.AreEqual( OpCodes.Stind_I1, ILUtils.GetStindOpCodeForType(typeof(byte)) ); Assert.AreEqual( OpCodes.Stind_I2, ILUtils.GetStindOpCodeForType(typeof(ushort)) ); Assert.AreEqual( OpCodes.Stind_I4, ILUtils.GetStindOpCodeForType(typeof(uint)) ); Assert.AreEqual( OpCodes.Stind_I8, ILUtils.GetStindOpCodeForType(typeof(ulong)) ); Assert.AreEqual( OpCodes.Stind_R4, ILUtils.GetStindOpCodeForType(typeof(float)) ); Assert.AreEqual( OpCodes.Stind_R8, ILUtils.GetStindOpCodeForType(typeof(double)) ); Assert.AreEqual( OpCodes.Stind_I2, ILUtils.GetStindOpCodeForType(typeof(char)) ); Assert.AreEqual( OpCodes.Stind_I1, ILUtils.GetStindOpCodeForType(typeof(bool)) ); Assert.AreEqual( OpCodes.Stobj, ILUtils.GetStindOpCodeForType(typeof(Guid)) ); Assert.AreEqual( OpCodes.Stind_Ref, ILUtils.GetStindOpCodeForType(typeof(object)) ); } } } |
From: Griffin C. <gc...@us...> - 2005-01-01 22:58:19
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24588/DotNetMock/Dynamic/Generate Modified Files: ClassGenerator.cs Added Files: ILUtils.cs Log Message: - Merged branch RFE_1001778 into head --- NEW FILE: ILUtils.cs --- #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. // until we figure out what to put here #endregion #region Imports using System; using System.Collections; using System.Reflection.Emit; #endregion namespace DotNetMock.Dynamic.Generate { /// <summary> /// Utility functions for emitting IL. /// </summary> public class ILUtils { /// <summary> /// Return appropriate ldind <see cref="OpCode"/> for type /// referenced by address on top of stack (of emitted code). /// </summary> /// <param name="referencedType">type referenced by address /// on the top of the stack (of emitted code)</param> /// <returns>appropriate ldind <see cref="OpCode"/> that will /// load the stack with value in the address that is expected /// to be on the stack</returns> /// <remarks> /// If <see cref="OpCodes.Ldobj"/> is returned, then you must /// emit the <see cref="ValueType"/> with it. /// </remarks> public static OpCode GetLdindOpCodeForType(Type referencedType) { // short-circuit reference types if ( ! referencedType.IsValueType ) { return OpCodes.Ldind_Ref; } // must be a value type // check among primitive types // ensure table is initialized if (ldindOpCodes == null) { ldindOpCodes = new Hashtable(); ldindOpCodes[typeof(sbyte)] = OpCodes.Ldind_I1; ldindOpCodes[typeof(short)] = OpCodes.Ldind_I2; ldindOpCodes[typeof(int)] = OpCodes.Ldind_I4; ldindOpCodes[typeof(long)] = OpCodes.Ldind_I8; ldindOpCodes[typeof(byte)] = OpCodes.Ldind_U1; ldindOpCodes[typeof(ushort)] = OpCodes.Ldind_U2; ldindOpCodes[typeof(uint)] = OpCodes.Ldind_U4; ldindOpCodes[typeof(ulong)] = OpCodes.Ldind_I8; ldindOpCodes[typeof(float)] = OpCodes.Ldind_R4; ldindOpCodes[typeof(double)] = OpCodes.Ldind_R8; ldindOpCodes[typeof(char)] = OpCodes.Ldind_U2; ldindOpCodes[typeof(bool)] = OpCodes.Ldind_I1; } object opCodeObject = ldindOpCodes[referencedType]; if (opCodeObject != null) { return (OpCode) opCodeObject; } // must be non-primitive ValueType return OpCodes.Ldobj; } /// <summary> /// Return appropriate stind <see cref="OpCode"/> for type /// on top of stack (of emitted code). /// </summary> /// <param name="referencedType">type /// on the top of the stack (of emitted code)</param> /// <returns>appropriate stind <see cref="OpCode"/> that will /// store the value on the stack in the address below it</returns> /// <remarks> /// If <see cref="OpCodes.Stobj"/> is returned, then you must /// emit the <see cref="ValueType"/> with it. /// </remarks> public static OpCode GetStindOpCodeForType(Type referencedType) { // short-circuit reference types if ( ! referencedType.IsValueType ) { return OpCodes.Stind_Ref; } // must be a value type, first check among primitives // ensure primitive opcodes table is initialized if (stindOpCodes == null) { stindOpCodes = new Hashtable(); stindOpCodes[typeof(sbyte)] = OpCodes.Stind_I1; stindOpCodes[typeof(short)] = OpCodes.Stind_I2; stindOpCodes[typeof(int)] = OpCodes.Stind_I4; stindOpCodes[typeof(long)] = OpCodes.Stind_I8; stindOpCodes[typeof(byte)] = OpCodes.Stind_I1; stindOpCodes[typeof(ushort)] = OpCodes.Stind_I2; stindOpCodes[typeof(uint)] = OpCodes.Stind_I4; stindOpCodes[typeof(ulong)] = OpCodes.Stind_I8; stindOpCodes[typeof(float)] = OpCodes.Stind_R4; stindOpCodes[typeof(double)] = OpCodes.Stind_R8; stindOpCodes[typeof(char)] = OpCodes.Stind_I2; stindOpCodes[typeof(bool)] = OpCodes.Stind_I1; } object opCodeObject = stindOpCodes[referencedType]; if (opCodeObject != null) { return (OpCode) opCodeObject; } // must be non-primitive ValueType return OpCodes.Stobj; } /// <summary> /// Emit the appropriate ldind instruction(s) to load the /// specified type from the address on the stack. /// </summary> /// <param name="il">generator to emit code to</param> /// <param name="referencedType">the type in the address on /// the top of the stack</param> public static void EmitTypedLdind(ILGenerator il, Type referencedType) { OpCode opCode = GetLdindOpCodeForType(referencedType); if ( opCode.Equals(OpCodes.Ldobj) ) { il.Emit(opCode, referencedType); } else { il.Emit(opCode); } } /// <summary> /// Emit the appropriate stind instruction(s) to store the /// specified type from the top of the stack to the address /// bwlow it. /// </summary> /// <param name="il">generator to emit code to</param> /// <param name="referencedType">type of the value on the top of /// the stack</param> public static void EmitTypedStind(ILGenerator il, Type referencedType) { OpCode opCode = GetStindOpCodeForType(referencedType); if ( opCode.Equals(OpCodes.Stobj) ) { il.Emit(opCode, referencedType); } else { il.Emit(opCode); } } private static IDictionary ldindOpCodes = null; private static IDictionary stindOpCodes = null; } } Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/ClassGenerator.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ClassGenerator.cs 1 Jan 2005 21:13:51 -0000 1.7 --- ClassGenerator.cs 1 Jan 2005 22:58:08 -0000 1.8 *************** *** 1,6 **** --- 1,12 ---- + #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 *************** *** 11,29 **** public class ClassGenerator { ! private static IDictionary boxingOpCodes; /// <summary> ! /// Generates a proxy object for the input type, using the input <see cref="IDynamicMock"/> implementation. /// </summary> ! /// <param name="type"><see cref="System.Type"/> to generate proxy object for.</param> ! /// <param name="mock"><see cref="IDynamicMock"/> object containing the parameters for the proxy object</param> ! /// <returns>Generated proxy object</returns> ! public object Generate(Type type, IDynamicMock mock) { TypeBuilder typeBuilder = getTypeBuilder("Mock" + type.Name, type); ! FieldBuilder mockFieldBuilder = typeBuilder.DefineField("underlyingMock", typeof(IDynamicMock), FieldAttributes.Public); IList methods = getMethods(type); foreach ( MethodInfo m in methods ) { ! implementMethod(type, typeBuilder, m, mockFieldBuilder); } Type proxyType = typeBuilder.CreateType(); --- 17,57 ---- public class ClassGenerator { ! AssemblyBuilder _assemblyBuilder = null; ! ModuleBuilder _moduleBuilder = null; ! string _assemblyFilename = null; ! /// <summary> ! /// Create default instance of mock object generator. /// </summary> ! public ClassGenerator() ! { ! _assemblyBuilder = newAssemblyBuilder(AssemblyBuilderAccess.Run); ! _moduleBuilder = _assemblyBuilder.DefineDynamicModule("MockModule"); ! } ! ! /// <summary> ! /// Create mock object generator that can save. ! /// </summary> ! /// <param name="filename">filename to save to</param> ! public ClassGenerator(string filename) ! { ! _assemblyBuilder = newAssemblyBuilder(AssemblyBuilderAccess.RunAndSave); ! _moduleBuilder = _assemblyBuilder.DefineDynamicModule("MockModule", filename); ! _assemblyFilename = filename; ! } ! /// <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(); *************** *** 31,34 **** --- 59,66 ---- FieldInfo underlyingMock = proxyType.GetField("underlyingMock"); underlyingMock.SetValue(result, mock); + if ( _assemblyFilename!=null ) + { + _assemblyBuilder.Save(_assemblyFilename); + } return result; } *************** *** 59,67 **** private TypeBuilder getTypeBuilder(string name, Type originalType) { - AppDomain appDomain = AppDomain.CurrentDomain; - AssemblyName assemblyName = new AssemblyName(); - assemblyName.Name = "DynamicMockAssembly"; - AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); - ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MockModule"); Type superClass; Type[] interfaces; --- 91,94 ---- *************** *** 76,83 **** interfaces = new Type[0]; } ! return moduleBuilder.DefineType(name, TypeAttributes.Public, superClass, interfaces); } ! private void implementMethod(Type type, TypeBuilder typeBuilder, MethodInfo m, FieldBuilder mockFieldBuilder) { Type returnType = m.ReturnType; --- 103,110 ---- 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; *************** *** 94,97 **** --- 121,125 ---- il.DeclareLocal(typeof(object[])); + // TODO: why are we declaring all these locals? foreach (ParameterInfo param in m.GetParameters()) { *************** *** 99,133 **** } - string methodName = m.Name; - if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) - { - methodName = methodName.Substring(4); - } - il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldfld, mockFieldBuilder); ! il.Emit(OpCodes.Ldstr, methodName); ! il.Emit(OpCodes.Ldc_I4_S, paramTypes.Length); il.Emit(OpCodes.Newarr, typeof(object)); if (paramTypes.Length > 0) { - il.Emit(OpCodes.Stloc_0); - il.Emit(OpCodes.Ldloc_0); - for(int i = 0; i < paramTypes.Length; i++) { ! il.Emit(OpCodes.Ldc_I4_S, i); ! il.Emit(OpCodes.Ldarg_S, i + 1); ! if (paramTypes[i].IsValueType) { ! il.Emit(OpCodes.Box, paramTypes[i]); } il.Emit(OpCodes.Stelem_Ref); - il.Emit(OpCodes.Ldloc_0); } } ! MethodInfo call = typeof(IDynamicMock).GetMethod("Call"); il.EmitCall(OpCodes.Callvirt, call, null); --- 127,171 ---- } 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); *************** *** 141,199 **** { il.Emit(OpCodes.Unbox, returnType); ! if (returnType.IsPrimitive) ! { ! il.Emit(GetBoxingOpCode(returnType)); ! } ! else { ! il.Emit(GetBoxingOpCode(returnType), returnType); } } } il.Emit(OpCodes.Ret); } ! /// <summary> ! /// Returns the IL <see cref="System.Reflection.Emit.OpCode"/> for the input type. ! /// </summary> ! /// <param name="currentType">Type to return op code for.</param> ! /// <returns>Op Code for input type.</returns> ! public OpCode GetBoxingOpCode( Type currentType ) { ! if (boxingOpCodes == null) ! { ! boxingOpCodes = new Hashtable(); ! boxingOpCodes[typeof(sbyte)] = OpCodes.Ldind_I1; ! boxingOpCodes[typeof(short)] = OpCodes.Ldind_I2; ! boxingOpCodes[typeof(int)] = OpCodes.Ldind_I4; ! boxingOpCodes[typeof(long)] = OpCodes.Ldind_I8; ! boxingOpCodes[typeof(byte)] = OpCodes.Ldind_U1; ! boxingOpCodes[typeof(ushort)] = OpCodes.Ldind_U2; ! boxingOpCodes[typeof(uint)] = OpCodes.Ldind_U4; ! boxingOpCodes[typeof(ulong)] = OpCodes.Ldind_I8; ! boxingOpCodes[typeof(float)] = OpCodes.Ldind_R4; ! boxingOpCodes[typeof(double)] = OpCodes.Ldind_R8; ! boxingOpCodes[typeof(char)] = OpCodes.Ldind_U2; ! boxingOpCodes[typeof(bool)] = OpCodes.Ldind_I1; ! } ! ! OpCode opCode; ! object opCodeObject = boxingOpCodes[currentType]; ! ! if (opCodeObject != null) ! { ! opCode = (OpCode)opCodeObject; ! } ! else if (!currentType.IsValueType) ! { ! opCode = OpCodes.Ldind_I1; ! } ! else ! { ! opCode = OpCodes.Ldobj; ! } ! ! return opCode; } - } --- 179,222 ---- { 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) { ! AppDomain appDomain = AppDomain.CurrentDomain; ! AssemblyName assemblyName = new AssemblyName(); ! assemblyName.Name = "DynamicMockAssembly"; ! return appDomain.DefineDynamicAssembly( assemblyName, access ); } } |
From: Griffin C. <gc...@us...> - 2005-01-01 22:38:11
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15142/DotNetMock/Dynamic Modified Files: Tag: RFE_1001778 DynamicMock.cs DynamicOrderedMock.cs Log Message: - Fixed missing XML comments errors. Index: DynamicOrderedMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicOrderedMock.cs,v retrieving revision 1.3.2.4 retrieving revision 1.3.2.5 diff -C2 -d -r1.3.2.4 -r1.3.2.5 *** DynamicOrderedMock.cs 1 Jan 2005 22:32:08 -0000 1.3.2.4 --- DynamicOrderedMock.cs 1 Jan 2005 22:37:49 -0000 1.3.2.5 *************** *** 43,46 **** --- 43,52 ---- } } + /// <summary> + /// Uses the given method to verify expectations for the method. Also verifies method call order. + /// </summary> + /// <param name="mi">mathod called</param> + /// <param name="args">arguments to the method</param> + /// <returns>Return value, if any, from method call.</returns> public override object Call(MethodInfo mi, params object[] args) { Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/DynamicMock.cs,v retrieving revision 1.11.2.4 retrieving revision 1.11.2.5 diff -C2 -d -r1.11.2.4 -r1.11.2.5 *** DynamicMock.cs 1 Jan 2005 22:32:08 -0000 1.11.2.4 --- DynamicMock.cs 1 Jan 2005 22:37:49 -0000 1.11.2.5 *************** *** 176,179 **** --- 176,185 ---- values[methodName] = returnVal; } + /// <summary> + /// Uses the given method to verify expectations for the method. + /// </summary> + /// <param name="mi">mathod called</param> + /// <param name="args">arguments to the method</param> + /// <returns>Return value, if any, from method call.</returns> public virtual object Call(MethodInfo mi, params object[] args) { *************** *** 217,221 **** list.Add(e); } ! protected static string getMethodName( MethodInfo mi ) { --- 223,231 ---- list.Add(e); } ! /// <summary> ! /// Returns the method name for the input <see cref="MethodInfo"/>. Accounts for property get and set methods. ! /// </summary> ! /// <param name="mi">method to get name from</param> ! /// <returns>methond name for input method.</returns> protected static string getMethodName( MethodInfo mi ) { |
From: Griffin C. <gc...@us...> - 2005-01-01 22:38:11
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15142/DotNetMock/Dynamic/Generate Modified Files: Tag: RFE_1001778 ClassGenerator.cs Log Message: - Fixed missing XML comments errors. Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/ClassGenerator.cs,v retrieving revision 1.6.2.10 retrieving revision 1.6.2.11 diff -C2 -d -r1.6.2.10 -r1.6.2.11 *** ClassGenerator.cs 1 Jan 2005 22:32:08 -0000 1.6.2.10 --- ClassGenerator.cs 1 Jan 2005 22:37:49 -0000 1.6.2.11 *************** *** 40,43 **** --- 40,49 ---- _assemblyFilename = filename; } + /// <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) { |