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...> - 2006-03-06 02:25:00
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10746/DotNetMock.Tests/Dynamic Modified Files: AbstractDynamicMockTests.cs DynamicMockTests.cs DynamicOrderedMockTests.cs MethodCallTests.cs PredicateTests.cs Log Message: - Merged in changes from Niklas Index: DynamicOrderedMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicOrderedMockTests.cs,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** DynamicOrderedMockTests.cs 19 Feb 2005 21:47:56 -0000 1.8 --- DynamicOrderedMockTests.cs 6 Mar 2006 02:24:57 -0000 1.9 *************** *** 5,9 **** using System; using System.Reflection; - using DotNetMock.Dynamic.Predicates; using NUnit.Framework; using DotNetMock.Dynamic; --- 5,8 ---- *************** *** 35,39 **** public void CallMoreMethodsThanExpected() { ! mock.Expect("myMethod1"); mock.Expect("myMethod2"); mock.Call(myMethod1); --- 34,39 ---- public void CallMoreMethodsThanExpected() { ! IDynamicMock mock = newDynamicMock(typeof(IBlah)); ! mock.Expect("myMethod1"); mock.Expect("myMethod2"); mock.Call(myMethod1); *************** *** 47,51 **** public void CallMultipleMethodsInWrongOrder() { ! mock.Expect("myMethod1"); mock.Expect("myMethod2"); mock.Expect("myMethod3"); --- 47,52 ---- public void CallMultipleMethodsInWrongOrder() { ! IDynamicMock mock = newDynamicMock(typeof(IBlah)); ! mock.Expect("myMethod1"); mock.Expect("myMethod2"); mock.Expect("myMethod3"); Index: DynamicMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/DynamicMockTests.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** DynamicMockTests.cs 12 Feb 2005 18:10:36 -0000 1.19 --- DynamicMockTests.cs 6 Mar 2006 02:24:57 -0000 1.20 *************** *** 8,12 **** using NUnit.Framework; - using DotNetMock.Dynamic.Predicates; #endregion --- 8,11 ---- *************** *** 32,42 **** public void CallMultipleMethodsInWrongOrder() { ! mock.Expect("myMethod1"); ! mock.Expect("myMethod2"); ! mock.Expect("myMethod3"); ! mock.Call(myMethod1); ! mock.Call(myMethod3); ! mock.Call(myMethod2); ! mock.Verify(); } --- 31,42 ---- public void CallMultipleMethodsInWrongOrder() { ! IDynamicMock mock2 = newDynamicMock(typeof(IBlah)); ! mock2.Expect("myMethod1"); ! mock2.Expect("myMethod2"); ! mock2.Expect("myMethod3"); ! mock2.Call(myMethod1); ! mock2.Call(myMethod3); ! mock2.Call(myMethod2); ! mock2.Verify(); } *************** *** 45,50 **** public void NoCallToVoidMethodWithReason() { ! mock.Expect("myMethod"); ! mock.Verify(); } --- 45,51 ---- public void NoCallToVoidMethodWithReason() { ! IDynamicMock mock2 = newDynamicMock(typeof(IBlah)); ! mock2.Expect("myMethod"); ! mock2.Verify(); } *************** *** 53,64 **** public void ThrowsIfUnexpectedMethodCalled() { ! IDynamicMock mock = newDynamicMock(typeof(IBlah)); ! IBlah blah = (IBlah) mock.Object; ! mock.Strict = true; ! mock.ExpectAndReturn("DoStuff", "world", "hello"); Assert.AreEqual("world", blah.DoStuff("hello")); blah.DoStuffWithParams("ID", "P1", "P2"); ! mock.Verify(); } --- 54,65 ---- public void ThrowsIfUnexpectedMethodCalled() { ! IDynamicMock mock2 = newDynamicMock(typeof(IBlah)); ! IBlah blah = (IBlah) mock2.Object; ! mock2.Strict = true; ! mock2.ExpectAndReturn("DoStuff", "world", "hello"); Assert.AreEqual("world", blah.DoStuff("hello")); blah.DoStuffWithParams("ID", "P1", "P2"); ! mock2.Verify(); } *************** *** 66,73 **** public void CustomDynamicMock() { ! IDynamicMock mock = new CustomMock(typeof(IBlah)); ! IBlah blah = (IBlah)mock.Object; Assert.AreEqual("CUSTOM", blah.DoStuff("hello")); ! mock.Verify(); } private class CustomMock : DynamicMock --- 67,74 ---- public void CustomDynamicMock() { ! IDynamicMock mock2 = new CustomMock(typeof(IBlah)); ! IBlah blah = (IBlah)mock2.Object; Assert.AreEqual("CUSTOM", blah.DoStuff("hello")); ! mock2.Verify(); } private class CustomMock : DynamicMock Index: PredicateTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/PredicateTests.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** PredicateTests.cs 25 Apr 2005 00:14:47 -0000 1.15 --- PredicateTests.cs 6 Mar 2006 02:24:57 -0000 1.16 *************** *** 29,33 **** { Assert.AreEqual( ! "value is within 0.1 of 1", new IsCloseTo( 1, 0.1 ).ToString( ) ); --- 29,33 ---- { Assert.AreEqual( ! "value is within "+ 0.1 +" of 1", new IsCloseTo( 1, 0.1 ).ToString( ) ); *************** *** 73,77 **** { Assert.AreEqual( ! "value is in [1, 'two', 3.4]", new IsIn( 1, "two", 3.4 ).ToString( ) ); --- 73,77 ---- { Assert.AreEqual( ! "value is in [1, 'two', "+3.4+"]", new IsIn( 1, "two", 3.4 ).ToString( ) ); *************** *** 114,118 **** { Assert.AreEqual( ! "value is not in [1, 'two', 3.4]", new NotIn( 1, "two", 3.4 ).ToString( ) ); --- 114,118 ---- { Assert.AreEqual( ! "value is not in [1, 'two', "+3.4+"]", new NotIn( 1, "two", 3.4 ).ToString( ) ); Index: MethodCallTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/MethodCallTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MethodCallTests.cs 11 May 2005 04:08:31 -0000 1.5 --- MethodCallTests.cs 6 Mar 2006 02:24:57 -0000 1.6 *************** *** 81,85 **** { MethodCall mc = new MethodCall(method3, 1, "two", 3.4); ! Assert.AreEqual("Method3(x=1, y=\"two\", z=3.4)", mc.ToString()); mc = new MethodCall(method4); Assert.AreEqual("Method4()", mc.ToString()); --- 81,85 ---- { MethodCall mc = new MethodCall(method3, 1, "two", 3.4); ! Assert.AreEqual("Method3(x=1, y=\"two\", z="+3.4+")", mc.ToString()); mc = new MethodCall(method4); Assert.AreEqual("Method4()", mc.ToString()); Index: AbstractDynamicMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/AbstractDynamicMockTests.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractDynamicMockTests.cs 11 May 2005 05:17:14 -0000 1.5 --- AbstractDynamicMockTests.cs 6 Mar 2006 02:24:57 -0000 1.6 *************** *** 13,17 **** namespace DotNetMock.Tests.Dynamic { ! [TestFixture] public abstract class AbstractDynamicMockTests { --- 13,17 ---- namespace DotNetMock.Tests.Dynamic { ! public abstract class AbstractDynamicMockTests { *************** *** 20,24 **** protected MethodInfo myMethod1; protected MethodInfo myMethod2; ! protected MethodInfo myMethod3; protected MethodInfo anotherMethod; protected MethodInfo method0; --- 20,25 ---- protected MethodInfo myMethod1; protected MethodInfo myMethod2; ! protected MethodInfo myMethod3; ! protected MethodInfo myEnumMethod; protected MethodInfo anotherMethod; protected MethodInfo method0; *************** *** 45,50 **** protected abstract IDynamicMock newDynamicMock(Type type); protected abstract IDynamicMock newDynamicMock(string name); ! ! protected interface IBlah { object DoStuff(string name); --- 46,51 ---- protected abstract IDynamicMock newDynamicMock(Type type); protected abstract IDynamicMock newDynamicMock(string name); ! public enum MyEnum { One, Two }; ! public interface IBlah { object DoStuff(string name); *************** *** 57,62 **** void myMethod1(); void myMethod2(); ! void myMethod3(); ! void anotherMethod(); void Method0(object p0, object p1); object Method1(object p0); --- 58,63 ---- void myMethod1(); void myMethod2(); ! void myMethod3(); ! void anotherMethod(); void Method0(object p0, object p1); object Method1(object p0); *************** *** 90,95 **** 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]); method0 = typeof(IBlah).GetMethod("Method0"); method1 = typeof(IBlah).GetMethod("Method1"); --- 91,96 ---- 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]); method0 = typeof(IBlah).GetMethod("Method0"); method1 = typeof(IBlah).GetMethod("Method1"); *************** *** 290,294 **** --- 291,324 ---- mock.Verify(); } + + + [Test] + public void NoCallExpectedToVoidMethod() + { + mock.ExpectNoCall("myMethod"); + mock.Verify(); + } + [Test] + public void MixedCallNoCallExpectedToVoidMethod() + { + mock.Expect("myMethod"); + mock.ExpectNoCall("myMethod1"); + mock.ExpectNoCall("myMethod1"); + mock.ExpectNoCall("myMethod2"); + mock.Call(myMethod); + mock.Verify(); + } + [Test] + [ExpectedException(typeof(AssertionException))] + public void NoCallExpectedButCalledToVoidMethod() + { + mock.ExpectNoCall("myMethod"); + mock.Call(myMethod); + mock.Verify(); + } + + + [Test] public void CallToMethodWithParams() |
From: Choy R. <ch...@us...> - 2005-05-11 05:42:41
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4872/DotNetMock/Dynamic Modified Files: MethodCall.cs Log Message: Error in comment - I meant OR. Index: MethodCall.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/MethodCall.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MethodCall.cs 11 May 2005 04:08:32 -0000 1.5 --- MethodCall.cs 11 May 2005 05:42:24 -0000 1.6 *************** *** 66,70 **** } /// <summary> ! /// Are we accessing a property of calling a typical method? /// </summary> public bool IsPropertyAccess --- 66,70 ---- } /// <summary> ! /// Are we accessing a property or calling a typical method? /// </summary> public bool IsPropertyAccess |
From: Choy R. <ch...@us...> - 2005-05-11 05:22:31
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2203/DotNetMock/Dynamic Modified Files: ExpectationMethod.cs Log Message: BUG [ 1199222 ] Does not cast return value well * Fixed an error in that last fix. Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** ExpectationMethod.cs 11 May 2005 05:17:14 -0000 1.25 --- ExpectationMethod.cs 11 May 2005 05:22:22 -0000 1.26 *************** *** 270,276 **** // in the IL that unboxes the return value. Type expectedReturnType = _expectedReturnValue.GetType(); ! if ( expectedReturnType.IsValueType ) { - Type returnType = ActualMethod.ReturnType; if ( returnType!=expectedReturnType ) { --- 270,276 ---- // in the IL that unboxes the return value. Type expectedReturnType = _expectedReturnValue.GetType(); ! Type returnType = ActualMethod.ReturnType; ! if ( returnType!=typeof(void) && returnType.IsValueType ) { if ( returnType!=expectedReturnType ) { |
From: Choy R. <ch...@us...> - 2005-05-11 05:17:28
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1535/DotNetMock.Tests/Dynamic Modified Files: AbstractDynamicMockTests.cs ExpectationMethodTests.cs Log Message: BUG [ 1199222 ] Does not cast return value well * Do a simple conversion using Convert.ChangeType on the return value if necessary. It is necessary if the return type is a value type and the return type of the method is not the same as the type of the specified return value. Index: ExpectationMethodTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/ExpectationMethodTests.cs,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ExpectationMethodTests.cs 8 Apr 2005 02:57:09 -0000 1.15 --- ExpectationMethodTests.cs 11 May 2005 05:17:14 -0000 1.16 *************** *** 26,29 **** --- 26,30 ---- void Method4(int x); void Method4(int x, int y); + long Method5(); } *************** *** 39,43 **** --- 40,55 ---- new Type[] { typeof(int), typeof(int) } ); + static readonly MethodInfo method5 = typeof(IMethods).GetMethod("Method5"); + [Test] public void ProvideReturnValueWithWrongType() + { + methodCallExpectation = new ExpectationMethod( + method5.Name, + 123 + ); + MethodCall call = new MethodCall(method5); + object returnValue = methodCallExpectation.CheckCallAndSendResponse(call); + methodCallExpectation.Verify(); + } [ExpectedException( typeof(AssertionException), Index: AbstractDynamicMockTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/AbstractDynamicMockTests.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AbstractDynamicMockTests.cs 8 Apr 2005 02:57:09 -0000 1.4 --- AbstractDynamicMockTests.cs 11 May 2005 05:17:14 -0000 1.5 *************** *** 33,36 **** --- 33,40 ---- new Type[] { typeof(int), typeof(int) } ); + protected static readonly MethodInfo METHOD3 = + typeof(IBlah).GetMethod("Method3"); + protected static readonly MethodInfo METHOD4 = + typeof(IBlah).GetMethod("Method4"); *************** *** 60,63 **** --- 64,85 ---- void Method2(int a); void Method2(int a, int b); + + long Method3(); + int Method4(); + } + + protected struct CanBeCastToLongExplicitly + { + public static explicit operator long(CanBeCastToLongExplicitly v) + { + return 0; + } + } + protected struct CanBeCastToLongImplicitly + { + public static implicit operator long(CanBeCastToLongImplicitly v) + { + return 0; + } } *************** *** 74,77 **** --- 96,153 ---- } + [Test] public void ReturnDifferentReferenceType() + { + IDynamicMock mock = newDynamicMock(typeof(IBlah)); + IBlah blah = (IBlah) mock.Object; + mock.ExpectAndReturn("Method1", + 123, + 1 + ); + + object r = blah.Method1(1); + Assert.AreEqual(123, r); + mock.Verify(); + } + + [ExpectedException(typeof(InvalidCastException))] + [Test] public void ReturnWrongImplicitlyCastableValueType() + { + IDynamicMock mock = newDynamicMock(typeof(IBlah)); + IBlah blah = (IBlah) mock.Object; + mock.ExpectAndReturn("Method3", + new CanBeCastToLongImplicitly() + ); + + long r = blah.Method3(); + Assert.AreEqual(0, r); + mock.Verify(); + } + [ExpectedException(typeof(InvalidCastException))] + [Test] public void ReturnWrongExplicitlyCastableValueType() + { + IDynamicMock mock = newDynamicMock(typeof(IBlah)); + IBlah blah = (IBlah) mock.Object; + mock.ExpectAndReturn("Method3", + new CanBeCastToLongExplicitly() + ); + + long r = blah.Method3(); + Assert.AreEqual(0, r); + mock.Verify(); + } + + [Test] public void ReturnWrongValueType() + { + IDynamicMock mock = newDynamicMock(typeof(IBlah)); + IBlah blah = (IBlah) mock.Object; + mock.ExpectAndReturn("Method3", + 123 + ); + + long r = blah.Method3(); + Assert.AreEqual(123, r); + mock.Verify(); + } + [ExpectedException(typeof(AssertionException))] [Test] public void FailsIfPassedTooManyArguments() *************** *** 289,296 **** mock.ExpectAndReturn("myMethod", something); mock.ExpectAndReturn("myMethod", anotherthing); ! mock.ExpectAndReturn("myMethod", x); Assert.AreEqual(something, mock.Call(myMethod)); Assert.AreEqual(anotherthing, mock.Call(myMethod)); ! Assert.AreEqual(x, mock.Call(myMethod)); mock.Verify(); } --- 365,372 ---- mock.ExpectAndReturn("myMethod", something); mock.ExpectAndReturn("myMethod", anotherthing); ! mock.ExpectAndReturn("Method4", x); Assert.AreEqual(something, mock.Call(myMethod)); Assert.AreEqual(anotherthing, mock.Call(myMethod)); ! Assert.AreEqual(x, mock.Call(METHOD4)); mock.Verify(); } |
From: Choy R. <ch...@us...> - 2005-05-11 05:17:28
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1535/DotNetMock/Dynamic Modified Files: ExpectationMethod.cs Log Message: BUG [ 1199222 ] Does not cast return value well * Do a simple conversion using Convert.ChangeType on the return value if necessary. It is necessary if the return type is a value type and the return type of the method is not the same as the type of the specified return value. Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** ExpectationMethod.cs 25 Apr 2005 03:26:31 -0000 1.24 --- ExpectationMethod.cs 11 May 2005 05:17:14 -0000 1.25 *************** *** 265,268 **** --- 265,282 ---- } } + if ( _expectedReturnValue!=null ) + { + // handle return values that are ValueTypes and ensure they can be casted + // in the IL that unboxes the return value. + Type expectedReturnType = _expectedReturnValue.GetType(); + if ( expectedReturnType.IsValueType ) + { + Type returnType = ActualMethod.ReturnType; + if ( returnType!=expectedReturnType ) + { + _expectedReturnValue = Convert.ChangeType(_expectedReturnValue, returnType); + } + } + } // if exception setup to be thrown, throw it if ( _expectedException != null ) |
From: Choy R. <ch...@us...> - 2005-05-11 04:08:40
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22636/DotNetMock/Dynamic Modified Files: MethodCall.cs Log Message: BUG [ 1194538 ] MethodCall::MethodName property has "somewhat-invalid" logic * needed to pass through the SpecialName attribute to the created mock method on the proxy type. * added check for IsSpecialName in handling of property access method calls. Index: MethodCall.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/MethodCall.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MethodCall.cs 25 Apr 2005 03:26:31 -0000 1.4 --- MethodCall.cs 11 May 2005 04:08:32 -0000 1.5 *************** *** 58,64 **** { string name = _method.Name; ! if ( name.StartsWith("get_") || name.StartsWith("set_") ) { ! name = name.Substring(4); } return name; --- 58,64 ---- { string name = _method.Name; ! if ( IsPropertyAccess ) { ! return name.Substring(4); } return name; *************** *** 66,69 **** --- 66,84 ---- } /// <summary> + /// Are we accessing a property of calling a typical method? + /// </summary> + public bool IsPropertyAccess + { + get + { + if ( ! _method.IsSpecialName ) + { + return false; + } + string name = _method.Name; + return name.StartsWith("get_") || name.StartsWith("set_"); + } + } + /// <summary> /// Check if given and this object represent the same method call. /// </summary> *************** *** 159,163 **** /// </summary> public object[] Arguments { get { return _arguments; } } - } } --- 174,177 ---- |
From: Choy R. <ch...@us...> - 2005-05-11 04:08:40
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22636/DotNetMock/Dynamic/Generate Modified Files: MockClassBuilder.cs Log Message: BUG [ 1194538 ] MethodCall::MethodName property has "somewhat-invalid" logic * needed to pass through the SpecialName attribute to the created mock method on the proxy type. * added check for IsSpecialName in handling of property access method calls. Index: MockClassBuilder.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/MockClassBuilder.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockClassBuilder.cs 23 Apr 2005 21:53:33 -0000 1.3 --- MockClassBuilder.cs 11 May 2005 04:08:32 -0000 1.4 *************** *** 149,156 **** "Cannot add methods after class has been compiled." ); ! } MethodBuilder methodBuilder = _typeBuilder.DefineMethod( methodName, ! MethodAttributes.Public | MethodAttributes.Virtual, returnType, parameterTypes --- 149,163 ---- "Cannot add methods after class has been compiled." ); ! } ! MethodAttributes attributes = MethodAttributes.Public | ! MethodAttributes.Virtual; ! if ( mi!=null ) ! { ! // only overlay SpecialName attribute ! attributes |= mi.Attributes & (MethodAttributes.SpecialName); ! } MethodBuilder methodBuilder = _typeBuilder.DefineMethod( methodName, ! attributes, returnType, parameterTypes |
From: Choy R. <ch...@us...> - 2005-05-11 04:08:40
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22636/DotNetMock.Tests/Dynamic Modified Files: MethodCallTests.cs Log Message: BUG [ 1194538 ] MethodCall::MethodName property has "somewhat-invalid" logic * needed to pass through the SpecialName attribute to the created mock method on the proxy type. * added check for IsSpecialName in handling of property access method calls. Index: MethodCallTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/MethodCallTests.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** MethodCallTests.cs 8 Apr 2005 01:21:50 -0000 1.4 --- MethodCallTests.cs 11 May 2005 04:08:31 -0000 1.5 *************** *** 28,31 **** --- 28,34 ---- void Method5(ToStringThrows x); + + int get_method6(); + void set_method6(); } interface IMethodsA *************** *** 53,62 **** --- 56,78 ---- static readonly MethodInfo property0_set = typeof(IMethods).GetMethod("set_Property0"); static readonly MethodInfo method5 = typeof(IMethods).GetMethod("Method5"); + static readonly MethodInfo get_method6 = typeof(IMethods).GetMethod("get_method6"); + static readonly MethodInfo set_method6 = typeof(IMethods).GetMethod("set_method6"); + [Test] public void MethodNameWorksForMethodsWithNamesLikePropertyAccessors() + { + MethodCall mc = new MethodCall(get_method6); + Assert.IsFalse(mc.IsPropertyAccess); + Assert.AreEqual("get_method6", mc.MethodName); + mc = new MethodCall(set_method6); + Assert.IsFalse(mc.IsPropertyAccess); + Assert.AreEqual("set_method6", mc.MethodName); + } [Test] public void MethodNameStripsPrefixOnProperties() { MethodCall gc = new MethodCall(property0_get); + Assert.IsTrue(gc.IsPropertyAccess); Assert.AreEqual("Property0", gc.MethodName); MethodCall sc = new MethodCall(property0_set, 1); + Assert.IsTrue(sc.IsPropertyAccess); Assert.AreEqual("Property0", sc.MethodName); } |
From: Choy R. <ch...@us...> - 2005-05-11 04:08:40
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22636/DotNetMock.Tests/Dynamic/Generate Modified Files: ClassGeneratorTests.cs Log Message: BUG [ 1194538 ] MethodCall::MethodName property has "somewhat-invalid" logic * needed to pass through the SpecialName attribute to the created mock method on the proxy type. * added check for IsSpecialName in handling of property access method calls. Index: ClassGeneratorTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate/ClassGeneratorTests.cs,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ClassGeneratorTests.cs 23 Apr 2005 21:53:33 -0000 1.18 --- ClassGeneratorTests.cs 11 May 2005 04:08:31 -0000 1.19 *************** *** 133,136 **** --- 133,142 ---- private MethodInfo _methodInfo = null; } + [Test] public void ReadPropertyGetIsSpecialName() + { + Type mot = thingy.GetType(); + MethodInfo get_ReadProperty = mot.GetMethod("get_ReadProperty"); + Assert.IsTrue(get_ReadProperty.IsSpecialName); + } [Test] public void SaveGeneratedAssembly() |
From: Griffin C. <gc...@us...> - 2005-04-25 03:53:18
|
Update of /cvsroot/dotnetmock/dotnetmock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18036 Modified Files: DotNetMock.build Log Message: - Updated build number Index: DotNetMock.build =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.build,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** DotNetMock.build 25 Feb 2005 16:10:00 -0000 1.26 --- DotNetMock.build 25 Apr 2005 03:53:10 -0000 1.27 *************** *** 6,10 **** <property name="VisualStudioTemplates2003" value="VisualStudioTemplates2003" /> <property name="project.name" value="DotNetMock" /> ! <property name="version" value="0.7.5" /> <property name="build.dir" value="build/" /> <property name="dist.dir" value="dist" /> --- 6,10 ---- <property name="VisualStudioTemplates2003" value="VisualStudioTemplates2003" /> <property name="project.name" value="DotNetMock" /> ! <property name="version" value="0.7.6" /> <property name="build.dir" value="build/" /> <property name="dist.dir" value="dist" /> |
From: Griffin C. <gc...@us...> - 2005-04-25 03:52:59
|
Update of /cvsroot/dotnetmock/dotnetmock/docs/ChangeLogs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17716/docs/ChangeLogs Modified Files: Changes-0.7.6.txt Log Message: - Updated Change log Index: Changes-0.7.6.txt =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/docs/ChangeLogs/Changes-0.7.6.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Changes-0.7.6.txt 23 Apr 2005 20:58:23 -0000 1.1 --- Changes-0.7.6.txt 25 Apr 2005 03:52:36 -0000 1.2 *************** *** 1 **** ! - Fixed bug 1174059 ( Thanks Kari Hirvi ) \ No newline at end of file --- 1,3 ---- ! - Fixed bug 1174059 ( Thanks Kari Hirvi ) ! - Added ExpectationStringQueue class ( Thanks to Evhen Khasenevich ) ! - Updated MockCommand to use ExpectationStringQueue class for command text values. \ No newline at end of file |
From: Griffin C. <gc...@us...> - 2005-04-25 03:37:54
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10796/DotNetMock.Framework/Data Modified Files: MockCommand.cs Log Message: - Updated MockCommand object to use ExpectationStringQueue class for commant text values Index: MockCommand.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework/Data/MockCommand.cs,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** MockCommand.cs 5 Feb 2005 22:05:09 -0000 1.19 --- MockCommand.cs 25 Apr 2005 03:37:45 -0000 1.20 *************** *** 10,14 **** public class MockCommand : MockObject, IDbCommand, ICloneable { ! private ExpectationString _commandText = new ExpectationString("MockCommand.CommandText"); private ExpectationValue _commandTimeout = new ExpectationValue("MockCommand.CommandTimeout"); private ExpectationValue _commandType = new ExpectationValue("MockCommand.CommandType"); --- 10,14 ---- public class MockCommand : MockObject, IDbCommand, ICloneable { ! private ExpectationStringQueue _commandText = new ExpectationStringQueue("MockCommand.CommandText"); private ExpectationValue _commandTimeout = new ExpectationValue("MockCommand.CommandTimeout"); private ExpectationValue _commandType = new ExpectationValue("MockCommand.CommandType"); |
From: Griffin C. <gc...@us...> - 2005-04-25 03:37:53
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework.Tests/Data In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10796/DotNetMock.Framework.Tests/Data Modified Files: MockCommandTests.cs Log Message: - Updated MockCommand object to use ExpectationStringQueue class for commant text values Index: MockCommandTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Framework.Tests/Data/MockCommandTests.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** MockCommandTests.cs 9 Oct 2004 21:14:12 -0000 1.17 --- MockCommandTests.cs 25 Apr 2005 03:37:45 -0000 1.18 *************** *** 21,25 **** --- 21,27 ---- _mockCmd = new MockCommand(); _mockCmd.SetExpectedCommandText(@"user id=sa;password=password;Connect Timeout=30"); + _mockCmd.SetExpectedCommandText(@"SQL COMMAND"); _mockCmd.CommandText = @"user id=sa;password=password;Connect Timeout=30"; + _mockCmd.CommandText = @"SQL COMMAND"; _mockCmd.Verify(); } |
From: Griffin C. <gc...@us...> - 2005-04-25 03:35:19
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9318/DotNetMock.Tests Modified Files: DotNetMock.Tests.csproj Added Files: ExpectationStringQueueTests.cs Log Message: - Added ExpectationStringQueue Class --- NEW FILE: ExpectationStringQueueTests.cs --- using NUnit.Framework; namespace DotNetMock.Tests { [TestFixture] public class ExpectationStringQueueTests { private ExpectationStringQueue _expectationStringQueue = null; [SetUp] public void SetUp( ) { _expectationStringQueue = new ExpectationStringQueue( "ExpectationQueueString" ); } [TearDown] public void TearDown( ) { _expectationStringQueue = null; } [Test] public void NoExpectations() { _expectationStringQueue.Verify(); } [Test] public void SetActual( ) { string test1 = "test string 1"; string test2 = "test string 2"; string actualString; Assert.IsNull( _expectationStringQueue.Actual ); _expectationStringQueue.Actual = test1; _expectationStringQueue.Actual = test2; actualString = _expectationStringQueue.Actual; Assert.IsNotNull( actualString ); Assert.AreEqual( test1, actualString ); actualString = _expectationStringQueue.Actual; Assert.IsNotNull( actualString ); Assert.AreEqual( test2, actualString ); Assert.IsNull( _expectationStringQueue.Actual ); } [Test] public void SetExpected( ) { string test3 = "test string 3"; string test4 = "test string 4"; string expectedString; Assert.IsNull( _expectationStringQueue.Expected ); _expectationStringQueue.Expected = test3; _expectationStringQueue.Expected = test4; expectedString = _expectationStringQueue.Expected; Assert.IsNotNull( expectedString ); Assert.AreEqual( test3, expectedString ); expectedString = _expectationStringQueue.Expected; Assert.IsNotNull( expectedString ); Assert.AreEqual( test4, expectedString ); Assert.IsNull( _expectationStringQueue.Expected ); } [Test] public void HasExpectations( ) { string test5 = "test string 5"; Assert.IsNull( _expectationStringQueue.Expected ); Assert.IsFalse( _expectationStringQueue.HasExpectations ); _expectationStringQueue.Expected = test5; Assert.IsTrue( _expectationStringQueue.HasExpectations ); string expectedString = _expectationStringQueue.Expected; Assert.IsNotNull( expectedString ); Assert.AreEqual( test5, expectedString ); Assert.IsFalse( _expectationStringQueue.HasExpectations ); } [Test] public void ClearExpected( ) { string test6 = "test string 6"; string test7 = "test string 7"; Assert.IsNull( _expectationStringQueue.Expected ); _expectationStringQueue.Expected = test6; _expectationStringQueue.Expected = test7; _expectationStringQueue.ClearExpected( ); Assert.IsNull( _expectationStringQueue.Expected ); } [Test] public void ClearActual( ) { string test8 = "test string 8"; string test9 = "test string 9"; Assert.IsNull( _expectationStringQueue.Actual ); _expectationStringQueue.Actual = test8; _expectationStringQueue.Actual = test9; _expectationStringQueue.ClearActual( ); Assert.IsNull( _expectationStringQueue.Actual ); } [Test] public void Verify( ) { string test10 = "test string 10"; string test11 = "test string 11"; string test12 = "test string 12"; bool exceptionFlag; #region Strings in queues are not equal _expectationStringQueue.Actual = test10; _expectationStringQueue.Actual = test11; _expectationStringQueue.Actual = test12; _expectationStringQueue.Expected = test10; _expectationStringQueue.Expected = test11; _expectationStringQueue.Expected = test11; exceptionFlag = false; try { _expectationStringQueue.Verify( ); } catch { exceptionFlag = true; } Assert.IsTrue( exceptionFlag, "Verify() MUST fail: strings in queues are not equal" ); #endregion #region Actual queue is longer than Expected one _expectationStringQueue.ClearActual( ); _expectationStringQueue.ClearExpected( ); _expectationStringQueue.Actual = test10; _expectationStringQueue.Actual = test11; _expectationStringQueue.Actual = test12; _expectationStringQueue.Actual = test12; _expectationStringQueue.Expected = test10; _expectationStringQueue.Expected = test11; _expectationStringQueue.Expected = test12; exceptionFlag = false; try { _expectationStringQueue.Verify( ); } catch { exceptionFlag = true; } Assert.IsTrue( exceptionFlag, "Verify() MUST fail: Actual queue is longer than Expected one" ); #endregion #region Expected queue is longer than Actual one _expectationStringQueue.ClearActual( ); _expectationStringQueue.ClearExpected( ); _expectationStringQueue.Actual = test10; _expectationStringQueue.Actual = test11; _expectationStringQueue.Actual = test12; _expectationStringQueue.Expected = test10; _expectationStringQueue.Expected = test11; _expectationStringQueue.Expected = test12; _expectationStringQueue.Expected = test12; exceptionFlag = false; try { _expectationStringQueue.Verify( ); } catch { exceptionFlag = true; } Assert.IsTrue( exceptionFlag, "Verify() MUST fail: Expected queue is longer than Actual one" ); #endregion #region Queues are equal _expectationStringQueue.ClearActual( ); _expectationStringQueue.ClearExpected( ); _expectationStringQueue.ClearActual( ); _expectationStringQueue.ClearExpected( ); _expectationStringQueue.Actual = test10; _expectationStringQueue.Actual = test11; _expectationStringQueue.Actual = test12; _expectationStringQueue.Expected = test10; _expectationStringQueue.Expected = test11; _expectationStringQueue.Expected = test12; _expectationStringQueue.Verify( ); #endregion } [Test] public void FailureMode( ) { string test13 = "test string 13"; _expectationStringQueue.Expected = test13; Assert.IsFalse( _expectationStringQueue.ShouldCheckImmediate ); _expectationStringQueue.VerifyImmediate = true; Assert.IsTrue( _expectationStringQueue.ShouldCheckImmediate ); } [Test] public void ImmediateValidation( ) { string test14 = "test string 14"; string test15 = "test string 15"; bool exceptionFlag; #region Fail case _expectationStringQueue.Expected = test14; _expectationStringQueue.Expected = test15; _expectationStringQueue.VerifyImmediate = true; exceptionFlag = false; try { _expectationStringQueue.Actual = test15; } catch { exceptionFlag = true; } Assert.IsTrue( exceptionFlag, "Immediate Verification MUST fail" ); #endregion #region Success case _expectationStringQueue.ClearActual( ); _expectationStringQueue.ClearExpected( ); _expectationStringQueue.Expected = test14; _expectationStringQueue.Expected = test15; _expectationStringQueue.VerifyImmediate = true; _expectationStringQueue.Actual = test14; _expectationStringQueue.Actual = test15; _expectationStringQueue.Actual = test15; #endregion } } } Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** DotNetMock.Tests.csproj 25 Apr 2005 00:14:47 -0000 1.21 --- DotNetMock.Tests.csproj 25 Apr 2005 03:35:10 -0000 1.22 *************** *** 126,129 **** --- 126,134 ---- /> <File + RelPath = "ExpectationStringQueueTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "ExpectationStringTests.cs" SubType = "Code" |
From: Griffin C. <gc...@us...> - 2005-04-25 03:35:19
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9318/DotNetMock Modified Files: DotNetMock.csproj Added Files: ExpectationStringQueue.cs Log Message: - Added ExpectationStringQueue Class Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** DotNetMock.csproj 25 Apr 2005 03:26:31 -0000 1.39 --- DotNetMock.csproj 25 Apr 2005 03:35:10 -0000 1.40 *************** *** 140,143 **** --- 140,148 ---- /> <File + RelPath = "ExpectationStringQueue.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "ExpectationType.cs" SubType = "Code" *************** *** 365,378 **** /> <File - RelPath = "Expectations\ExpectAndReturnExpectation.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File - RelPath = "Expectations\ExpectationsUtils.cs" - SubType = "Code" - BuildAction = "Compile" - /> - <File RelPath = "TestFramework\AbstractStubMaker.cs" SubType = "Code" --- 370,373 ---- --- NEW FILE: ExpectationStringQueue.cs --- using System.Collections; namespace DotNetMock { /// <summary> /// Expectation String Queue implementation. Extends <c>AbstractStaticExpectaion</c> /// </summary> /// <author>Evhen Khasenevich</author> public class ExpectationStringQueue : AbstractStaticExpectation { private Queue _actualStringQueue = new Queue( ); private Queue _expectedStringQueue = new Queue( ); /// <summary> /// Default Constructor for ExpectationQueueString. Set the name for this Expectation /// </summary> /// <param name="name">Name of this Expectation</param> public ExpectationStringQueue( string name ) : base( name ) { ClearActual( ); } /// <summary> /// Enqueue/Dequeue Actual strings. /// </summary> public string Actual { get { if ( this._actualStringQueue.Count == 0 ) { return null; } return ( string )this._actualStringQueue.Dequeue( ); } set { this._actualStringQueue.Enqueue( value ); if ( ShouldCheckImmediate ) { Verify( ); } } } /// <summary> /// Enqueue/Dequeue Expected strings. /// </summary> public string Expected { get { if ( this._expectedStringQueue.Count == 0 ) { return null; } if ( this._expectedStringQueue.Count == 1 ) { this.HasExpectations = false; } return ( string )this._expectedStringQueue.Dequeue( ); } set { this._expectedStringQueue.Enqueue( value ); this.HasExpectations = true; } } /// <summary> /// Clears Actual strings. /// </summary> public override void ClearActual( ) { this._actualStringQueue.Clear( ); } /// <summary> /// Clears Expected strings. /// </summary> public override void ClearExpected( ) { this._expectedStringQueue.Clear( ); HasExpectations = false; } /// <summary> /// Verifies object /// </summary> public override void Verify( ) { if ( this.HasExpectations ) { if ( this.ShouldCheckImmediate ) { Assertion.AssertEquals( "String values in the queues are not equal for object " + this.name, this.Expected, this.Actual ); } else { string expected; while ( ( expected = this.Expected ) != null ) { if ( this._actualStringQueue.Count > 0 ) { Assertion.AssertEquals( "String values in the queues are not equal for object " + this.name, expected, this.Actual ); } else { Assertion.Fail( string.Format( "{0} values left in the expected queue for object {1}: '{2}', ...", this._expectedStringQueue.Count + 1, this.name, expected ) ); } } if ( this._actualStringQueue.Count > 0 ) { Assertion.Fail( string.Format( "{0} values left in the actual queue for object {1}: '{2}', ...", this._actualStringQueue.Count, this.name, this.Actual ) ); } } } } } } |
From: Griffin C. <gc...@us...> - 2005-04-25 03:26:42
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5075/DotNetMock/Dynamic Modified Files: ExpectationMethod.cs MethodCall.cs Log Message: - Minor refactorings Index: MethodCall.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/MethodCall.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MethodCall.cs 8 Apr 2005 01:21:51 -0000 1.3 --- MethodCall.cs 25 Apr 2005 03:26:31 -0000 1.4 *************** *** 16,19 **** --- 16,23 ---- public class MethodCall { + #region Private Instance Fields + private MethodInfo _method; + private object[] _arguments; + #endregion /// <summary> /// Create new method call instance. *************** *** 156,163 **** public object[] Arguments { get { return _arguments; } } - #region Private Instance Fields - private MethodInfo _method; - private object[] _arguments; - #endregion } } --- 160,163 ---- Index: ExpectationMethod.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/ExpectationMethod.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ExpectationMethod.cs 8 Apr 2005 02:57:09 -0000 1.23 --- ExpectationMethod.cs 25 Apr 2005 03:26:31 -0000 1.24 *************** *** 1,10 **** #region License // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion #region Imports using System; using System.Reflection; - using DotNetMock.Dynamic.Predicates; #endregion --- 1,13 ---- #region License + // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. + #endregion + #region Imports + using System; using System.Reflection; #endregion *************** *** 14,19 **** /// Expected method call used for building dynamic mocks /// </summary> ! public class ExpectationMethod : ! IMethodCallExpectation { /// <summary> --- 17,21 ---- /// Expected method call used for building dynamic mocks /// </summary> ! public class ExpectationMethod : IMethodCallExpectation { /// <summary> *************** *** 42,46 **** /// <param name="methodName">Method name to expect</param> public ExpectationMethod( string methodName ) ! : this(methodName, null, null, null) { } --- 44,48 ---- /// <param name="methodName">Method name to expect</param> public ExpectationMethod( string methodName ) ! : this( methodName, null, null, null ) { } *************** *** 80,88 **** object[] argumentExpectations, Exception expectedException ! ) { _expectedMethodName = methodName; _argumentExpectations = argumentExpectations; - _expectedReturnValue = returnValue; _expectedException = expectedException; --- 82,89 ---- object[] argumentExpectations, Exception expectedException ! ) { _expectedMethodName = methodName; _argumentExpectations = argumentExpectations; _expectedReturnValue = returnValue; _expectedException = expectedException; *************** *** 93,97 **** public string ExpectedMethodName { ! get { return _expectedMethodName; } } /// <summary> --- 94,101 ---- public string ExpectedMethodName { ! get ! { ! return _expectedMethodName; ! } } /// <summary> *************** *** 100,104 **** public object ReturnValue { ! get { return _expectedReturnValue; } } /// <summary> --- 104,111 ---- public object ReturnValue { ! get ! { ! return _expectedReturnValue; ! } } /// <summary> *************** *** 106,119 **** /// <seealso cref="ActualMethodCall"/> /// </summary> ! public bool ActualMethodCallWasSet { ! get { return _actualMethodCall!=null; } } /// <summary> /// <see cref="MethodInfo"/> of actual method called. /// </summary> ! public MethodInfo ActualMethod { ! get { return ActualMethodCall.Method; --- 113,129 ---- /// <seealso cref="ActualMethodCall"/> /// </summary> ! public bool ActualMethodCallWasSet { ! get ! { ! return _actualMethodCall != null; ! } } /// <summary> /// <see cref="MethodInfo"/> of actual method called. /// </summary> ! public MethodInfo ActualMethod { ! get { return ActualMethodCall.Method; *************** *** 123,129 **** /// Name of actual method called. /// </summary> ! public string ActualMethodName { ! get { return ActualMethodCall.MethodName; } } /// <summary> --- 133,142 ---- /// Name of actual method called. /// </summary> ! public string ActualMethodName { ! get ! { ! return ActualMethodCall.MethodName; ! } } /// <summary> *************** *** 132,149 **** public MethodCall ActualMethodCall { ! get { ! if ( ! ActualMethodCallWasSet ) { throw new InvalidOperationException( ! "Cannot get property ActualMethodCall "+ ! "before setting it." ); } return _actualMethodCall; } ! set { ! if ( value==null ) { throw new ArgumentNullException( --- 145,162 ---- public MethodCall ActualMethodCall { ! get { ! if ( ! ActualMethodCallWasSet ) { throw new InvalidOperationException( ! "Cannot get property ActualMethodCall " + ! "before setting it." ); } return _actualMethodCall; } ! set { ! if ( value == null ) { throw new ArgumentNullException( *************** *** 151,159 **** ); } ! if ( ActualMethodCallWasSet ) { throw new InvalidOperationException( ! "Cannot set property ActualMethodCall "+ ! "more than once." ); } --- 164,172 ---- ); } ! if ( ActualMethodCallWasSet ) { throw new InvalidOperationException( ! "Cannot set property ActualMethodCall " + ! "more than once." ); } *************** *** 162,187 **** } //TODO: Refactor methods ! private string argsToString( object[] args ) { ! if ( args != null && args.Length > 0 ) { string[] argText = new string[args.Length]; ! for (int i=0; i<args.Length; ++i) { ! object arg = args[i]; ! if ( object.ReferenceEquals(arg, null) ) { ! argText[i] = "null"; } ! else if( arg is string ) { ! argText[i] = "\"" + arg.ToString() + "\""; } ! else { ! argText[i] = arg.ToString(); } } ! return String.Join(", ", argText); } return String.Empty; --- 175,200 ---- } //TODO: Refactor methods ! private string argsToString( object[] args ) { ! if ( args != null && args.Length > 0 ) { string[] argText = new string[args.Length]; ! for ( int i = 0; i < args.Length; ++i ) { ! object arg = args[ i ]; ! if ( object.ReferenceEquals( arg, null ) ) { ! argText[ i ] = "null"; } ! else if ( arg is string ) { ! argText[ i ] = "\"" + arg.ToString( ) + "\""; } ! else { ! argText[ i ] = arg.ToString( ); } } ! return String.Join( ", ", argText ); } return String.Empty; *************** *** 190,212 **** /// Verifies this expectation /// </summary> ! public void Verify() { ! if ( ! ActualMethodCallWasSet ) { ! Assertion.Fail(String.Format( "{0}({1}) expected but never called.", ExpectedMethodName, ! argsToString(_argumentExpectations) ! )); } ! if( ExpectedMethodName != ActualMethodName ) { ! Assertion.Fail(String.Format( "{0}({1}) expected, but {2} called.", ! ExpectedMethodName, argsToString(_argumentExpectations), ActualMethodCall ! )); } ! if ( _argumentExpectations==null ) { return; --- 203,225 ---- /// Verifies this expectation /// </summary> ! public void Verify( ) { ! if ( ! ActualMethodCallWasSet ) { ! Assertion.Fail( String.Format( "{0}({1}) expected but never called.", ExpectedMethodName, ! argsToString( _argumentExpectations ) ! ) ); } ! if ( ExpectedMethodName != ActualMethodName ) { ! Assertion.Fail( String.Format( "{0}({1}) expected, but {2} called.", ! ExpectedMethodName, argsToString( _argumentExpectations ), ActualMethodCall ! ) ); } ! if ( _argumentExpectations == null ) { return; *************** *** 214,275 **** object[] actualArguments = ActualMethodCall.Arguments; // actual arguments must be equal to expectations ! if ( actualArguments.Length!=_argumentExpectations.Length) { ! Assertion.Fail(String.Format( ! "Expected {0} arguments but received {1} "+ ! "in method call {2}.", _argumentExpectations.Length, actualArguments.Length, ActualMethodCall ! )); } - // assert that each passed in arg is validated by the appropriate predicate. ! for (int i = 0; i < _argumentExpectations.Length; i++) { ! object argumentExpectation = _argumentExpectations[i]; ! object actualArgument = actualArguments[i]; ! // evaluate whether input expectations have been met IPredicate predicate = ! PredicateUtils.ConvertFrom(argumentExpectation); bool isPredicateSatisfied = ! predicate.Eval(actualArgument); ! if ( ! isPredicateSatisfied ) { ! Assertion.Fail(String.Format( ! "Failed to satisfy '{0}' on argument[{1}] "+ ! "of method call {2}", predicate, i, ActualMethodCall ! )); } // return output expectations if specified IArgumentMutator mutator = argumentExpectation as IArgumentMutator; ! if ( mutator!=null ) { ! mutator.Mutate(ref actualArguments[i]); } } - // if exception setup to be thrown, throw it ! if (_expectedException != null) { throw _expectedException; } } - /// <summary> /// Check actual incoming method call and return expected outgoing response. /// <see cref="IMethodCallExpectation.CheckCallAndSendResponse"/> /// </summary> ! public object CheckCallAndSendResponse(MethodCall call) { _actualMethodCall = call; ! this.Verify(); return _expectedReturnValue; } } ! } --- 227,284 ---- object[] actualArguments = ActualMethodCall.Arguments; // actual arguments must be equal to expectations ! if ( actualArguments.Length != _argumentExpectations.Length ) { ! Assertion.Fail( String.Format( ! "Expected {0} arguments but received {1} " + ! "in method call {2}.", _argumentExpectations.Length, actualArguments.Length, ActualMethodCall ! ) ); } // assert that each passed in arg is validated by the appropriate predicate. ! for ( int i = 0; i < _argumentExpectations.Length; i++ ) { ! object argumentExpectation = _argumentExpectations[ i ]; ! object actualArgument = actualArguments[ i ]; // evaluate whether input expectations have been met IPredicate predicate = ! PredicateUtils.ConvertFrom( argumentExpectation ); bool isPredicateSatisfied = ! predicate.Eval( actualArgument ); ! if ( ! isPredicateSatisfied ) { ! Assertion.Fail( String.Format( ! "Failed to satisfy '{0}' on argument[{1}] " + ! "of method call {2}", predicate, i, ActualMethodCall ! ) ); } // return output expectations if specified IArgumentMutator mutator = argumentExpectation as IArgumentMutator; ! if ( mutator != null ) { ! mutator.Mutate( ref actualArguments[ i ] ); } } // if exception setup to be thrown, throw it ! if ( _expectedException != null ) { throw _expectedException; } } /// <summary> /// Check actual incoming method call and return expected outgoing response. /// <see cref="IMethodCallExpectation.CheckCallAndSendResponse"/> /// </summary> ! public object CheckCallAndSendResponse( MethodCall call ) { _actualMethodCall = call; ! this.Verify( ); return _expectedReturnValue; } } ! } \ No newline at end of file |
From: Griffin C. <gc...@us...> - 2005-04-25 03:26:41
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5075/DotNetMock Modified Files: DotNetMock.csproj Log Message: - Minor refactorings Index: DotNetMock.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/DotNetMock.csproj,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** DotNetMock.csproj 23 Apr 2005 21:28:39 -0000 1.38 --- DotNetMock.csproj 25 Apr 2005 03:26:31 -0000 1.39 *************** *** 365,368 **** --- 365,378 ---- /> <File + RelPath = "Expectations\ExpectAndReturnExpectation.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "Expectations\ExpectationsUtils.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "TestFramework\AbstractStubMaker.cs" SubType = "Code" |
From: Griffin C. <gc...@us...> - 2005-04-25 00:15:12
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17305/DotNetMock.Tests Modified Files: DotNetMock.Tests.csproj Log Message: - Rounding out some code coverage Index: DotNetMock.Tests.csproj =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/DotNetMock.Tests.csproj,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** DotNetMock.Tests.csproj 23 Apr 2005 21:28:38 -0000 1.20 --- DotNetMock.Tests.csproj 25 Apr 2005 00:14:47 -0000 1.21 *************** *** 216,219 **** --- 216,224 ---- /> <File + RelPath = "Dynamic\Generate\MockClassBuilderTests.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "Util\StringUtilsTests.cs" SubType = "Code" |
From: Griffin C. <gc...@us...> - 2005-04-25 00:15:12
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17305/DotNetMock.Tests/Dynamic Modified Files: PredicateTests.cs Log Message: - Rounding out some code coverage Index: PredicateTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/PredicateTests.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** PredicateTests.cs 20 Feb 2005 09:26:48 -0000 1.14 --- PredicateTests.cs 25 Apr 2005 00:14:47 -0000 1.15 *************** *** 4,168 **** using DotNetMock.Dynamic.Predicates; using NUnit.Framework; - namespace DotNetMock.Tests.Dynamic { [TestFixture] public class PredicatesTest ! { private IPredicate p; ! ! [Test] public void AndToString() { Assert.AreEqual( "(value is anything) and (value is anything)", new AndPredicate( ! new IsAnything(), new IsAnything() ! ).ToString() ); } ! [Test] public void IsAnythingToString() { ! Assert.AreEqual("value is anything", new IsAnything().ToString()); } ! [Test] public void IsCloseToToString() { Assert.AreEqual( "value is within 0.1 of 1", ! new IsCloseTo(1, 0.1).ToString() ); } ! [Test] public void IsEqualToString() { Assert.AreEqual( "value equals 3", ! new IsEqual(3).ToString() ); Assert.AreEqual( "value equals 'whatever it is'", ! new IsEqual("whatever it is").ToString() ); } ! [Test] public void IsEqualIgnoreCaseToString() { Assert.AreEqual( "value equals 'abc' (ignore case)", ! new IsEqualIgnoreCase("abc").ToString() ); Assert.AreEqual( "value equals 'whatever' (ignore case)", ! new IsEqualIgnoreCase("whatever").ToString() ); } ! [Test] public void IsEqualIgnoreWhiteSpaceToString() { Assert.AreEqual( "value equals 'a b c' (ignore whitespace)", ! new IsEqualIgnoreWhiteSpace("a b c").ToString() ); Assert.AreEqual( "value equals 'what ever' (ignore whitespace)", ! new IsEqualIgnoreWhiteSpace("what ever").ToString() ); } ! [Test] public void IsInToString() { Assert.AreEqual( "value is in [1, 'two', 3.4]", ! new IsIn(1, "two", 3.4).ToString() ); } ! [Test] public void IsMatchToString() { Assert.AreEqual( "value matches /^abc$/", ! new IsMatch("^abc$").ToString() ); } ! [Test] public void IsNullToString() { ! Assert.AreEqual("value is null", new IsNull().ToString()); } ! [Test] public void IsTypeOfToString() { Assert.AreEqual( "value is a System.Object", ! new IsTypeOf(typeof(object)).ToString() ); } ! [Test] public void NotEqualToString() { Assert.AreEqual( "value is not equal to 3", ! new NotEqual(3).ToString() ); Assert.AreEqual( "value is not equal to 'whatever it is'", ! new NotEqual("whatever it is").ToString() ); } ! [Test] public void NotInToString() { Assert.AreEqual( "value is not in [1, 'two', 3.4]", ! new NotIn(1, "two", 3.4).ToString() ); } ! [Test] public void NotNullToString() { ! Assert.AreEqual("value is not null", new NotNull().ToString()); } ! [Test] public void NotToString() { Assert.AreEqual( "not (value is anything)", ! new NotPredicate(new IsAnything()).ToString() ); } ! [Test] public void OrToString() { Assert.AreEqual( "(value is anything) or (value is anything)", new OrPredicate( ! new IsAnything(), new IsAnything() ! ).ToString() ); } [Test] ! public void IsNull() { ! p = new IsNull(); ! Assert.IsTrue(p.Eval(null)); ! Assert.IsTrue(!p.Eval(new object())); ! Assert.IsTrue(!p.Eval(1)); ! Assert.IsTrue(!p.Eval(true)); ! Assert.IsTrue(!p.Eval(false)); } - [Test] ! public void NotNull() { ! p = new NotNull(); ! Assert.IsTrue(!p.Eval(null)); ! Assert.IsTrue(p.Eval(new object())); } - [Test] ! public void IsEqual() { ! object o1 = new object(); ! object o2 = new object(); ! p = new IsEqual(o1); ! Assert.IsTrue(p.Eval(o1)); ! Assert.IsTrue(!p.Eval(o2)); ! Assert.IsTrue(!p.Eval(null)); ! int i1 = 1; int i2 = 2; ! p = new IsEqual(i1); ! Assert.IsTrue(p.Eval(i1)); ! Assert.IsTrue(p.Eval(1)); ! Assert.IsTrue(!p.Eval(i2)); ! Assert.IsTrue(!p.Eval(2)); ! p = new IsEqual( null ); Assert.IsTrue( !p.Eval( "something" ) ); --- 4,177 ---- using DotNetMock.Dynamic.Predicates; using NUnit.Framework; namespace DotNetMock.Tests.Dynamic { [TestFixture] public class PredicatesTest ! { private IPredicate p; ! [Test] ! public void AndToString( ) { Assert.AreEqual( "(value is anything) and (value is anything)", new AndPredicate( ! new IsAnything( ), new IsAnything( ) ! ).ToString( ) ); } ! [Test] ! public void IsAnythingToString( ) { ! Assert.AreEqual( "value is anything", new IsAnything( ).ToString( ) ); } ! [Test] ! public void IsCloseToToString( ) { Assert.AreEqual( "value is within 0.1 of 1", ! new IsCloseTo( 1, 0.1 ).ToString( ) ); } ! [Test] ! public void IsEqualToString( ) { Assert.AreEqual( "value equals 3", ! new IsEqual( 3 ).ToString( ) ); Assert.AreEqual( "value equals 'whatever it is'", ! new IsEqual( "whatever it is" ).ToString( ) ); } ! [Test] ! public void IsEqualIgnoreCaseToString( ) { Assert.AreEqual( "value equals 'abc' (ignore case)", ! new IsEqualIgnoreCase( "abc" ).ToString( ) ); Assert.AreEqual( "value equals 'whatever' (ignore case)", ! new IsEqualIgnoreCase( "whatever" ).ToString( ) ); } ! [Test] ! public void IsEqualIgnoreWhiteSpaceToString( ) { Assert.AreEqual( "value equals 'a b c' (ignore whitespace)", ! new IsEqualIgnoreWhiteSpace( "a b c" ).ToString( ) ); Assert.AreEqual( "value equals 'what ever' (ignore whitespace)", ! new IsEqualIgnoreWhiteSpace( "what ever" ).ToString( ) ); } ! [Test] ! public void IsInToString( ) { Assert.AreEqual( "value is in [1, 'two', 3.4]", ! new IsIn( 1, "two", 3.4 ).ToString( ) ); } ! [Test] ! public void IsMatchToString( ) { Assert.AreEqual( "value matches /^abc$/", ! new IsMatch( "^abc$" ).ToString( ) ); } ! [Test] ! public void IsNullToString( ) { ! Assert.AreEqual( "value is null", new IsNull( ).ToString( ) ); } ! [Test] ! public void IsTypeOfToString( ) { Assert.AreEqual( "value is a System.Object", ! new IsTypeOf( typeof ( object ) ).ToString( ) ); } ! [Test] ! public void NotEqualToString( ) { Assert.AreEqual( "value is not equal to 3", ! new NotEqual( 3 ).ToString( ) ); Assert.AreEqual( "value is not equal to 'whatever it is'", ! new NotEqual( "whatever it is" ).ToString( ) ); } ! [Test] ! public void NotInToString( ) { Assert.AreEqual( "value is not in [1, 'two', 3.4]", ! new NotIn( 1, "two", 3.4 ).ToString( ) ); } ! [Test] ! public void NotNullToString( ) { ! Assert.AreEqual( "value is not null", new NotNull( ).ToString( ) ); } ! [Test] ! public void NotToString( ) { Assert.AreEqual( "not (value is anything)", ! new NotPredicate( new IsAnything( ) ).ToString( ) ); } ! [Test] ! public void OrToString( ) { Assert.AreEqual( "(value is anything) or (value is anything)", new OrPredicate( ! new IsAnything( ), new IsAnything( ) ! ).ToString( ) ); } [Test] ! public void IsNull( ) { ! p = new IsNull( ); ! Assert.IsTrue( p.Eval( null ) ); ! Assert.IsTrue( !p.Eval( new object( ) ) ); ! Assert.IsTrue( !p.Eval( 1 ) ); ! Assert.IsTrue( !p.Eval( true ) ); ! Assert.IsTrue( !p.Eval( false ) ); } [Test] ! public void NotNull( ) { ! p = new NotNull( ); ! Assert.IsTrue( !p.Eval( null ) ); ! Assert.IsTrue( p.Eval( new object( ) ) ); } [Test] ! public void IsEqual( ) { ! object o1 = new object( ); ! object o2 = new object( ); ! p = new IsEqual( o1 ); ! Assert.IsTrue( p.Eval( o1 ) ); ! Assert.IsTrue( !p.Eval( o2 ) ); ! Assert.IsTrue( !p.Eval( null ) ); int i1 = 1; int i2 = 2; ! p = new IsEqual( i1 ); ! Assert.IsTrue( p.Eval( i1 ) ); ! Assert.IsTrue( p.Eval( 1 ) ); ! Assert.IsTrue( !p.Eval( i2 ) ); ! Assert.IsTrue( !p.Eval( 2 ) ); p = new IsEqual( null ); Assert.IsTrue( !p.Eval( "something" ) ); *************** *** 170,361 **** } [Test] ! public void IsEqualArray() { ! object[] array1 = new object[] { 1 }; ! object[] array2 = new object[] { 1 }; ! p = new IsEqual( array1 ); Assert.IsTrue( !p.Eval( "hello" ) ); Assert.IsTrue( !p.Eval( null ) ); ! Assert.IsTrue( !p.Eval( new object[] { 2, 3 } ) ); Assert.IsTrue( !p.Eval( new object[] {} ) ); ! Assert.IsTrue( !p.Eval( new object[] { 2 } ) ); Assert.IsTrue( p.Eval( array1 ) ); ! Assert.IsTrue( p.Eval( new object[] { 1 } ) ); ! } [Test] ! public void NotEqual() { ! object o1 = new object(); ! object o2 = new object(); ! p = new NotEqual(o1); ! Assert.IsTrue(!p.Eval(o1)); ! Assert.IsTrue(p.Eval(o2)); ! Assert.IsTrue(p.Eval(null)); ! int i1 = 1; int i2 = 2; ! p = new NotEqual(i1); ! Assert.IsTrue(!p.Eval(i1)); ! Assert.IsTrue(!p.Eval(1)); ! Assert.IsTrue(p.Eval(i2)); ! Assert.IsTrue(p.Eval(2)); } - [Test] ! public void IsAnything() { ! p = new IsAnything(); ! Assert.IsTrue(p.Eval(null)); ! Assert.IsTrue(p.Eval(0)); ! Assert.IsTrue(p.Eval(99)); ! Assert.IsTrue(p.Eval(-2)); ! Assert.IsTrue(p.Eval(true)); ! Assert.IsTrue(p.Eval(false)); ! Assert.IsTrue(p.Eval("")); ! Assert.IsTrue(p.Eval("hello")); ! Assert.IsTrue(p.Eval(new object())); } - [Test] ! public void IsType() { ! p = new IsTypeOf(typeof(TextReader)); ! Assert.IsTrue(!p.Eval(null)); ! Assert.IsTrue(p.Eval(new StringReader(""))); ! Assert.IsTrue(!p.Eval(new StringWriter())); } - [Test] ! public void Not() { ! Assert.IsTrue(new NotPredicate(new False()).Eval(null)); ! Assert.IsTrue(!new NotPredicate(new True()).Eval(null)); } - [Test] ! public void And() { ! Assert.IsTrue( new AndPredicate(new True() , new True() ).Eval(null)); ! Assert.IsTrue(!new AndPredicate(new True() , new False()).Eval(null)); ! Assert.IsTrue(!new AndPredicate(new False(), new True() ).Eval(null)); ! Assert.IsTrue(!new AndPredicate(new False(), new False()).Eval(null)); } - [Test] ! public void Or() { ! Assert.IsTrue( new OrPredicate(new True() , new True() ).Eval(null)); ! Assert.IsTrue( new OrPredicate(new True() , new False()).Eval(null)); ! Assert.IsTrue( new OrPredicate(new False(), new True() ).Eval(null)); ! Assert.IsTrue(!new OrPredicate(new False(), new False()).Eval(null)); } - [Test] ! public void IsIn() { ! p = new IsIn(2, 3, 5); ! Assert.IsTrue(!p.Eval(1)); ! Assert.IsTrue(p.Eval(2)); ! Assert.IsTrue(p.Eval(3)); ! Assert.IsTrue(!p.Eval(4)); ! Assert.IsTrue(p.Eval(5)); ! Assert.IsTrue(!p.Eval(6)); ! Assert.IsTrue(!p.Eval(null)); ! int[] array = {1, 2}; ! p = new IsIn(array); ! Assert.IsTrue(p.Eval(1)); ! Assert.IsTrue(p.Eval(2)); ! Assert.IsTrue(!p.Eval(3)); } - [Test] ! public void NotIn() { ! p = new NotIn(1, 2); ! Assert.IsTrue(!p.Eval(1)); ! Assert.IsTrue(!p.Eval(2)); ! Assert.IsTrue(p.Eval(3)); ! int[] array = {1, 2}; ! p = new NotIn(array); ! Assert.IsTrue(!p.Eval(1)); ! Assert.IsTrue(!p.Eval(2)); ! Assert.IsTrue(p.Eval(3)); } - [Test] ! public void IsEqualIgnoreCase() { ! p = new IsEqualIgnoreCase("heLLo"); ! Assert.IsTrue(p.Eval("HELLO")); ! Assert.IsTrue(p.Eval("hello")); ! Assert.IsTrue(p.Eval("HelLo")); ! Assert.IsTrue(!p.Eval("abcde")); } - [Test] ! public void StripSpace() { ! Assert.AreEqual("Hello World", IsEqualIgnoreWhiteSpace.StripSpace("Hello\n \n World")); ! Assert.AreEqual("Hello World", IsEqualIgnoreWhiteSpace.StripSpace(" Hello World ")); ! Assert.AreEqual("", IsEqualIgnoreWhiteSpace.StripSpace(" ")); } - [Test] ! public void TestIsEqualIgnoreWhiteSpace() { ! p = new IsEqualIgnoreWhiteSpace("Hello World how\n are we?"); ! Assert.IsTrue(p.Eval("Hello World how are we?")); ! Assert.IsTrue(p.Eval(" Hello World how are \n\n\twe?")); ! Assert.IsTrue(!p.Eval("HelloWorld how are we?")); ! Assert.IsTrue(!p.Eval("Hello World how are we")); } - [Test] ! public void IsMatch() { ! p = new IsMatch(new Regex(@"^th[aeiou]\w* .*$")); ! Assert.IsTrue(p.Eval("the world")); ! Assert.IsTrue(!p.Eval("theworld")); ! Assert.IsTrue(!p.Eval("ThE world")); ! Assert.IsTrue(!p.Eval(" the world")); ! Assert.IsTrue(p.Eval("thats nice")); ! Assert.IsTrue(!p.Eval(new object())); ! Assert.IsTrue(!p.Eval(null)); ! ! p = new IsMatch(@"^th[aeiou]\w* .*$"); ! Assert.IsTrue(p.Eval("the world")); ! Assert.IsTrue(!p.Eval("theworld")); ! Assert.IsTrue(!p.Eval("ThE world")); ! ! p = new IsMatch(@"^th[aeiou]\w* .*$", false); ! Assert.IsTrue(p.Eval("the world")); ! Assert.IsTrue(!p.Eval("theworld")); ! Assert.IsTrue(!p.Eval("ThE world")); ! ! p = new IsMatch(@"^th[aeiou]\w* .*$", true); ! Assert.IsTrue(p.Eval("the world")); ! Assert.IsTrue(!p.Eval("theworld")); ! Assert.IsTrue(p.Eval("ThE world")); ! } - [Test] ! public void Delegate() { ! p = new Predicate(new Predicate.EvaluationMethod(myEval)); myFlag = false; ! Assert.IsTrue(p.Eval(null)); ! Assert.IsTrue(!p.Eval(null)); ! Assert.IsTrue(p.Eval(null)); ! Assert.IsTrue(!p.Eval(null)); } - [Test] ! public void IsCloseTo() { ! p = new IsCloseTo(3.0, 0.5); Assert.IsTrue( p.Eval( 3.0 ) ); Assert.IsTrue( p.Eval( 3.5 ) ); --- 179,349 ---- } [Test] ! public void IsEqualArray( ) { ! object[] array1 = new object[] {1}; ! p = new IsEqual( array1 ); Assert.IsTrue( !p.Eval( "hello" ) ); Assert.IsTrue( !p.Eval( null ) ); ! Assert.IsTrue( !p.Eval( new object[] {2, 3} ) ); Assert.IsTrue( !p.Eval( new object[] {} ) ); ! Assert.IsTrue( !p.Eval( new object[] {2} ) ); Assert.IsTrue( p.Eval( array1 ) ); ! Assert.IsTrue( p.Eval( new object[] {1} ) ); } [Test] ! public void NotEqual( ) { ! object o1 = new object( ); ! object o2 = new object( ); ! p = new NotEqual( o1 ); ! Assert.IsTrue( !p.Eval( o1 ) ); ! Assert.IsTrue( p.Eval( o2 ) ); ! Assert.IsTrue( p.Eval( null ) ); int i1 = 1; int i2 = 2; ! p = new NotEqual( i1 ); ! Assert.IsTrue( !p.Eval( i1 ) ); ! Assert.IsTrue( !p.Eval( 1 ) ); ! Assert.IsTrue( p.Eval( i2 ) ); ! Assert.IsTrue( p.Eval( 2 ) ); } [Test] ! public void IsAnything( ) { ! p = new IsAnything( ); ! Assert.IsTrue( p.Eval( null ) ); ! Assert.IsTrue( p.Eval( 0 ) ); ! Assert.IsTrue( p.Eval( 99 ) ); ! Assert.IsTrue( p.Eval( -2 ) ); ! Assert.IsTrue( p.Eval( true ) ); ! Assert.IsTrue( p.Eval( false ) ); ! Assert.IsTrue( p.Eval( "" ) ); ! Assert.IsTrue( p.Eval( "hello" ) ); ! Assert.IsTrue( p.Eval( new object( ) ) ); } [Test] ! public void IsType( ) { ! p = new IsTypeOf( typeof ( TextReader ) ); ! Assert.IsTrue( !p.Eval( null ) ); ! Assert.IsTrue( p.Eval( new StringReader( "" ) ) ); ! Assert.IsTrue( !p.Eval( new StringWriter( ) ) ); } [Test] ! public void Not( ) { ! Assert.IsTrue( new NotPredicate( new False( ) ).Eval( null ) ); ! Assert.IsTrue( !new NotPredicate( new True( ) ).Eval( null ) ); } [Test] ! public void And( ) { ! Assert.IsTrue( new AndPredicate( new True( ), new True( ) ).Eval( null ) ); ! Assert.AreEqual( "(N/A)", new True( ).ToString( ) ); ! Assert.IsTrue( !new AndPredicate( new True( ), new False( ) ).Eval( null ) ); ! Assert.IsTrue( !new AndPredicate( new False( ), new True( ) ).Eval( null ) ); ! Assert.IsTrue( !new AndPredicate( new False( ), new False( ) ).Eval( null ) ); } [Test] ! public void Or( ) { ! Assert.IsTrue( new OrPredicate( new True( ), new True( ) ).Eval( null ) ); ! Assert.IsTrue( new OrPredicate( new True( ), new False( ) ).Eval( null ) ); ! Assert.IsTrue( new OrPredicate( new False( ), new True( ) ).Eval( null ) ); ! Assert.IsTrue( !new OrPredicate( new False( ), new False( ) ).Eval( null ) ); } [Test] ! public void IsIn( ) { ! p = new IsIn( 2, 3, 5 ); ! Assert.IsTrue( !p.Eval( 1 ) ); ! Assert.IsTrue( p.Eval( 2 ) ); ! Assert.IsTrue( p.Eval( 3 ) ); ! Assert.IsTrue( !p.Eval( 4 ) ); ! Assert.IsTrue( p.Eval( 5 ) ); ! Assert.IsTrue( !p.Eval( 6 ) ); ! Assert.IsTrue( !p.Eval( null ) ); int[] array = {1, 2}; ! p = new IsIn( array ); ! Assert.IsTrue( p.Eval( 1 ) ); ! Assert.IsTrue( p.Eval( 2 ) ); ! Assert.IsTrue( !p.Eval( 3 ) ); } [Test] ! public void NotIn( ) { ! p = new NotIn( 1, 2 ); ! Assert.IsTrue( !p.Eval( 1 ) ); ! Assert.IsTrue( !p.Eval( 2 ) ); ! Assert.IsTrue( p.Eval( 3 ) ); int[] array = {1, 2}; ! p = new NotIn( array ); ! Assert.IsTrue( !p.Eval( 1 ) ); ! Assert.IsTrue( !p.Eval( 2 ) ); ! Assert.IsTrue( p.Eval( 3 ) ); } [Test] ! public void IsEqualIgnoreCase( ) { ! p = new IsEqualIgnoreCase( "heLLo" ); ! Assert.IsTrue( p.Eval( "HELLO" ) ); ! Assert.IsTrue( p.Eval( "hello" ) ); ! Assert.IsTrue( p.Eval( "HelLo" ) ); ! Assert.IsTrue( !p.Eval( "abcde" ) ); } [Test] ! public void StripSpace( ) { ! Assert.AreEqual( "Hello World", IsEqualIgnoreWhiteSpace.StripSpace( "Hello\n \n World" ) ); ! Assert.AreEqual( "Hello World", IsEqualIgnoreWhiteSpace.StripSpace( " Hello World " ) ); ! Assert.AreEqual( "", IsEqualIgnoreWhiteSpace.StripSpace( " " ) ); } [Test] ! public void TestIsEqualIgnoreWhiteSpace( ) { ! p = new IsEqualIgnoreWhiteSpace( "Hello World how\n are we?" ); ! Assert.IsTrue( p.Eval( "Hello World how are we?" ) ); ! Assert.IsTrue( p.Eval( " Hello World how are \n\n\twe?" ) ); ! Assert.IsTrue( !p.Eval( "HelloWorld how are we?" ) ); ! Assert.IsTrue( !p.Eval( "Hello World how are we" ) ); } [Test] ! public void IsMatch( ) { ! p = new IsMatch( new Regex( @"^th[aeiou]\w* .*$" ) ); ! Assert.IsTrue( p.Eval( "the world" ) ); ! Assert.IsTrue( !p.Eval( "theworld" ) ); ! Assert.IsTrue( !p.Eval( "ThE world" ) ); ! Assert.IsTrue( !p.Eval( " the world" ) ); ! Assert.IsTrue( p.Eval( "thats nice" ) ); ! Assert.IsTrue( !p.Eval( new object( ) ) ); ! Assert.IsTrue( !p.Eval( null ) ); ! p = new IsMatch( @"^th[aeiou]\w* .*$" ); ! Assert.IsTrue( p.Eval( "the world" ) ); ! Assert.IsTrue( !p.Eval( "theworld" ) ); ! Assert.IsTrue( !p.Eval( "ThE world" ) ); ! p = new IsMatch( @"^th[aeiou]\w* .*$", false ); ! Assert.IsTrue( p.Eval( "the world" ) ); ! Assert.IsTrue( !p.Eval( "theworld" ) ); ! Assert.IsTrue( !p.Eval( "ThE world" ) ); ! p = new IsMatch( @"^th[aeiou]\w* .*$", true ); ! Assert.IsTrue( p.Eval( "the world" ) ); ! Assert.IsTrue( !p.Eval( "theworld" ) ); ! Assert.IsTrue( p.Eval( "ThE world" ) ); } [Test] ! public void Delegate( ) { ! p = new Predicate( new Predicate.EvaluationMethod( myEval ) ); myFlag = false; ! Assert.IsTrue( p.Eval( null ) ); ! Assert.IsTrue( !p.Eval( null ) ); ! Assert.IsTrue( p.Eval( null ) ); ! Assert.IsTrue( !p.Eval( null ) ); } [Test] ! public void IsCloseTo( ) { ! p = new IsCloseTo( 3.0, 0.5 ); Assert.IsTrue( p.Eval( 3.0 ) ); Assert.IsTrue( p.Eval( 3.5 ) ); *************** *** 368,389 **** } private bool myFlag; ! ! private bool myEval(object val) { myFlag = !myFlag; return myFlag; } ! ! class True : AbstractPredicate { ! public override bool Eval(object val) { return true; } } ! ! class False : AbstractPredicate { ! public override bool Eval(object val) { return false; --- 356,374 ---- } private bool myFlag; ! private bool myEval( object val ) { myFlag = !myFlag; return myFlag; } ! private class True : AbstractPredicate { ! public override bool Eval( object val ) { return true; } } ! private class False : AbstractPredicate { ! public override bool Eval( object val ) { return false; *************** *** 391,393 **** } } ! } --- 376,378 ---- } } ! } \ No newline at end of file |
From: Griffin C. <gc...@us...> - 2005-04-25 00:15:02
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17305/DotNetMock.Tests/Dynamic/Generate Added Files: MockClassBuilderTests.cs Log Message: - Rounding out some code coverage --- NEW FILE: MockClassBuilderTests.cs --- using System; using System.Reflection; using System.Reflection.Emit; using DotNetMock.Dynamic.Generate; using NUnit.Framework; namespace DotNetMock.Tests.Dynamic.Generate { [TestFixture] public class MockClassBuilderTests { [Test] [ExpectedException(typeof(InvalidOperationException))] public void ThrowsExceptionWhenNotCompiled() { MockClassBuilder classBuilder = createMockClassBuilder( ); object mockClass = classBuilder.MockClass; } [Test] [ExpectedException(typeof(InvalidOperationException))] public void ThrowsExceptionForHandlerFieldWhenNotCompiled() { MockClassBuilder classBuilder = createMockClassBuilder( ); object mockClass = classBuilder.HandlerField; } [Test] [ExpectedException(typeof(InvalidOperationException))] public void ThrowsExceptionWhenCompiledTwice() { MockClassBuilder classBuilder = createMockClassBuilder( ); classBuilder.Compile(); classBuilder.Compile(); } [Test] [ExpectedException(typeof(InvalidOperationException))] public void ThrowsExceptionWhenImplementMethodAfterCompiled() { MockClassBuilder classBuilder = createMockClassBuilder( ); classBuilder.Compile(); classBuilder.ImplementMockedMethod( "FooMethod", typeof(object), new Type[] { typeof(object) } ); } private static MockClassBuilder createMockClassBuilder( ) { AssemblyBuilder _assemblyBuilder; ModuleBuilder _moduleBuilder; _assemblyBuilder = newAssemblyBuilder( AssemblyBuilderAccess.Run ); _moduleBuilder = _assemblyBuilder.DefineDynamicModule( "MockModule" ); return new MockClassBuilder( _moduleBuilder, "MockObject", typeof ( object ), Type.EmptyTypes ); } 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-04-23 21:57:09
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5606/DotNetMock/Dynamic/Generate Modified Files: ClassGenerator.cs Log Message: - Minor Refactorings Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/ClassGenerator.cs,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** ClassGenerator.cs 23 Apr 2005 21:53:33 -0000 1.11 --- ClassGenerator.cs 23 Apr 2005 21:57:00 -0000 1.12 *************** *** 73,88 **** 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; } /// <summary> --- 73,77 ---- classBuilder.ImplementMockedMethod( mi ); } ! return compileAndGenerateMock( classBuilder, handler ); } /// <summary> *************** *** 105,108 **** --- 94,101 ---- classBuilder.ImplementMockedMethod( ms.MethodName, ms.ReturnType, ms.ParamTypes ); } + return compileAndGenerateMock( classBuilder, handler ); + } + private object compileAndGenerateMock( MockClassBuilder classBuilder, IMockedCallHandler handler ) + { // create type classBuilder.Compile( ); |
From: Griffin C. <gc...@us...> - 2005-04-23 21:53:45
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3617/DotNetMock/Dynamic/Generate Modified Files: ClassGenerator.cs MockClassBuilder.cs Log Message: - Added overload ImplementMockedMethod to MockClassBuilder - Added Roman's ClassGenerator patches Index: MockClassBuilder.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/MockClassBuilder.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MockClassBuilder.cs 8 Apr 2005 03:33:01 -0000 1.2 --- MockClassBuilder.cs 23 Apr 2005 21:53:33 -0000 1.3 *************** *** 129,132 **** --- 129,144 ---- /// <param name="parameterTypes">array of <see cref="Type"/>s in /// the method signature</param> + public void ImplementMockedMethod(string methodName, Type returnType, Type[] parameterTypes ) + { + ImplementMockedMethod(methodName, returnType, parameterTypes, null); + } + /// <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> /// <param name="mi">if not null, used to get extra parameter information</param> public void ImplementMockedMethod(string methodName, Type returnType, Type[] parameterTypes, MethodInfo mi) Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/Generate/ClassGenerator.cs,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ClassGenerator.cs 9 Jan 2005 06:48:35 -0000 1.10 --- ClassGenerator.cs 23 Apr 2005 21:53:33 -0000 1.11 *************** *** 2,5 **** --- 2,6 ---- // Copyright (c) 2004 Griffin Caprio & Choy Rim. All rights reserved. #endregion + #region Imports using System; *************** *** 7,11 **** using System.Reflection; using System.Reflection.Emit; - using DotNetMock.Dynamic; #endregion --- 8,11 ---- *************** *** 15,43 **** /// Dynamic Mock object generation engine. Generates the dynamic proxies for dynamic mock objects. /// </summary> ! 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 a mock object for the specified type. --- 15,49 ---- /// Dynamic Mock object generation engine. Generates the dynamic proxies for dynamic mock objects. /// </summary> ! /// <author>Griffin Caprio</author> ! /// <author>Choy Rim</author> ! /// <author>Roman V. Gavrilov</author> ! public class ClassGenerator { ! private AssemblyBuilder _assemblyBuilder; ! private ModuleBuilder _moduleBuilder; ! private string _assemblyFilename; + #region Constructors /// <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; } + #endregion + + #region Public Methods /// <summary> /// Generates a mock object for the specified type. *************** *** 47,51 **** /// 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; --- 53,57 ---- /// 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; *************** *** 62,115 **** 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) { IList methods; ! if (type.IsInterface) { ! ArrayList list = new ArrayList(); ! getMethodsForInterface(type, list); methods = list; } else { ! methods = type.GetMethods(); } return methods; } ! ! private void getMethodsForInterface(Type type, ArrayList list) { ! list.AddRange(type.GetMethods()); ! foreach (Type interfaceType in type.GetInterfaces()) { ! getMethodsForInterface(interfaceType, list); } } ! private static void determineSuperClassAndInterfaces(Type targetType, out Type superClass, out Type[] interfaces) { ! if (targetType.IsInterface) { superClass = null; ! interfaces = new Type[] { targetType }; } ! else { superClass = targetType; --- 68,155 ---- 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; } ! /// <summary> ! /// Generates a mock object with an interface defined by an array of method signatures. ! /// </summary> ! /// <param name="typeName">Name of the type to ganerate.</param> ! /// <param name="methodSignatures">Array of method signatures of methods to be implemented.</param> ! /// <param name="handler">Mocked calls handler.</param> ! /// <returns>Instance of generated class.</returns> ! public object Generate( string typeName, MethodSignature[] methodSignatures, IMockedCallHandler handler ) ! { ! MockClassBuilder classBuilder = new MockClassBuilder( ! _moduleBuilder, ! typeName, ! typeof ( object ), ! Type.EmptyTypes ! ); ! foreach ( MethodSignature ms in methodSignatures ) ! { ! classBuilder.ImplementMockedMethod( ms.MethodName, ms.ReturnType, ms.ParamTypes ); ! } ! // 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; ! } ! #endregion ! ! #region Private Methods ! private IList getMethods( Type type ) { IList methods; ! if ( type.IsInterface ) { ! ArrayList list = new ArrayList( ); ! getMethodsForInterface( type, list ); methods = list; } else { ! methods = type.GetMethods( ); } return methods; } ! private void getMethodsForInterface( Type type, ArrayList list ) { ! list.AddRange( type.GetMethods( ) ); ! foreach ( Type interfaceType in type.GetInterfaces( ) ) { ! getMethodsForInterface( interfaceType, list ); } } ! private static void determineSuperClassAndInterfaces( Type targetType, out Type superClass, out Type[] interfaces ) { ! if ( targetType.IsInterface ) { superClass = null; ! interfaces = new Type[] {targetType}; } ! else { superClass = targetType; *************** *** 117,129 **** } } ! private static AssemblyBuilder newAssemblyBuilder(AssemblyBuilderAccess access) { AppDomain appDomain = AppDomain.CurrentDomain; ! AssemblyName assemblyName = new AssemblyName(); assemblyName.Name = "DynamicMockAssembly"; return appDomain.DefineDynamicAssembly( assemblyName, access ); } } ! ! ! } --- 157,169 ---- } } ! private static AssemblyBuilder newAssemblyBuilder( AssemblyBuilderAccess access ) { AppDomain appDomain = AppDomain.CurrentDomain; ! AssemblyName assemblyName = new AssemblyName( ); assemblyName.Name = "DynamicMockAssembly"; return appDomain.DefineDynamicAssembly( assemblyName, access ); } + #endregion + } ! } \ No newline at end of file |
From: Griffin C. <gc...@us...> - 2005-04-23 21:53:45
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3617/DotNetMock.Tests/Dynamic/Generate Modified Files: ClassGeneratorTests.cs Log Message: - Added overload ImplementMockedMethod to MockClassBuilder - Added Roman's ClassGenerator patches Index: ClassGeneratorTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/Generate/ClassGeneratorTests.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** ClassGeneratorTests.cs 8 Apr 2005 03:33:00 -0000 1.17 --- ClassGeneratorTests.cs 23 Apr 2005 21:53:33 -0000 1.18 *************** *** 1,110 **** using System; using System.IO; ! using NUnit.Framework; using DotNetMock.Dynamic; - using DotNetMock.Dynamic.Predicates; using DotNetMock.Dynamic.Generate; ! using System.Collections; ! using System.Reflection; ! namespace DotNetMock.Tests.Dynamic.Generate { #region Dummy Test Structures ! public interface IThingy { ! void NoArgs(); ! void Another(); ! void WithSimpleArg(string s); ! void WithTwoArgs(string a, string b); ! void WithThreeArgs(string a, string b, string c); ! void WithLotsOfArgs(string a, string b, string c, string d, string e, string f); ! void WithOtherArgs(int x, bool y, object o, IList list); ! void WithParams(int i, params string[] extra); ! object simpleReturn(); ! string stringReturn(); ! int intReturn(); ! bool boolReturn(); ! double doubleReturn(); ! IThingy AThingy(); string ReadProperty { get; } string WriteProperty { set; } string AProperty { get; set; } ! void TakesGuid(Guid guid); ! Guid ReturnsGuid(); } - public abstract class SolidThingy { ! public virtual string VirtualMethod() { return "xx"; } ! public override string ToString() { return "xx"; } ! public abstract string AbstractMethod(); ! // cannot override ! public static string StaticMethod() { return "xx"; } ! public string NonVirtualMethod() { return "xx"; } ! private string privateMethod() { return "xx"; } ! internal string internalMethod() { return "xx"; } ! protected virtual string protectedMethod() { return "xx"; } ! protected internal virtual string protectedInternalMethod() { return "xx"; } ! string defaultInternalMethod() { return "xx"; } } public interface IBaseInterface { ! void BaseMethod(); } ! ! public interface ISubInterface: IBaseInterface { ! void SubMethod(); } - #endregion [TestFixture] ! public class ClassGeneratorTest { private ClassGenerator cg; private IDynamicMock mock; private IThingy thingy; - [SetUp] ! public void SetUp() { ! cg = new ClassGenerator(); ! mock = new DynamicMock("Test Mock"); ! thingy = (IThingy)cg.Generate(typeof(IThingy), mock); } ! ! 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; --- 1,131 ---- using System; + using System.Collections; using System.IO; ! using System.Reflection; using DotNetMock.Dynamic; using DotNetMock.Dynamic.Generate; ! using DotNetMock.Dynamic.Predicates; ! using NUnit.Framework; namespace DotNetMock.Tests.Dynamic.Generate { + #region Dummy Test Structures ! public interface IThingy { ! void NoArgs( ); ! void Another( ); ! void WithSimpleArg( string s ); ! void WithTwoArgs( string a, string b ); ! void WithThreeArgs( string a, string b, string c ); ! void WithLotsOfArgs( string a, string b, string c, string d, string e, string f ); ! void WithOtherArgs( int x, bool y, object o, IList list ); ! void WithParams( int i, params string[] extra ); ! object simpleReturn( ); ! string stringReturn( ); ! int intReturn( ); ! bool boolReturn( ); ! double doubleReturn( ); ! IThingy AThingy( ); string ReadProperty { get; } string WriteProperty { set; } string AProperty { get; set; } ! void TakesGuid( Guid guid ); ! Guid ReturnsGuid( ); } public abstract class SolidThingy { ! public virtual string VirtualMethod( ) ! { ! return "xx"; ! } ! public override string ToString( ) ! { ! return "xx"; ! } ! public abstract string AbstractMethod( ); // cannot override ! public static string StaticMethod( ) ! { ! return "xx"; ! } ! public string NonVirtualMethod( ) ! { ! return "xx"; ! } ! private string privateMethod( ) ! { ! return "xx"; ! } ! internal string internalMethod( ) ! { ! return "xx"; ! } ! protected virtual string protectedMethod( ) ! { ! return "xx"; ! } ! protected internal virtual string protectedInternalMethod( ) ! { ! return "xx"; ! } ! private string defaultInternalMethod( ) ! { ! return "xx"; ! } } public interface IBaseInterface { ! void BaseMethod( ); } ! public interface ISubInterface : IBaseInterface { ! void SubMethod( ); } #endregion [TestFixture] ! public class ClassGeneratorTest { private ClassGenerator cg; private IDynamicMock mock; private IThingy thingy; [SetUp] ! public void SetUp( ) { ! cg = new ClassGenerator( ); ! mock = new DynamicMock( "Test Mock" ); ! thingy = ( IThingy )cg.Generate( typeof ( IThingy ), mock ); } ! private 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 ); } ! private 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; *************** *** 112,133 **** private MethodInfo _methodInfo = null; } ! [Test] public void NamedParametersAvailableInProxy() { DirectionalMockedCallHandler dmch = ! new DirectionalMockedCallHandler(); ! IDirectionalParameters dp = (IDirectionalParameters) ! cg.Generate(typeof(IDirectionalParameters), dmch); ! Type dpt = dp.GetType(); ! MethodInfo mi = dpt.GetMethod("DoWithInParameters"); ! ParameterInfo[] pis = mi.GetParameters(); ! Assert.AreEqual(2, pis.Length); ! Assert.AreEqual(typeof(int), pis[0].ParameterType); ! Assert.AreEqual(typeof(string), pis[1].ParameterType); ! Assert.AreEqual("a", pis[0].Name); ! Assert.AreEqual("b", pis[1].Name); } [Test] ! public void GeneratePersistentAssembly() { if ( File.Exists( "test.dll" ) ) --- 133,172 ---- private MethodInfo _methodInfo = null; } + [Test] + public void SaveGeneratedAssembly() + { + string mockAssemblyName = "mockAssembly.dll"; + if ( File.Exists( mockAssemblyName ) ) + { + File.Delete( mockAssemblyName ); + } + cg = new ClassGenerator( mockAssemblyName ); + mock = new DynamicMock( "Test Mock" ); + thingy = ( IThingy )cg.Generate( typeof ( IThingy ), mock ); ! Assert.IsTrue( File.Exists( mockAssemblyName ) ); ! if ( File.Exists( mockAssemblyName ) ) ! { ! File.Delete( mockAssemblyName ); ! } ! } ! [Test] ! public void NamedParametersAvailableInProxy( ) { DirectionalMockedCallHandler dmch = ! new DirectionalMockedCallHandler( ); ! IDirectionalParameters dp = ( IDirectionalParameters ) ! cg.Generate( typeof ( IDirectionalParameters ), dmch ); ! Type dpt = dp.GetType( ); ! MethodInfo mi = dpt.GetMethod( "DoWithInParameters" ); ! ParameterInfo[] pis = mi.GetParameters( ); ! Assert.AreEqual( 2, pis.Length ); ! Assert.AreEqual( typeof ( int ), pis[ 0 ].ParameterType ); ! Assert.AreEqual( typeof ( string ), pis[ 1 ].ParameterType ); ! Assert.AreEqual( "a", pis[ 0 ].Name ); ! Assert.AreEqual( "b", pis[ 1 ].Name ); } [Test] ! public void GeneratePersistentAssembly( ) { if ( File.Exists( "test.dll" ) ) *************** *** 135,142 **** 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" ) ) --- 174,181 ---- 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" ) ) *************** *** 145,428 **** } } ! [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() { ! mock.Expect("NoArgs"); ! thingy.NoArgs(); ! mock.Verify(); } - [Test] ! public void CallMethodWithReturn() { object x = "sdfs"; ! mock.ExpectAndReturn("simpleReturn", x); ! object result = thingy.simpleReturn(); ! Assert.AreEqual(x, result); ! mock.Verify(); } - [Test] ! public void CallMethodWithReturnAndCast() { string x = "sdfs"; ! mock.ExpectAndReturn("stringReturn", x); ! string result = thingy.stringReturn(); ! Assert.AreEqual(x, result); ! mock.Verify(); } - [Test] ! public void CallMethodWithWeirdObjectReturn() { IThingy t = thingy; ! mock.ExpectAndReturn("AThingy", t); ! IThingy result = thingy.AThingy(); ! Assert.AreEqual(thingy, result); ! mock.Verify(); } - [Test] ! public void CallMethodWithReturnInt() { ! mock.ExpectAndReturn("intReturn", 7); ! int result = thingy.intReturn(); ! Assert.AreEqual(7, result); ! mock.Verify(); } - [Test] ! public void CallMethodWithReturnBoxings() { ! mock.ExpectAndReturn("boolReturn", true); ! mock.ExpectAndReturn("doubleReturn", 1234567891234E+10); ! Assert.IsTrue(thingy.boolReturn()); ! Assert.AreEqual(1234567891234E+10, thingy.doubleReturn()); ! mock.Verify(); } - [Test] ! [ExpectedException(typeof(System.IO.IOException))] ! public void CallMethodTheThrowsException() { ! mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); ! thingy.boolReturn(); } - [Test] ! public void CallMethodWithParamExpectations() { ! mock.Expect("WithSimpleArg", new IsEqual("hello")); ! thingy.WithSimpleArg("hello"); ! mock.Verify(); } - [Test] ! [ExpectedException(typeof(DotNetMock.AssertionException))] ! public void CallMethodWithParamExpectationsThatFails() { ! mock.Expect("WithSimpleArg", new IsEqual("hello")); ! thingy.WithSimpleArg("goodbye"); ! mock.Verify(); } - [Test] ! public void CallMethodWithTwoParamExpectations() { ! mock.Expect("WithTwoArgs", new IsEqual("hello"), new IsEqual("world")); ! thingy.WithTwoArgs("hello", "world"); ! mock.Verify(); } - [Test] ! [ExpectedException(typeof(AssertionException))] ! public void CallMethodWithTwoParamExpectationsThatFails() { ! mock.Expect("WithTwoArgs", new IsEqual("hello"), new IsEqual("world")); ! thingy.WithTwoArgs("hello", "moon"); ! mock.Verify(); } - [Test] ! public void CallMethodWithThreeParamExpectations() { ! mock.Expect("WithThreeArgs", new IsEqual("hello"), new IsEqual("the"), new IsEqual("world")); ! thingy.WithThreeArgs("hello", "the", "world"); ! mock.Verify(); } - [Test] ! public void CallMethodWithLoadsOfParamExpectations() { ! mock.Expect("WithLotsOfArgs", new IsEqual("hello"), new IsEqual("world"), new IsEqual("is"), new IsEqual("this"), new IsEqual("the"), new IsEqual("end")); ! thingy.WithLotsOfArgs("hello", "world", "is", "this", "the", "end"); ! mock.Verify(); } - [Test] ! public void CallMethodWithOtherArgs() { ! IList l = new ArrayList(); ! mock.Expect("WithOtherArgs", new IsEqual(6), new IsEqual(true), new IsNull(), new IsEqual(l)); ! thingy.WithOtherArgs(6, true, null, l); ! mock.Verify(); } - [Test] ! public void CallReadOnlyProperty() { ! mock.ExpectAndReturn("ReadProperty", "hello"); ! mock.ExpectAndReturn("ReadProperty", "world"); ! Assert.AreEqual("hello", thingy.ReadProperty); ! Assert.AreEqual("world", thingy.ReadProperty); ! mock.Verify(); } - [Test] ! public void WriteOnlyPropertyExpectations() { ! mock.Expect("WriteProperty", "hello"); ! mock.Expect("WriteProperty", "world"); thingy.WriteProperty = "hello"; thingy.WriteProperty = "world"; ! mock.Verify(); } - [Test] ! public void ReadAndWriteProperty() { ! mock.Expect("AProperty", "hello"); ! mock.Expect("AProperty", "world"); ! mock.ExpectAndReturn("AProperty", "good"); ! mock.ExpectAndReturn("AProperty", "bye"); thingy.AProperty = "hello"; thingy.AProperty = "world"; ! Assert.AreEqual("good", thingy.AProperty); ! Assert.AreEqual("bye", thingy.AProperty); ! mock.Verify(); } - [Test] ! public void ExtendClass() { ! cg = new ClassGenerator(); ! SolidThingy s = (SolidThingy)cg.Generate(typeof(SolidThingy), mock); ! ! mock.ExpectAndReturn("VirtualMethod", "hello"); ! mock.ExpectAndReturn("ToString", "STRING"); ! mock.ExpectAndReturn("GetHashCode", 123); ! mock.ExpectAndReturn("AbstractMethod", "fish"); ! Assert.AreEqual("hello", s.VirtualMethod()); ! Assert.AreEqual("STRING", s.ToString()); ! Assert.AreEqual(123, s.GetHashCode()); ! Assert.AreEqual("fish", s.AbstractMethod()); ! ! Assert.AreEqual("xx", s.NonVirtualMethod()); ! mock.Verify(); } - [Test] ! public void ExtendedInterface() { ! cg = new ClassGenerator(); ! ! mock.Expect("BaseMethod"); ! mock.Expect("SubMethod"); ! ! ISubInterface i = (ISubInterface)cg.Generate(typeof(ISubInterface), mock); ! ! i.BaseMethod(); ! i.SubMethod(); ! ! mock.Verify(); } - [Test] ! public void ValueTypeParameter() { ! cg = new ClassGenerator(); ! Guid guid = Guid.NewGuid(); ! ! mock.Expect("TakesGuid", new IsEqual(guid)); ! ! IThingy i = (IThingy)cg.Generate(typeof(IThingy), mock); ! ! i.TakesGuid(guid); ! ! mock.Verify(); } - [Test] ! public void ValueTypeReturn() { ! cg = new ClassGenerator(); ! Guid guid = Guid.NewGuid(); ! ! mock.ExpectAndReturn("ReturnsGuid", guid); ! ! IThingy i = (IThingy)cg.Generate(typeof(IThingy), mock); ! ! Guid returnedGuid = i.ReturnsGuid(); ! ! mock.Verify(); ! Assert.AreEqual(guid, returnedGuid); } } ! } --- 184,454 ---- } } ! [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( ) { ! mock.Expect( "NoArgs" ); ! thingy.NoArgs( ); ! mock.Verify( ); } [Test] ! public void CallMethodWithReturn( ) { object x = "sdfs"; ! mock.ExpectAndReturn( "simpleReturn", x ); ! object result = thingy.simpleReturn( ); ! Assert.AreEqual( x, result ); ! mock.Verify( ); } [Test] ! public void CallMethodWithReturnAndCast( ) { string x = "sdfs"; ! mock.ExpectAndReturn( "stringReturn", x ); ! string result = thingy.stringReturn( ); ! Assert.AreEqual( x, result ); ! mock.Verify( ); } [Test] ! public void CallMethodWithWeirdObjectReturn( ) { IThingy t = thingy; ! mock.ExpectAndReturn( "AThingy", t ); ! IThingy result = thingy.AThingy( ); ! Assert.AreEqual( thingy, result ); ! mock.Verify( ); } [Test] ! public void CallMethodWithReturnInt( ) { ! mock.ExpectAndReturn( "intReturn", 7 ); ! int result = thingy.intReturn( ); ! Assert.AreEqual( 7, result ); ! mock.Verify( ); } [Test] ! public void CallMethodWithReturnBoxings( ) { ! mock.ExpectAndReturn( "boolReturn", true ); ! mock.ExpectAndReturn( "doubleReturn", 1234567891234E+10 ); ! Assert.IsTrue( thingy.boolReturn( ) ); ! Assert.AreEqual( 1234567891234E+10, thingy.doubleReturn( ) ); ! mock.Verify( ); } [Test] ! [ExpectedException( typeof ( IOException ) )] ! public void CallMethodTheThrowsException( ) { ! mock.ExpectAndThrow( "boolReturn", new IOException( ) ); ! thingy.boolReturn( ); } [Test] ! public void CallMethodWithParamExpectations( ) { ! mock.Expect( "WithSimpleArg", new IsEqual( "hello" ) ); ! thingy.WithSimpleArg( "hello" ); ! mock.Verify( ); } [Test] ! [ExpectedException( typeof ( AssertionException ) )] ! public void CallMethodWithParamExpectationsThatFails( ) { ! mock.Expect( "WithSimpleArg", new IsEqual( "hello" ) ); ! thingy.WithSimpleArg( "goodbye" ); ! mock.Verify( ); } [Test] ! public void CallMethodWithTwoParamExpectations( ) { ! mock.Expect( "WithTwoArgs", new IsEqual( "hello" ), new IsEqual( "world" ) ); ! thingy.WithTwoArgs( "hello", "world" ); ! mock.Verify( ); } [Test] ! [ExpectedException( typeof ( AssertionException ) )] ! public void CallMethodWithTwoParamExpectationsThatFails( ) { ! mock.Expect( "WithTwoArgs", new IsEqual( "hello" ), new IsEqual( "world" ) ); ! thingy.WithTwoArgs( "hello", "moon" ); ! mock.Verify( ); } [Test] ! public void CallMethodWithThreeParamExpectations( ) { ! mock.Expect( "WithThreeArgs", new IsEqual( "hello" ), new IsEqual( "the" ), new IsEqual( "world" ) ); ! thingy.WithThreeArgs( "hello", "the", "world" ); ! mock.Verify( ); } [Test] ! public void CallMethodWithLoadsOfParamExpectations( ) { ! mock.Expect( "WithLotsOfArgs", new IsEqual( "hello" ), new IsEqual( "world" ), new IsEqual( "is" ), new IsEqual( "this" ), new IsEqual( "the" ), new IsEqual( "end" ) ); ! thingy.WithLotsOfArgs( "hello", "world", "is", "this", "the", "end" ); ! mock.Verify( ); } [Test] ! public void CallMethodWithOtherArgs( ) { ! IList l = new ArrayList( ); ! mock.Expect( "WithOtherArgs", new IsEqual( 6 ), new IsEqual( true ), new IsNull( ), new IsEqual( l ) ); ! thingy.WithOtherArgs( 6, true, null, l ); ! mock.Verify( ); } [Test] ! public void CallReadOnlyProperty( ) { ! mock.ExpectAndReturn( "ReadProperty", "hello" ); ! mock.ExpectAndReturn( "ReadProperty", "world" ); ! Assert.AreEqual( "hello", thingy.ReadProperty ); ! Assert.AreEqual( "world", thingy.ReadProperty ); ! mock.Verify( ); } [Test] ! public void WriteOnlyPropertyExpectations( ) { ! mock.Expect( "WriteProperty", "hello" ); ! mock.Expect( "WriteProperty", "world" ); thingy.WriteProperty = "hello"; thingy.WriteProperty = "world"; ! mock.Verify( ); } [Test] ! public void ReadAndWriteProperty( ) { ! mock.Expect( "AProperty", "hello" ); ! mock.Expect( "AProperty", "world" ); ! mock.ExpectAndReturn( "AProperty", "good" ); ! mock.ExpectAndReturn( "AProperty", "bye" ); thingy.AProperty = "hello"; thingy.AProperty = "world"; ! Assert.AreEqual( "good", thingy.AProperty ); ! Assert.AreEqual( "bye", thingy.AProperty ); ! mock.Verify( ); } [Test] ! public void ExtendClass( ) { ! cg = new ClassGenerator( ); ! SolidThingy s = ( SolidThingy )cg.Generate( typeof ( SolidThingy ), mock ); ! mock.ExpectAndReturn( "VirtualMethod", "hello" ); ! mock.ExpectAndReturn( "ToString", "STRING" ); ! mock.ExpectAndReturn( "GetHashCode", 123 ); ! mock.ExpectAndReturn( "AbstractMethod", "fish" ); ! Assert.AreEqual( "hello", s.VirtualMethod( ) ); ! Assert.AreEqual( "STRING", s.ToString( ) ); ! Assert.AreEqual( 123, s.GetHashCode( ) ); ! Assert.AreEqual( "fish", s.AbstractMethod( ) ); ! Assert.AreEqual( "xx", s.NonVirtualMethod( ) ); ! mock.Verify( ); } [Test] ! public void ExtendedInterface( ) { ! cg = new ClassGenerator( ); ! mock.Expect( "BaseMethod" ); ! mock.Expect( "SubMethod" ); ! ISubInterface i = ( ISubInterface )cg.Generate( typeof ( ISubInterface ), mock ); ! i.BaseMethod( ); ! i.SubMethod( ); ! mock.Verify( ); } [Test] ! public void ValueTypeParameter( ) { ! cg = new ClassGenerator( ); ! Guid guid = Guid.NewGuid( ); ! mock.Expect( "TakesGuid", new IsEqual( guid ) ); ! IThingy i = ( IThingy )cg.Generate( typeof ( IThingy ), mock ); ! i.TakesGuid( guid ); ! mock.Verify( ); } [Test] ! public void ValueTypeReturn( ) { ! cg = new ClassGenerator( ); ! Guid guid = Guid.NewGuid( ); ! mock.ExpectAndReturn( "ReturnsGuid", guid ); ! IThingy i = ( IThingy )cg.Generate( typeof ( IThingy ), mock ); ! Guid returnedGuid = i.ReturnsGuid( ); ! mock.Verify( ); ! Assert.AreEqual( guid, returnedGuid ); ! } ! [Test] ! public void GenerateClassWithSpecifiedMethods( ) ! { ! cg = new ClassGenerator( ); ! DirectionalMockedCallHandler dmch = new DirectionalMockedCallHandler( ); ! MethodSignature ms1 = new MethodSignature( "Method1", typeof ( void ), Type.EmptyTypes ); ! MethodSignature ms2 = new MethodSignature( "Method2", typeof ( object ), new Type[] {typeof ( int ), typeof ( object )} ); ! MethodSignature[] mss = new MethodSignature[] {ms1, ms2}; ! object obj = cg.Generate( "TestType", mss, dmch ); ! Type genType = obj.GetType( ); ! genType.GetMethod( ms1.MethodName ).Invoke( obj, new object[0] ); ! Assert.AreEqual( ms1.MethodName, dmch.MethodName, "Wrong [dmch.MethodName]." ); ! Assert.AreEqual( 0, dmch.IncomingArgs.Length, "Wrong [dmch.IncomingArgs.Length]." ); ! object testObject = new object( ); ! genType.GetMethod( ms2.MethodName ).Invoke( obj, new object[] {5, testObject} ); ! Assert.AreEqual( ms2.MethodName, dmch.MethodName, "ms2.MethodName != dmch.MethodName" ); ! Assert.AreEqual( 2, dmch.IncomingArgs.Length, "Wrong [dmch.IncomingArgs.Length]." ); ! Assert.AreEqual( 5, dmch.IncomingArgs[ 0 ], "Wrong [dmch.IncomingArgs[0]]." ); ! Assert.AreEqual( testObject, dmch.IncomingArgs[ 1 ], "Wrong [dmch.IncomingArgs[1]]." ); } } ! } \ No newline at end of file |
From: Griffin C. <gc...@us...> - 2005-04-23 21:53:45
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3617/DotNetMock/Dynamic Modified Files: MethodSignature.cs Log Message: - Added overload ImplementMockedMethod to MockClassBuilder - Added Roman's ClassGenerator patches Index: MethodSignature.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock/Dynamic/MethodSignature.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MethodSignature.cs 23 Apr 2005 21:28:39 -0000 1.1 --- MethodSignature.cs 23 Apr 2005 21:53:33 -0000 1.2 *************** *** 7,10 **** --- 7,11 ---- /// </summary> /// <author>Roman V. Gavrilov</author> + /// <author>Griffin Caprio</author> public class MethodSignature { |
From: Griffin C. <gc...@us...> - 2005-04-23 21:36:14
|
Update of /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28030/DotNetMock.Tests/Dynamic Modified Files: MethodSignatureTests.cs Log Message: Filled out test coverage Index: MethodSignatureTests.cs =================================================================== RCS file: /cvsroot/dotnetmock/dotnetmock/DotNetMock.Tests/Dynamic/MethodSignatureTests.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MethodSignatureTests.cs 23 Apr 2005 21:28:39 -0000 1.1 --- MethodSignatureTests.cs 23 Apr 2005 21:35:52 -0000 1.2 *************** *** 47,50 **** --- 47,75 ---- Assert.AreEqual( expected, actual ); } + [Test] + public void TestNotEqualToNull() + { + MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) ); + Assert.IsFalse( sign.Equals(null) ); + } + [Test] + public void TestNotEqualToNonMethodSignatureObject() + { + MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) ); + Assert.IsFalse( sign.Equals(new MockObject()) ); + } + [Test] + public void TestGetHashCode() + { + MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) ); + Assert.IsNotNull( sign.GetHashCode() ); + } + [Test] + public void TestNotEqualsDifferentParameterTypes() + { + MethodSignature sign = new MethodSignature( "Method1", typeof ( Exception ), typeof ( bool ), typeof ( object ), typeof ( Exception ) ); + MethodSignature sign1 = new MethodSignature( "Method1", typeof ( Exception ), typeof ( object ), typeof ( bool ), typeof ( Exception ) ); + Assert.IsFalse( sign.Equals(sign1) ); + } #endregion |