You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(31) |
Dec
(26) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(8) |
Feb
(27) |
Mar
(15) |
Apr
|
May
(2) |
Jun
(13) |
Jul
(59) |
Aug
(48) |
Sep
(9) |
Oct
(4) |
Nov
(24) |
Dec
|
| 2004 |
Jan
(24) |
Feb
(2) |
Mar
(12) |
Apr
(9) |
May
(4) |
Jun
(26) |
Jul
(20) |
Aug
(23) |
Sep
(13) |
Oct
(31) |
Nov
(23) |
Dec
(11) |
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
(19) |
May
(64) |
Jun
(7) |
Jul
(20) |
Aug
(1) |
Sep
(6) |
Oct
|
Nov
(3) |
Dec
|
| 2006 |
Jan
|
Feb
(69) |
Mar
(18) |
Apr
(1) |
May
(4) |
Jun
(3) |
Jul
(27) |
Aug
(19) |
Sep
(12) |
Oct
(3) |
Nov
(13) |
Dec
(6) |
| 2007 |
Jan
(20) |
Feb
(17) |
Mar
(1) |
Apr
(3) |
May
(4) |
Jun
(11) |
Jul
(10) |
Aug
(24) |
Sep
(19) |
Oct
(13) |
Nov
(8) |
Dec
(7) |
| 2008 |
Jan
(54) |
Feb
(24) |
Mar
(11) |
Apr
(35) |
May
(13) |
Jun
(10) |
Jul
(30) |
Aug
(18) |
Sep
(21) |
Oct
(18) |
Nov
(40) |
Dec
(76) |
| 2009 |
Jan
(64) |
Feb
(23) |
Mar
(15) |
Apr
(23) |
May
(46) |
Jun
(25) |
Jul
(31) |
Aug
(7) |
Sep
(7) |
Oct
(6) |
Nov
(15) |
Dec
(19) |
| 2010 |
Jan
(13) |
Feb
(8) |
Mar
(6) |
Apr
(4) |
May
(8) |
Jun
(7) |
Jul
(3) |
Aug
(9) |
Sep
(6) |
Oct
(15) |
Nov
(3) |
Dec
(5) |
| 2011 |
Jan
(1) |
Feb
|
Mar
(4) |
Apr
(5) |
May
(2) |
Jun
|
Jul
(2) |
Aug
(2) |
Sep
(2) |
Oct
(4) |
Nov
(2) |
Dec
(3) |
| 2012 |
Jan
(6) |
Feb
(2) |
Mar
(3) |
Apr
(3) |
May
(3) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(1) |
| 2013 |
Jan
(3) |
Feb
(1) |
Mar
|
Apr
|
May
(1) |
Jun
(1) |
Jul
|
Aug
(5) |
Sep
|
Oct
(1) |
Nov
(2) |
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
| 2015 |
Jan
|
Feb
(19) |
Mar
(115) |
Apr
(23) |
May
(41) |
Jun
(48) |
Jul
(59) |
Aug
(29) |
Sep
(40) |
Oct
(78) |
Nov
(58) |
Dec
(47) |
| 2016 |
Jan
(25) |
Feb
(30) |
Mar
(29) |
Apr
(10) |
May
(17) |
Jun
(1) |
Jul
(1) |
Aug
(6) |
Sep
(2) |
Oct
(1) |
Nov
(3) |
Dec
(2) |
| 2017 |
Jan
(5) |
Feb
(2) |
Mar
(7) |
Apr
(1) |
May
(7) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2018 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(1) |
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
|
Nov
(2) |
Dec
|
| 2019 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
(29) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2021 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(5) |
Dec
(3) |
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(5) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
|
Jun
(7) |
Jul
(1) |
Aug
|
Sep
(6) |
Oct
(4) |
Nov
(1) |
Dec
(4) |
| 2024 |
Jan
(2) |
Feb
(5) |
Mar
|
Apr
|
May
(8) |
Jun
(159) |
Jul
(90) |
Aug
(22) |
Sep
|
Oct
(6) |
Nov
(8) |
Dec
(1) |
| 2025 |
Jan
(20) |
Feb
(6) |
Mar
(2) |
Apr
(4) |
May
(29) |
Jun
(63) |
Jul
(62) |
Aug
(70) |
Sep
(120) |
Oct
(46) |
Nov
(33) |
Dec
(25) |
| 2026 |
Jan
(37) |
Feb
(56) |
Mar
(62) |
Apr
(26) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Owen R. <exo...@us...> - 2004-10-22 11:47:06
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19470/src/NMock/Dynamic Modified Files: ClassGenerator.cs Log Message: upgraded to nunit 2.2 upgraded to new version of NAnt Index: ClassGenerator.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/ClassGenerator.cs,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** ClassGenerator.cs 23 Jun 2004 04:44:53 -0000 1.22 --- ClassGenerator.cs 22 Oct 2004 11:46:26 -0000 1.23 *************** *** 88,92 **** private object CreateProxyInstance(Type proxyType) { ! object result = Activator.CreateInstance(proxyType); FieldInfo handlerField = proxyType.GetField(INVOCATION_HANDLER_FIELD_NAME); --- 88,92 ---- private object CreateProxyInstance(Type proxyType) { ! object result = Activator.CreateInstance(proxyType, true); FieldInfo handlerField = proxyType.GetField(INVOCATION_HANDLER_FIELD_NAME); |
|
From: Owen R. <exo...@us...> - 2004-10-22 11:47:06
|
Update of /cvsroot/nmock/nmock/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19470/lib Modified Files: nunit.framework.dll Log Message: upgraded to nunit 2.2 upgraded to new version of NAnt Index: nunit.framework.dll =================================================================== RCS file: /cvsroot/nmock/nmock/lib/nunit.framework.dll,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 Binary files /tmp/cvsmjgQDh and /tmp/cvsM9jvoS differ |
|
From: Owen R. <exo...@us...> - 2004-10-22 11:46:55
|
Update of /cvsroot/nmock/nmock/tools/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19470/tools/lib Added Files: NUnitCore.dll Log Message: upgraded to nunit 2.2 upgraded to new version of NAnt --- NEW FILE: NUnitCore.dll --- (This appears to be a binary file; contents omitted.) |
|
From: Owen R. <exo...@us...> - 2004-10-22 11:46:55
|
Update of /cvsroot/nmock/nmock/tools/lib/net/1.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19470/tools/lib/net/1.1 Added Files: NDoc.Core.dll NDoc.Documenter.Msdn.dll nunit.core.dll nunit.framework.dll nunit.util.dll Log Message: upgraded to nunit 2.2 upgraded to new version of NAnt --- NEW FILE: NDoc.Documenter.Msdn.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.framework.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: NDoc.Core.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.util.dll --- (This appears to be a binary file; contents omitted.) --- NEW FILE: nunit.core.dll --- (This appears to be a binary file; contents omitted.) |
|
From: Owen R. <exo...@us...> - 2004-10-22 11:39:57
|
Update of /cvsroot/nmock/nmock/tools/lib/net/1.1 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18574/1.1 Log Message: Directory /cvsroot/nmock/nmock/tools/lib/net/1.1 added to the repository |
|
From: Owen R. <exo...@us...> - 2004-10-22 11:39:33
|
Update of /cvsroot/nmock/nmock/tools/lib/net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18489/net Log Message: Directory /cvsroot/nmock/nmock/tools/lib/net added to the repository |
|
From: Owen R. <exo...@us...> - 2004-10-22 11:38:56
|
Update of /cvsroot/nmock/nmock/tools/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18340/lib Log Message: Directory /cvsroot/nmock/nmock/tools/lib added to the repository |
|
From: <thi...@gm...> - 2004-10-19 08:38:44
|
Anyone ? Or am I on the wrong list ?
regards
Thibaut
On Thu, 14 Oct 2004 11:00:26 +0200, Thibaut Barr=E8re
<thi...@gm...> wrote:
> Hi gentlemen,
>=20
> I'm really new to mock objects, apart from very basic stuff, and would
> like to have your opinion about the way I plan to use them.
>=20
> I am testing interaction with remote servers, and I'm expecting to be
> called in one of several callbacks (registered to the server) in my
> testfixture to decide that my test has passed. Callbacks, if called,
> set an AutoResetEvent. I'm currently testing the behaviour using this
> :
>=20
> AutoResetEvent _connected =3D new AutoResetEvent(false);
>=20
> /// <summary>
> /// Callback for connect test
> /// </summary>
> /// <param name=3D"e"></param>
> private void Connected(object sender,ConnectionEventArgs e)
> {
> // mark the event
> _connected.Set();
> }
>=20
> ....
>=20
> WaitHandle[] handles =3D { _accepted,_rejected,_cancelled };
> Assert.IsTrue(WaitHandle.WaitAny(handles,5000,true)!=3DWaitHandle.WaitTim=
eout,"No
> valid callback called.");
>=20
> I'm thinking about refactoring the callbacks and waitany code inside a
> mock object, with some "expectations" that would do what I need. I
> would then mock the receiver, not the server.
>=20
> To give more background, the remote servers (~ 10 different
> implementations, native c++ code) are wrapped behind a common managed
> c++ proxy interface. I couldn't manage to see the benefits of just
> mocking one of the remote server, as it would not test the real thing.
>=20
> What do you think of mocking the receiver ? Could I do better here ?
> Am I totally wrong somewhere ?
>=20
> thanks in advance
>=20
> Thibaut
>
|
|
From: <thi...@gm...> - 2004-10-14 09:01:56
|
Hi gentlemen,
I'm really new to mock objects, apart from very basic stuff, and would
like to have your opinion about the way I plan to use them.
I am testing interaction with remote servers, and I'm expecting to be
called in one of several callbacks (registered to the server) in my
testfixture to decide that my test has passed. Callbacks, if called,
set an AutoResetEvent. I'm currently testing the behaviour using this
:
AutoResetEvent _connected = new AutoResetEvent(false);
/// <summary>
/// Callback for connect test
/// </summary>
/// <param name="e"></param>
private void Connected(object sender,ConnectionEventArgs e)
{
// mark the event
_connected.Set();
}
....
WaitHandle[] handles = { _accepted,_rejected,_cancelled };
Assert.IsTrue(WaitHandle.WaitAny(handles,5000,true)!=WaitHandle.WaitTimeout,"No
valid callback called.");
I'm thinking about refactoring the callbacks and waitany code inside a
mock object, with some "expectations" that would do what I need. I
would then mock the receiver, not the server.
To give more background, the remote servers (~ 10 different
implementations, native c++ code) are wrapped behind a common managed
c++ proxy interface. I couldn't manage to see the benefits of just
mocking one of the remote server, as it would not test the real thing.
What do you think of mocking the receiver ? Could I do better here ?
Am I totally wrong somewhere ?
thanks in advance
Thibaut
|
|
From: Levi K. <lkh...@us...> - 2004-10-13 18:04:09
|
Update of /cvsroot/nmock/nmock/test/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11257/test/NMock/Proxy Modified Files: MockRealProxyTest.cs Log Message: fixed bug with inherited/explicitly implemented interface methods Index: MockRealProxyTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/Proxy/MockRealProxyTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MockRealProxyTest.cs 13 Oct 2004 15:43:17 -0000 1.1 --- MockRealProxyTest.cs 13 Oct 2004 18:03:57 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- using System; using System.Collections; + using System.IO; using System.Reflection; using System.Reflection.Emit; *************** *** 37,54 **** string AProperty { get; set; } } public struct MyStruct ! { ! public int x; ! } ! class X ! { ! private IMock mock = null; ! string stringReturn() { return (string)mock.Invoke("stringReturn", new object[0]); } ! decimal decimalReturn() { return (decimal)mock.Invoke("decimalReturn", new object[0]); } ! MyStruct structReturn() { return (MyStruct)mock.Invoke("structReturn", new object[0]); } ! } public interface ISolidThingy --- 38,59 ---- string AProperty { get; set; } } + + public interface IDerivedThingy : IThingy + { + } public struct MyStruct ! { ! public int x; ! } ! class X ! { ! private IMock mock = null; ! string stringReturn() { return (string)mock.Invoke("stringReturn", new object[0]); } ! decimal decimalReturn() { return (decimal)mock.Invoke("decimalReturn", new object[0]); } ! MyStruct structReturn() { return (MyStruct)mock.Invoke("structReturn", new object[0]); } ! } public interface ISolidThingy *************** *** 94,97 **** --- 99,117 ---- public virtual void NoArgs() { Assertion.Fail("Should have been overriden"); } } + + public class DerivedThing : ConcreteThing + { + } + + public interface ISimpleThingy + { + void NoArgs(); + } + + public class SimpleThingy : MarshalByRefObject, ISimpleThingy + { + void ISimpleThingy.NoArgs() { Assertion.Fail("Should have been overriden"); } + } + #endregion *************** *** 196,218 **** [Test] ! public void CallMethodWithReturnDecimal() ! { ! decimal d = new decimal(3); ! mock.ExpectAndReturn("decimalReturn", d); ! decimal result = thingy.decimalReturn(); ! Assertion.AssertEquals(new decimal(3), result); ! mock.Verify(); ! } ! [Test] ! public void CallMethodWithStruct() ! { ! MyStruct str = new MyStruct(); ! str.x = 3; ! mock.ExpectAndReturn("structReturn", str); ! MyStruct result = thingy.structReturn(); ! Assertion.AssertEquals(str, result); ! mock.Verify(); ! } [Test] public void CallMethodWithReturnEnum() --- 216,238 ---- [Test] ! public void CallMethodWithReturnDecimal() ! { ! decimal d = new decimal(3); ! mock.ExpectAndReturn("decimalReturn", d); ! decimal result = thingy.decimalReturn(); ! Assertion.AssertEquals(new decimal(3), result); ! mock.Verify(); ! } ! [Test] ! public void CallMethodWithStruct() ! { ! MyStruct str = new MyStruct(); ! str.x = 3; ! mock.ExpectAndReturn("structReturn", str); ! MyStruct result = thingy.structReturn(); ! Assertion.AssertEquals(str, result); ! mock.Verify(); ! } [Test] public void CallMethodWithReturnEnum() *************** *** 224,228 **** } ! [Test] [ExpectedException(typeof(System.IO.IOException))] public void CallMethodTheThrowsException() { mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); --- 244,248 ---- } ! [Test] [ExpectedException(typeof(IOException))] public void CallMethodTheThrowsException() { mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); *************** *** 305,308 **** --- 325,358 ---- } + [Test] public void CallMethodOfImplementedInterface() + { + rp = new MockRealProxy(typeof(SimpleThingy), mock); + ISimpleThingy thingy = (ISimpleThingy)rp.GetTransparentProxy(); + + mock.SetupResult("NonVirtualProperty", "foo"); + thingy.NoArgs(); + mock.Verify(); + } + + [Test] public void CallMethodOfInheritedInterface() + { + rp = new MockRealProxy(typeof(IDerivedThingy), mock); + thingy = (IThingy)rp.GetTransparentProxy(); + + mock.Expect("NoArgs"); + thingy.NoArgs(); + mock.Verify(); + } + + [Test] public void CallMethodOfInheritedClass() + { + rp = new MockRealProxy(typeof(DerivedThing), mock); + DerivedThing derived = (DerivedThing)rp.GetTransparentProxy(); + + mock.Expect("NoArgs"); + derived.NoArgs(); + mock.Verify(); + } + [Test] public void CallReadOnlyProperty() { *************** *** 336,340 **** } ! [Test] public void CanExtendAbstractClass() { rp = new MockRealProxy(typeof(AbstractThingy), mock); --- 386,390 ---- } ! [Test] public void CanProxyAbstractClass() { rp = new MockRealProxy(typeof(AbstractThingy), mock); *************** *** 354,361 **** } ! [Test] public void CanExtendConcreteClass() { ! ConcreteThing concrete = (ConcreteThing) ! (new MockRealProxy(typeof(ConcreteThing), mock)).GetTransparentProxy(); mock.Expect("NoArgs"); --- 404,411 ---- } ! [Test] public void CanProxyConcreteClass() { ! rp = new MockRealProxy(typeof(ConcreteThing), mock); ! ConcreteThing concrete = (ConcreteThing)rp.GetTransparentProxy(); mock.Expect("NoArgs"); |
|
From: Levi K. <lkh...@us...> - 2004-10-13 18:04:08
|
Update of /cvsroot/nmock/nmock/src/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11257/src/NMock/Proxy Modified Files: MockRealProxy.cs Log Message: fixed bug with inherited/explicitly implemented interface methods Index: MockRealProxy.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Proxy/MockRealProxy.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MockRealProxy.cs 13 Oct 2004 15:43:15 -0000 1.3 --- MockRealProxy.cs 13 Oct 2004 18:03:56 -0000 1.4 *************** *** 63,74 **** private Type GetReturnType(IMethodCallMessage call) { ! MethodInfo method = type.GetMethod( ! call.MethodName, (Type[])call.MethodSignature); ! ! if (method == null) ! { ! method = typeof(object).GetMethod( ! call.MethodName, (Type[])call.MethodSignature); ! } return method.ReturnType; } --- 63,67 ---- private Type GetReturnType(IMethodCallMessage call) { ! MethodInfo method = (MethodInfo)call.MethodBase; return method.ReturnType; } |
|
From: Levi K. <lkh...@us...> - 2004-10-13 15:44:38
|
Update of /cvsroot/nmock/nmock/test/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8192/test/NMock/Proxy Added Files: MockRealProxyTest.cs Log Message: fixed bug in proxy mock, added unit tests --- NEW FILE: MockRealProxyTest.cs --- using System; using System.Collections; using System.Reflection; using System.Reflection.Emit; using NUnit.Framework; using NMock; using NMock.Constraints; namespace NMock.Proxy { #region types 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); void WithLongParam(long l); void WithIntParam(int i); object simpleReturn(); string stringReturn(); int intReturn(); bool boolReturn(); double doubleReturn(); decimal decimalReturn(); MyStruct structReturn(); IThingy AThingy(); MyEnum getEnum(); string ReadProperty { get; } string WriteProperty { set; } string AProperty { get; set; } } public struct MyStruct { public int x; } class X { private IMock mock = null; string stringReturn() { return (string)mock.Invoke("stringReturn", new object[0]); } decimal decimalReturn() { return (decimal)mock.Invoke("decimalReturn", new object[0]); } MyStruct structReturn() { return (MyStruct)mock.Invoke("structReturn", new object[0]); } } public interface ISolidThingy { string NonVirtualProperty { get; } } public abstract class AbstractThingy : MarshalByRefObject, ISolidThingy { // internal and protected internal methods must be overridable! public virtual string VirtualMethod() { return "xx"; } public abstract string AbstractMethod(); protected internal virtual string ProtectedInternalMethod() { return "xx"; } // cannot override public static string StaticMethod() { return "xx"; } public string NonVirtualMethod() { return "xx"; } internal string NonVirtualInternalMethod() { return "xx"; } private string privateMethod() { return "xx"; } protected virtual string protectedMethod() { return "xx"; } string defaultInternalMethod() { return "xx"; } public override string ToString() { return "xx"; } // method is ignored // implemented interface members/methods are defined as final (ie. non-virtual) public string NonVirtualProperty { get { return "xx"; } } } public class ClassWithInternalMethod { internal virtual string InternalMethod() { return "xx"; } } public enum MyEnum { A, B, C, D } public class ConcreteThing : MarshalByRefObject { public virtual void NoArgs() { Assertion.Fail("Should have been overriden"); } } #endregion [TestFixture] public class MockRealProxyInvocationHandlerTest { public class InvocationHandlerImpl : IInvocationHandler { public string expectedMethodName; public bool wasCalled = false; public object Invoke(string methodName, params object[] args) { Assertion.AssertEquals("should be method name", expectedMethodName, methodName); Assertion.AssertEquals("Should be no args", 0, args.Length); wasCalled = true; return null; } public bool DelegateToStub(string methodName) { return true; } } [Test] public void CreateRealProxy() { InvocationHandlerImpl handler = new InvocationHandlerImpl(); MockRealProxy rp = new MockRealProxy(typeof(IThingy), handler); IThingy thingy = (IThingy)rp.GetTransparentProxy(); handler.expectedMethodName = "NoArgs"; thingy.NoArgs(); Assertion.Assert("Should have been called ", handler.wasCalled); } } [TestFixture] public class MockRealProxyTest { private MockRealProxy rp; private IMock mock; private IThingy thingy; [SetUp] public void SetUp() { mock = new Mock("Test Mock"); rp = new MockRealProxy(typeof(IThingy), mock); thingy = (IThingy)rp.GetTransparentProxy(); } [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(); Assertion.AssertEquals(x, result); mock.Verify(); } [Test] public void CallMethodWithReturnAndCast() { string x = "sdfs"; mock.ExpectAndReturn("stringReturn", x); string result = thingy.stringReturn(); Assertion.AssertEquals(x, result); mock.Verify(); } [Test] public void CallMethodWithWeirdObjectReturn() { IThingy t = thingy; mock.ExpectAndReturn("AThingy", t); IThingy result = thingy.AThingy(); Assertion.AssertSame(thingy, result); mock.Verify(); } [Test] public void CallMethodWithReturnInt() { mock.ExpectAndReturn("intReturn", 7); int result = thingy.intReturn(); Assertion.AssertEquals(7, result); mock.Verify(); } [Test] public void CallMethodWithReturnBoxings() { mock.ExpectAndReturn("boolReturn", true); mock.ExpectAndReturn("doubleReturn", 1234567891234E+10); Assertion.Assert(thingy.boolReturn()); Assertion.AssertEquals(1234567891234E+10, thingy.doubleReturn()); mock.Verify(); } [Test] public void CallMethodWithReturnDecimal() { decimal d = new decimal(3); mock.ExpectAndReturn("decimalReturn", d); decimal result = thingy.decimalReturn(); Assertion.AssertEquals(new decimal(3), result); mock.Verify(); } [Test] public void CallMethodWithStruct() { MyStruct str = new MyStruct(); str.x = 3; mock.ExpectAndReturn("structReturn", str); MyStruct result = thingy.structReturn(); Assertion.AssertEquals(str, result); mock.Verify(); } [Test] public void CallMethodWithReturnEnum() { mock.ExpectAndReturn("getEnum", MyEnum.C); MyEnum result = thingy.getEnum(); Assertion.AssertEquals(MyEnum.C, result); mock.Verify(); } [Test] [ExpectedException(typeof(System.IO.IOException))] public void CallMethodTheThrowsException() { mock.ExpectAndThrow("boolReturn", new System.IO.IOException()); thingy.boolReturn(); } [Test] public void CallMethodWithStringParameterExpectation() { mock.Expect("WithSimpleArg", new StartsWith("he")); thingy.WithSimpleArg("hello"); mock.Verify(); } [Test] public void CallMethodWithStringParameter() { mock.Expect("WithSimpleArg", "hello"); thingy.WithSimpleArg("hello"); mock.Verify(); } [Test] public void CallMethodWithIntParameter() { mock.Expect("WithIntParam", 1); thingy.WithIntParam(1); mock.Verify(); } [Test] [ExpectedException(typeof(VerifyException))] 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(VerifyException))] 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 CallMethodWithLotsOfArgsExpectations() { 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 CallMethodWithVariableNumberOfParams() { mock.Expect("WithParams", 1, new object[]{"string1", "string2"}); thingy.WithParams(1, "string1", "string2"); mock.Verify(); } [Test] public void CallMethodWithLongParam() { mock.Expect("WithLongParam", 5L); thingy.WithLongParam(5); mock.Verify(); } [Test] public void CallReadOnlyProperty() { mock.ExpectAndReturn("ReadProperty", "hello"); mock.ExpectAndReturn("ReadProperty", "world"); Assertion.AssertEquals("hello", thingy.ReadProperty); Assertion.AssertEquals("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"; Assertion.AssertEquals("good", thingy.AProperty); Assertion.AssertEquals("bye", thingy.AProperty); mock.Verify(); } [Test] public void CanExtendAbstractClass() { rp = new MockRealProxy(typeof(AbstractThingy), mock); AbstractThingy s = (AbstractThingy)rp.GetTransparentProxy(); mock.ExpectAndReturn("VirtualMethod", "hello"); mock.ExpectAndReturn("GetHashCode", 123); mock.ExpectAndReturn("AbstractMethod", "fish"); mock.ExpectAndReturn("ProtectedInternalMethod", "white"); Assertion.AssertEquals("hello", s.VirtualMethod()); Assertion.AssertEquals(123, s.GetHashCode()); Assertion.AssertEquals("fish", s.AbstractMethod()); Assertion.AssertEquals("white", s.ProtectedInternalMethod()); mock.Verify(); } [Test] public void CanExtendConcreteClass() { ConcreteThing concrete = (ConcreteThing) (new MockRealProxy(typeof(ConcreteThing), mock)).GetTransparentProxy(); mock.Expect("NoArgs"); concrete.NoArgs(); mock.Verify(); } [Test] public void CanHandleNonVirtualFeatures() { rp = new MockRealProxy(typeof(AbstractThingy), mock); AbstractThingy s = (AbstractThingy)rp.GetTransparentProxy(); mock.SetupResult("NonVirtualMethod", "non virtual method"); mock.SetupResult("NonVirtualProperty", "non virtual property"); Assertion.AssertEquals("non virtual method", s.NonVirtualMethod()); Assertion.AssertEquals("non virtual property", s.NonVirtualProperty); mock.Verify(); } [Test] public void CanHandleObjectMethodOnInterface() { Assertion.AssertNull(thingy.ToString()); } } } |
|
From: Levi K. <lkh...@us...> - 2004-10-13 15:44:37
|
Update of /cvsroot/nmock/nmock/src/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8192/src/NMock/Proxy Modified Files: MockRealProxy.cs Log Message: fixed bug in proxy mock, added unit tests Index: MockRealProxy.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Proxy/MockRealProxy.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MockRealProxy.cs 24 Aug 2004 21:19:03 -0000 1.2 --- MockRealProxy.cs 13 Oct 2004 15:43:15 -0000 1.3 *************** *** 9,18 **** public class MockRealProxy : RealProxy { ! private readonly IMock mock; private readonly Type type; ! public MockRealProxy(IMock mock, Type type) : base(type) { ! this.mock = mock; this.type = type; } --- 9,18 ---- public class MockRealProxy : RealProxy { ! private readonly IInvocationHandler handler; private readonly Type type; ! public MockRealProxy(Type type, IInvocationHandler handler) : base(type) { ! this.handler = handler; this.type = type; } *************** *** 25,49 **** throw new NotSupportedException("Unsupported call type " + msg.GetType()); } ! if (call.MethodName == "GetType" && call.InArgCount == 0) { return new ReturnMessage(type, null, 0, null, call); } ! return new ReturnMessage(ExecuteCall(call), null, 0, null, call); } ! private object ExecuteCall(IMethodCallMessage call) { string methodName = TypeCheckedMock.StripGetSetPrefix(call.MethodName); ! object result = mock.Invoke(methodName, call.InArgs); if (result == null) { ! MethodInfo method = type.GetMethod(call.MethodName, (Type[])call.MethodSignature); ! if (method.ReturnType.IsValueType) { ! result = Activator.CreateInstance(method.ReturnType); } } return result; } } } --- 25,76 ---- throw new NotSupportedException("Unsupported call type " + msg.GetType()); } ! if (call.MethodName == "GetType" && call.ArgCount == 0) { return new ReturnMessage(type, null, 0, null, call); } ! return ExecuteCall(call); } ! private ReturnMessage ExecuteCall(IMethodCallMessage call) { string methodName = TypeCheckedMock.StripGetSetPrefix(call.MethodName); ! object result; ! try ! { ! result = handler.Invoke(methodName, call.Args); ! } ! catch (Exception e) ! { ! return new ReturnMessage(e, call); ! } ! object returnValue = GetReturnValue(result, call); ! return new ReturnMessage(returnValue, null, 0, null, call); ! } ! ! private object GetReturnValue(object result, IMethodCallMessage call) ! { if (result == null) { ! Type returnType = GetReturnType(call); ! if (returnType.IsValueType) { ! return Activator.CreateInstance(returnType); } } return result; } + + private Type GetReturnType(IMethodCallMessage call) + { + MethodInfo method = type.GetMethod( + call.MethodName, (Type[])call.MethodSignature); + + if (method == null) + { + method = typeof(object).GetMethod( + call.MethodName, (Type[])call.MethodSignature); + } + return method.ReturnType; + } } } |
|
From: Levi K. <lkh...@us...> - 2004-10-13 15:44:37
|
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8192/src/NMock Modified Files: ProxyMock.cs Log Message: fixed bug in proxy mock, added unit tests Index: ProxyMock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/ProxyMock.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProxyMock.cs 24 Aug 2004 21:15:28 -0000 1.1 --- ProxyMock.cs 13 Oct 2004 15:43:15 -0000 1.2 *************** *** 15,19 **** public ProxyMock(Type type, string name) : base(type, name) { ! proxy = new MockRealProxy(this, type); } --- 15,19 ---- public ProxyMock(Type type, string name) : base(type, name) { ! proxy = new MockRealProxy(type, this); } |
|
From: Levi K. <lkh...@us...> - 2004-10-13 15:44:37
|
Update of /cvsroot/nmock/nmock/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8192/test Modified Files: test.csproj Log Message: fixed bug in proxy mock, added unit tests Index: test.csproj =================================================================== RCS file: /cvsroot/nmock/nmock/test/test.csproj,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** test.csproj 24 Aug 2004 21:15:30 -0000 1.11 --- test.csproj 13 Oct 2004 15:43:15 -0000 1.12 *************** *** 160,163 **** --- 160,168 ---- /> <File + RelPath = "NMock\Proxy\MockRealProxyTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\Remoting\MockServerTest.cs" SubType = "Code" |
|
From: Levi K. <lkh...@us...> - 2004-10-13 14:31:07
|
Update of /cvsroot/nmock/nmock/test/NMock/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23183/Proxy Log Message: Directory /cvsroot/nmock/nmock/test/NMock/Proxy added to the repository |
|
From: Owen R. <OR...@th...> - 2004-09-30 04:27:12
|
ah i see... you're looking for a way to inject mocks for acceptance/regression/integration testing... while you can use nmock to accomplish this sort of task, the framework was not designed with this in mind. nmock, like most mocking frameworks is intended to help drive the design of code using unit tests. it is used to design and test the interaction between dependent objects, not for layer-based testing. nat pryce has a very nice blog entry on the subject: http://nat.truemesh.com/archives/000342.html that said, here's one suggestion for how you can use nmock to accomplish your task. if you can avoid having to work with persistent mocks, it will make your life much easier. the challenge is to figure out how to inject in-memory mocks into your code. my recommendation is to try using picocontainer and constructor-based dependency injection; however, this may require a radically change to your architecture. alternately, you can use service locators (which is kind of like what you already have). martin fowler has a nice article describing these two approaches: http://martinfowler.com/articles/injection.html cheers, owen. --- R. Owen Rogers ThoughtWorks Technologies (India) Pvt Ltd. ThoughtWorks - Deliver with passion! ThoughtWorks is always looking for talented people who are passionate about technology. To find out more about a career at ThoughtWorks go to http://www.thoughtworks.com/career/. <vas...@ac...> 29/09/2004 19:40 To: "Owen Rogers" <OR...@th...> cc: <nmo...@li...> Subject: Re: Some clarifications required on NMock Hi Owen, Thanks for the reply. Actually our development code will look like the below one. class XFactory { //.... some code Public X GetXInstance { get { if(InUnitTest) { retyrn return XMock } else { return realX } } } } I hope this will gives the information required. with regds, vasu Owen Rogers <OR...@th... To: Vasu Devan/Internal/Accenture@Accenture m> cc: nmo...@li... Subject: Re: Some clarifications required on NMock 09/29/2004 06:16 PM hi vasu, > Is it possible to save the Mock class generated by Nmock. currently no (at least as far as i understand your question). could you please explain further why you might want to do this? i'm not sure if i understand what you mean by "later time compilation and customization". cheers, owen. ps. in future, please address your queries to the list (nmo...@li...) rather than directly to the maintainers. --- R. Owen Rogers ThoughtWorks Technologies (India) Pvt Ltd. ThoughtWorks - Deliver with passion! ThoughtWorks is always looking for talented people who are passionate about technology. To find out more about a career at ThoughtWorks go to http://www.thoughtworks.com/career/. <vas...@ac...> To: cc: 29/09/2004 18:51 Subject: Some clarifications required on NMock Hi, We have a question on NMock. Is it possible to save the Mock class generated by Nmock. Whether the Mock classes will be available in the disk for later time compilation and customization. Pls give me these answers. with regds, vasu This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. |
|
From: <vas...@ac...> - 2004-09-29 14:09:32
|
Hi Owen,
Thanks for the reply. Actually our development code will look like the
below one.
class XFactory
{
//.... some code
Public X GetXInstance
{
get
{
if(InUnitTest)
{
retyrn return XMock
}
else
{
return realX
}
}
}
}
I hope this will gives the information required.
with regds,
vasu
Owen Rogers
<OR...@th... To: Vasu Devan/Internal/Accenture@Accenture
m> cc: nmo...@li...
Subject: Re: Some clarifications required on NMock
09/29/2004 06:16 PM
hi vasu,
> Is it possible to save the Mock class generated by Nmock.
currently no (at least as far as i understand your question). could you
please explain further why you might want to do this? i'm not sure if i
understand what you mean by "later time compilation and customization".
cheers,
owen.
ps. in future, please address your queries to the list
(nmo...@li...) rather than directly to the
maintainers.
---
R. Owen Rogers
ThoughtWorks Technologies (India) Pvt Ltd.
ThoughtWorks - Deliver with passion!
ThoughtWorks is always looking for talented people who are passionate about
technology. To find out more about a career at ThoughtWorks go to
http://www.thoughtworks.com/career/.
<vas...@ac...>
To:
cc:
29/09/2004 18:51 Subject: Some
clarifications required on NMock
Hi,
We have a question on NMock. Is it possible to save the Mock class
generated by Nmock. Whether the Mock classes will be available in the disk
for later time compilation and customization. Pls give me these answers.
with regds,
vasu
This message is for the designated recipient only and may contain
privileged, proprietary, or otherwise private information. If you have
received it in error, please notify the sender immediately and delete the
original. Any other use of the email by you is prohibited.
This message is for the designated recipient only and may contain
privileged, proprietary, or otherwise private information. If you have
received it in error, please notify the sender immediately and delete the
original. Any other use of the email by you is prohibited.
This message is for the designated recipient only and may contain
privileged, proprietary, or otherwise private information. If you have
received it in error, please notify the sender immediately and delete the
original. Any other use of the email by you is prohibited.
This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited.
|
|
From: Owen R. <OR...@th...> - 2004-09-29 14:01:41
|
hi vasu, > Is it possible to save the Mock class generated by Nmock. currently no (at least as far as i understand your question). could you please explain further why you might want to do this? i'm not sure if i understand what you mean by "later time compilation and customization". cheers, owen. ps. in future, please address your queries to the list (nmo...@li...) rather than directly to the maintainers. --- R. Owen Rogers ThoughtWorks Technologies (India) Pvt Ltd. ThoughtWorks - Deliver with passion! ThoughtWorks is always looking for talented people who are passionate about technology. To find out more about a career at ThoughtWorks go to http://www.thoughtworks.com/career/. <vas...@ac...> 29/09/2004 18:51 To: cc: Subject: Some clarifications required on NMock Hi, We have a question on NMock. Is it possible to save the Mock class generated by Nmock. Whether the Mock classes will be available in the disk for later time compilation and customization. Pls give me these answers. with regds, vasu This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. |
|
From: Owen R. <OR...@th...> - 2004-09-18 13:18:26
|
Mark Seeman from Microsoft Denmark has published an article about NMock on MSDN: http://msdn.microsoft.com/msdnmag/issues/04/10/NMock/default.aspx cheers, owen. --- R. Owen Rogers ThoughtWorks Technologies (India) Pvt Ltd. ThoughtWorks - Deliver with passion! ThoughtWorks is always looking for talented people who are passionate about technology. To find out more about a career at ThoughtWorks go to http://www.thoughtworks.com/career/. |
|
From: Owen R. <OR...@th...> - 2004-09-17 03:53:49
|
hi levi and jim, sorry for the slow response. i only recently got back from trekking in the himalayas :) i finally got around to committing jim's changes -- sorry it took so long. jim: i decided not to rely on the order of the method in the stacktrace to identify ref parameters. instead, i used reflection on the mocked type to match the method/property to be invoked. from that i could determine if the parameter was ref or not. this, however, required doing considerable refactoring of the signature class, which took longer than i had intended. > That reminded me that I should've sent you a message before committing in my stuff :) . don't worry -- no need. you don't need to confirm your changes with me, any more than you need to confirm them with any member of the dev team. as a committer, we trust you to do the right thing -- and, if that screws me because i was slow checking in my changes, then the fault is mine :) > I added the proxy mock primarily to be able to mock service proxies generated web by web references, since they don't have any virtual methods. I think it's going to be useful in many other cases as well, since a lot of potentially mockable types are in fact MarshalByRef as most behavior objects should theoretically be. i was thinking about doing this awhile ago, while playing with contextboundobjects and messagesinks. so, i think it is definitely a useful addition to nmock. as far as mocking web services are concerned, the way that we do it on my current project is to have both the proxy class and the web service class implement the same interface. this allows us to easily inject mocks that implement the interface so that we can stub out the web service. for ATs, this also allows us to bypass the overhead of making a web service call (all the marshalling to soap messages and back again really slows the tests down) by having the client call the web service class directly (we're using StructureMap). > Currently a non-strict mock returns null for all unexpected calls (by the it breaks in dynamic mock when return type is a value type). In many cases this behavior is not quite useful. i agree with your concerns about non-strict mocks. i've found that non-strict mocks can often create/conceal errors in the underlying code. plus, i think that it is pretty ambiguous as to what is meant by "strict" (i keep forgetting :) what i think would be vastly more useful is a mechanism whereby you don't have to explicitly specify the parameters for mocked methods. this feature was there (inadvertently or not) in the nmock 1.0 release, but ended up getting removed/changed subsequent to that. as a result, upgrading from nmock 1.0 to newer versions caused a considerable effort due to the amount of modifications to existing tests. IMO, you should only need to specify parameters if a) you want to verify them (using constraints or otherwise) b) there is are overloaded methods, so you need to specify parameters to indicate which method should have expectations set. i believe that jmock is designed with this approach in mind. so, in summary, i'm not sure about the UnexpectedCallAction enum. my preference would just be to remove the Strict property -- or at the very least change the default behaviour to be non-strict. but i would run it by joe, chris and steve first to see what they had in mind with it. cheers, owen. ps. i think that we should consider making a new nmock release (1.2) soon. any further changes that anyone wants to get in before the release? --- R. Owen Rogers ThoughtWorks Technologies (India) Pvt Ltd. ThoughtWorks - Deliver with passion! ThoughtWorks is always looking for talented people who are passionate about technology. To find out more about a career at ThoughtWorks go to http://www.thoughtworks.com/career/. Levi Khatskevitch 03/09/2004 20:08 To: Owen Rogers/Canada/ThoughtWorks@ThoughtWorks cc: Jim Arnold/UK/ThoughtWorks@ThoughtWorks Subject: NMock ideas Hi Owen, I met Jim Arnold at the TAP workshop in Redmond this week, he mentioned that you are working on merging his recent changes to NMock with mine. That reminded me that I should've sent you a message before committing in my stuff :) . I hope you don't have problems with the changes I made so far. I added the proxy mock primarily to be able to mock service proxies generated web by web references, since they don't have any virtual methods. I think it's going to be useful in many other cases as well, since a lot of potentially mockable types are in fact MarshalByRef as most behavior objects should theoretically be. I'm preparing another check-in with more unit test and a couple of minor bug fixes for the proxy mock that I missed the first time. A bigger change that I am contemplating right now is the following: Currently a non-strict mock returns null for all unexpected calls (by the it breaks in dynamic mock when return type is a value type). In many cases this behavior is not quite useful. For example I was trying to mock a base user control class that provided a couple of virtual methods implemented by several derived user controls. Adding such mock to the controls collection of its parent causes numerous calls to inherited virtual members that are not expected and therefore return null confusing the control collection. A work around would be find ignore all those methods and properties but there's quite a few of making this approach less than perfect, so ended up writing a custom mock with only those methods overridden. Ideally I would like non-strict mocks (dynamic or proxy) to delegate unexpected calls back to the stub (its base in dynamic mock case). However, since as Jim had noticed such a change would affect existing NMock semantics (in particular when the base class method has a side effect) , I'm thinking of a way to make this behavior available on demand rather than by default. I suppose we could add a property of an enumerated type like UnexpectedCallAction that excepts values Ignore, Forbid and DelegateToStub. We could then bind the Strict property to this new one in the following way: Strict returns true only when UnexpectedCallAction is set to Forbid, when Strict is set to false (default) it sets UnexpectedCallAction to Ignore. Here's what I mean: private UnexpectedCallAction unexpectedCallAction; public virtual UnexpectedCallAction UnexpectedCallAction { get { return unexpectedCallAction; } set { unexpectedCallAction = value; } } public virtual bool Strict { get { return unexpectedCallAction == UnexpectedCallAction.Forbid; } set { unexpectedCallAction = value? UnexpectedCallAction.Forbid : UnexpectedCallAction.Ignore; } } Eventually we'd mark the Strict property as obsolete and after that remove it. Using delegation to stub with proxy mock will enable simple hand written stubs (wrapped in proxy mock) emulate sealed types (like SqlCommand) or type with non-virtual members. I'm interested in your feedback before I commit my changes this time. Thank you, - Levi |
|
From: Owen R. <exo...@us...> - 2004-09-17 03:34:09
|
Update of /cvsroot/nmock/nmock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9698 Modified Files: .cvsignore Log Message: - committing jim's changes to add support for mocking methods with ref arguments - refactored signature class to encapsulate methods and properties Index: .cvsignore =================================================================== RCS file: /cvsroot/nmock/nmock/.cvsignore,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** .cvsignore 23 Mar 2004 06:20:17 -0000 1.3 --- .cvsignore 17 Sep 2004 03:33:29 -0000 1.4 *************** *** 5,6 **** --- 5,7 ---- nmock.resharper nmock.resharperoptions + _ReSharper.nmock \ No newline at end of file |
|
From: Owen R. <exo...@us...> - 2004-09-17 03:33:58
|
Update of /cvsroot/nmock/nmock/src/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9698/src/NMock Modified Files: DynamicMock.cs Method.cs Mock.cs MockCall.cs SingleMethod.cs TypeCheckedMock.cs VerifyException.cs Added Files: DefaultSignature.cs ISignature.cs Removed Files: MethodSignature.cs Log Message: - committing jim's changes to add support for mocking methods with ref arguments - refactored signature class to encapsulate methods and properties Index: Method.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Method.cs,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Method.cs 24 Aug 2004 21:15:28 -0000 1.7 --- Method.cs 17 Sep 2004 03:33:46 -0000 1.8 *************** *** 8,16 **** private static object NO_RETURN_VALUE = new object(); ! private MethodSignature signature; private int timesCalled = 0; private CallSequence expectations; ! public Method(MethodSignature signature) { this.signature = signature; --- 8,16 ---- private static object NO_RETURN_VALUE = new object(); ! private ISignature signature; private int timesCalled = 0; private CallSequence expectations; ! public Method(ISignature signature) { this.signature = signature; *************** *** 28,32 **** } ! public virtual void SetExpectation(MockCall aCall) { expectations.Add(aCall); --- 28,32 ---- } ! public virtual void SetExpectation(MockCall aCall) { expectations.Add(aCall); *************** *** 40,44 **** } ! public virtual void Verify() { if (expectations.CountExpectedCalls > timesCalled) --- 40,44 ---- } ! public virtual void Verify() { if (expectations.CountExpectedCalls > timesCalled) *************** *** 54,67 **** public class CallSequence { ! private MethodSignature signature; private ArrayList sequence = new ArrayList(); ! public CallSequence(MethodSignature signature) { this.signature = signature; } public MockCall this[int timesCalled] { ! get { if (sequence.Count <= timesCalled) --- 54,68 ---- public class CallSequence { ! private ISignature signature; private ArrayList sequence = new ArrayList(); ! public CallSequence(ISignature signature) { this.signature = signature; } + public MockCall this[int timesCalled] { ! get { if (sequence.Count <= timesCalled) *************** *** 69,76 **** throw VerifyException.TooManyCalls(signature, sequence.Count, timesCalled + 1); } ! return (MockCall)sequence[timesCalled]; } } ! public int Count { get { return sequence.Count; } --- 70,78 ---- throw VerifyException.TooManyCalls(signature, sequence.Count, timesCalled + 1); } ! return (MockCall) sequence[timesCalled]; } } ! ! public int Count { get { return sequence.Count; } *************** *** 79,86 **** public int CountExpectedCalls { ! get { int count = 0; ! foreach (Object mockCall in sequence) { if (! (mockCall is MockNoCall)) --- 81,88 ---- public int CountExpectedCalls { ! get { int count = 0; ! foreach (Object mockCall in sequence) { if (! (mockCall is MockNoCall)) *************** *** 89,97 **** } } ! return count; } } ! public void Add(MockCall aCall) { sequence.Add(aCall); --- 91,99 ---- } } ! return count; } } ! public void Add(MockCall aCall) { sequence.Add(aCall); *************** *** 100,102 **** } ! } --- 102,104 ---- } ! } \ No newline at end of file --- MethodSignature.cs DELETED --- Index: DynamicMock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** DynamicMock.cs 24 Aug 2004 21:15:28 -0000 1.23 --- DynamicMock.cs 17 Sep 2004 03:33:30 -0000 1.24 *************** *** 1,19 **** using System; using System.Collections; - using System.Reflection; - using NMock.Dynamic; namespace NMock { ! public class DynamicMock : TypeCheckedMock { private object mockInstance; private IList ignoredMethodNames; private readonly Type superclassIfTypeIsInterface; - - public DynamicMock(Type type) : this(type, "Mock" + type.Name) {} ! public DynamicMock(Type type, string name) : this (type, name, null) {} public DynamicMock(Type type, string name, Type superclassIfTypeIsInterface) : base(type, name) --- 1,21 ---- using System; using System.Collections; using NMock.Dynamic; namespace NMock { ! public class DynamicMock : TypeCheckedMock { private object mockInstance; private IList ignoredMethodNames; private readonly Type superclassIfTypeIsInterface; ! public DynamicMock(Type type) : this(type, "Mock" + type.Name) ! { ! } ! ! public DynamicMock(Type type, string name) : this(type, name, null) ! { ! } public DynamicMock(Type type, string name, Type superclassIfTypeIsInterface) : base(type, name) *************** *** 25,29 **** public override object MockInstance { ! get { if (mockInstance == null) --- 27,31 ---- public override object MockInstance { ! get { if (mockInstance == null) *************** *** 38,51 **** /// Don't generate mock method for suppied methodName. /// </summary> ! public virtual void Ignore(string methodName) { ignoredMethodNames.Add(methodName); } ! protected override void ValidateMethodInfo(MethodInfo methodInfo) { ! if(!methodInfo.IsVirtual) throw new ArgumentException( ! string.Format("method <{0}> is not virtual", methodInfo.Name)); } --- 40,53 ---- /// Don't generate mock method for suppied methodName. /// </summary> ! public virtual void Ignore(string methodName) { ignoredMethodNames.Add(methodName); } ! protected override void ValidateSignature(ISignature signature) { ! if (!signature.IsVirtual) throw new ArgumentException( ! string.Format("method <{0}> is not virtual", signature)); } *************** *** 55,57 **** } } ! } --- 57,59 ---- } } ! } \ No newline at end of file --- NEW FILE: DefaultSignature.cs --- using System; using System.Text; using NMock.Constraints; namespace NMock { public class DefaultSignature : ISignature { private string typeName; private string methodName; private Type[] argumentTypes; public DefaultSignature(string typeName, string methodName, params Type[] argumentTypes) { this.typeName = typeName; this.methodName = methodName; this.argumentTypes = argumentTypes; } public string TypeName { get { return typeName; } } public string MethodName { get { return methodName; } } public Type[] ArgumentTypes { get { return argumentTypes; } } public Type ReturnType { get { throw new NotImplementedException(); } } public override string ToString() { StringBuilder argumentList = new StringBuilder(); foreach (Type type in ArgumentTypes) { if (argumentList.Length > 0) argumentList.Append(", "); if (typeof(IConstraint).IsAssignableFrom(type)) { argumentList.Append("<constraint>"); } else { argumentList.Append(type.FullName); } } return string.Format("{0}.{1}({2})", TypeName, MethodName, argumentList); } public bool HasAConstraintArgument { get { foreach(Type argType in ArgumentTypes) { if(typeof(IConstraint).IsAssignableFrom(argType)) return true; } return false; } } public bool IsVirtual { get { return false; } } } } Index: VerifyException.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/VerifyException.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** VerifyException.cs 24 Aug 2004 16:00:24 -0000 1.3 --- VerifyException.cs 17 Sep 2004 03:33:46 -0000 1.4 *************** *** 7,30 **** public class VerifyException : Exception { - private string reason; private string expected; private object actual; - ! public VerifyException(MethodSignature signature, string reason) { this.reason = signature + " " + reason; } ! public VerifyException(MethodSignature signature, string reason, ! object expected, object actual) : this(signature, reason) { this.expected = "<" + expected + ">"; this.actual = actual; } ! ! public VerifyException(MethodSignature signature, ! IConstraint constraint, object actual, int index) { reason = string.Format("{0} called with incorrect parameter ({1})", signature, index + 1); --- 7,26 ---- public class VerifyException : Exception { private string reason; private string expected; private object actual; ! public VerifyException(ISignature signature, string reason) { this.reason = signature + " " + reason; } ! public VerifyException(ISignature signature, string reason, object expected, object actual) : this(signature, reason) { this.expected = "<" + expected + ">"; this.actual = actual; } ! ! public VerifyException(ISignature signature, IConstraint constraint, object actual, int index) { reason = string.Format("{0} called with incorrect parameter ({1})", signature, index + 1); *************** *** 32,39 **** this.actual = constraint.ExtractActualValue(actual); } - ! public static VerifyException TooManyCalls(MethodSignature signature, ! int expected, int actual) { if (expected >= actual) --- 28,34 ---- this.actual = constraint.ExtractActualValue(actual); } ! ! public static VerifyException TooManyCalls(ISignature signature, int expected, int actual) { if (expected >= actual) *************** *** 45,50 **** } ! public static VerifyException NotEnoughCalls(MethodSignature signature, ! int expected, int actual) { if (expected <= actual) --- 40,44 ---- } ! public static VerifyException NotEnoughCalls(ISignature signature, int expected, int actual) { if (expected <= actual) *************** *** 52,56 **** throw new ArgumentException("expected <= actual"); } ! string message = (actual == 0)? "never called" : "not called enough times"; return new VerifyException(signature, message, expected, actual); } --- 46,50 ---- throw new ArgumentException("expected <= actual"); } ! string message = (actual == 0) ? "never called" : "not called enough times"; return new VerifyException(signature, message, expected, actual); } *************** *** 61,79 **** get { return reason; } } ! public object Expected { get { return expected; } } ! public object Actual { get { return actual; } } ! public override string Message { ! get ! { StringBuilder message = new StringBuilder(); message.AppendFormat("\n\t{0}", reason); --- 55,73 ---- get { return reason; } } ! public object Expected { get { return expected; } } ! public object Actual { get { return actual; } } ! public override string Message { ! get ! { StringBuilder message = new StringBuilder(); message.AppendFormat("\n\t{0}", reason); *************** *** 87,89 **** } } ! } --- 81,83 ---- } } ! } \ No newline at end of file Index: TypeCheckedMock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/TypeCheckedMock.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TypeCheckedMock.cs 24 Aug 2004 21:15:28 -0000 1.1 --- TypeCheckedMock.cs 17 Sep 2004 03:33:46 -0000 1.2 *************** *** 1,5 **** using System; using System.Reflection; - using NMock.Dynamic; --- 1,4 ---- *************** *** 17,86 **** public Type MockedType { ! get ! { ! return type; ! } } public override void SetupResult(string methodName, object returnVal, params Type[] argTypes) { ! MethodSignature signature = new MethodSignature(Name, methodName, argTypes); CheckReturnTypeIsValid(signature, returnVal); SetupResult(signature, returnVal); } ! protected override IMethod getMethod(MethodSignature signature) { - CheckMethodIsValidIfNoConstraints(signature); return base.getMethod(signature); } ! protected void CheckReturnTypeIsValid(MethodSignature signature, object returnVal) { if (returnVal == null) return; ! if (signature.HasAConstraintArgument) return; ! Type realReturnType = GetReturnTypeForSignature(signature); if (!realReturnType.IsAssignableFrom(returnVal.GetType())) { throw new ArgumentException( string.Format("method <{0}> should return a {1}", ! signature, realReturnType)); ! } ! } ! ! protected void CheckMethodIsValidIfNoConstraints(MethodSignature signature) ! { ! if (signature.HasAConstraintArgument) ! return; ! ! GetReturnTypeForSignature(signature); ! } ! ! protected Type GetReturnTypeForSignature(MethodSignature signature) ! { ! foreach (Type t in new InterfaceLister().List(MockedType)) ! { ! MethodInfo method = FindMatchingMethodIn(signature, t); ! if (method != null) ! return method.ReturnType; ! ! PropertyInfo property = FindMatchingPropertyOn(signature, t); ! if (property != null) ! return property.PropertyType; } - - throw new MissingMethodException( - string.Format("method <{0}> not defined", signature)); } ! ! internal static string StripGetSetPrefix(string methodName) { ! if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) { methodName = methodName.Substring(4); --- 16,61 ---- public Type MockedType { ! get { return type; } } public override void SetupResult(string methodName, object returnVal, params Type[] argTypes) { ! ISignature signature = CreateMethodSignature(methodName, argTypes); CheckReturnTypeIsValid(signature, returnVal); SetupResult(signature, returnVal); } + protected override ISignature CreateMethodSignature(string methodName, Type[] args) + { + ISignature signature = new SignatureFactory(MockedType).CreateMethodSignature(methodName, args); + ValidateSignature(signature); + return signature; + } ! protected override IMethod getMethod(ISignature signature) { return base.getMethod(signature); } ! protected void CheckReturnTypeIsValid(ISignature signature, object returnVal) { if (returnVal == null) return; ! if (signature.HasAConstraintArgument) return; ! Type realReturnType = signature.ReturnType; if (!realReturnType.IsAssignableFrom(returnVal.GetType())) { throw new ArgumentException( string.Format("method <{0}> should return a {1}", ! signature, realReturnType)); } } ! internal static string StripGetSetPrefix(string methodName) { ! if (methodName.StartsWith("get_") || methodName.StartsWith("set_")) { methodName = methodName.Substring(4); *************** *** 90,164 **** } ! ! private PropertyInfo FindMatchingPropertyOn(MethodSignature signature, Type type) ! { ! return type.GetProperty( ! signature.MethodName, ClassGenerator.ALL_INSTANCE_METHODS); ! } ! ! private MethodInfo FindMatchingMethodIn(MethodSignature signature, Type type) ! { ! foreach (MethodInfo methodInfo in type.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS)) ! { ! if (MatchesNameAndAllNonNullArguments(signature, methodInfo)) ! { ! return methodInfo; ! } ! } ! return null; ! } ! ! private bool IsPropertyOn(MethodSignature signature, Type type) ! { ! return type.GetProperty(signature.MethodName, ! ClassGenerator.ALL_INSTANCE_METHODS) != null; ! } ! ! private bool HasMatchingMethodIn(MethodSignature signature, Type type) ! { ! foreach (MethodInfo methodInfo in type.GetMethods(ClassGenerator.ALL_INSTANCE_METHODS)) ! { ! if (MatchesNameAndAllNonNullArguments(signature, methodInfo)) ! { ! return true; ! } ! } ! return false; ! } ! ! private bool MatchesNameAndAllNonNullArguments(MethodSignature signature, MethodInfo methodInfo) ! { ! if (!signature.MethodName.Equals(methodInfo.Name)) ! return false; ! ! if (! MatchNonNullArguments(signature, methodInfo.GetParameters())) ! return false; ! ! ValidateMethodInfo(methodInfo); ! return true; ! } ! ! private bool MatchNonNullArguments(MethodSignature signature, ParameterInfo[] parameters) ! { ! if ( signature.ArgumentTypes.Length != parameters.Length ) ! return false; ! ! for ( int pi=0; pi<parameters.Length; pi++ ) ! { ! Type argumentType = signature.ArgumentTypes[pi]; ! if (argumentType == null) ! continue; ! ! Type parameterType = parameters[pi].ParameterType; ! if (!parameterType.IsAssignableFrom(argumentType)) ! return false; ! } ! return true; ! } ! ! ! protected virtual void ValidateMethodInfo(MethodInfo methodInfo) { } } ! } --- 65,71 ---- } ! protected virtual void ValidateSignature(ISignature signature) { } } ! } \ No newline at end of file Index: SingleMethod.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/SingleMethod.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SingleMethod.cs 24 Aug 2004 21:15:28 -0000 1.4 --- SingleMethod.cs 17 Sep 2004 03:33:46 -0000 1.5 *************** *** 6,14 **** public class SingleMethod : IMethod { ! private MethodSignature signature; private MockCall expectation; private int timesCalled = 0; ! public SingleMethod(MethodSignature signature) { this.signature = signature; --- 6,14 ---- public class SingleMethod : IMethod { ! private DefaultSignature signature; private MockCall expectation; private int timesCalled = 0; ! public SingleMethod(DefaultSignature signature) { this.signature = signature; Index: MockCall.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/MockCall.cs,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** MockCall.cs 24 Aug 2004 21:15:28 -0000 1.9 --- MockCall.cs 17 Sep 2004 03:33:46 -0000 1.10 *************** *** 1,3 **** --- 1,4 ---- using System; + using System.Reflection; using NMock.Constraints; *************** *** 6,15 **** public class MockCall { ! protected MethodSignature signature; private IConstraint[] expectedArgs; private object returnValue; private Exception e; ! public MockCall(MethodSignature signature, object returnValue, Exception e, object[] expectedArgs) { this.signature = signature; --- 7,16 ---- public class MockCall { ! protected ISignature signature; private IConstraint[] expectedArgs; private object returnValue; private Exception e; ! public MockCall(ISignature signature, object returnValue, Exception e, object[] expectedArgs) { this.signature = signature; *************** *** 53,57 **** public virtual object Call(string methodName, object[] actualArgs) { ! checkArguments(methodName, actualArgs); if (e != null) --- 54,58 ---- public virtual object Call(string methodName, object[] actualArgs) { ! checkArguments(actualArgs); if (e != null) *************** *** 63,67 **** } ! private void checkArguments(string methodName, object[] actualArgs) { if ( HasExpectations ) --- 64,68 ---- } ! private void checkArguments(object[] actualArgs) { if ( HasExpectations ) *************** *** 72,81 **** for (int i = 0; i < expectedArgs.Length; i++) { ! checkConstraint(methodName, expectedArgs[i], actualArgs[i], i); } } } ! private void checkConstraint(string methodName, IConstraint expected, object actual, int index) { if (!expected.Eval(actual)) --- 73,82 ---- for (int i = 0; i < expectedArgs.Length; i++) { ! checkConstraint(expectedArgs[i], actualArgs[i], i); } } } ! private void checkConstraint(IConstraint expected, object actual, int index) { if (!expected.Eval(actual)) *************** *** 107,115 **** return result; } } public class MockNoCall : MockCall { ! public MockNoCall(MethodSignature signature) : base(signature, null, null, null) { } --- 108,129 ---- return result; } + + public static Type[] GetArgTypes(MethodBase method) + { + ParameterInfo[] parameters = method.GetParameters(); + Type[] argTypes = new Type[parameters.Length]; + + for(int i = 0; i < parameters.Length; i++) + { + argTypes[i] = parameters[i].ParameterType; + } + + return argTypes; + } } public class MockNoCall : MockCall { ! public MockNoCall(ISignature signature) : base(signature, null, null, null) { } --- NEW FILE: ISignature.cs --- using System; namespace NMock { public interface ISignature { string TypeName { get; } string MethodName { get; } Type[] ArgumentTypes { get; } Type ReturnType { get; } bool HasAConstraintArgument { get; } bool IsVirtual { get; } } } Index: Mock.cs =================================================================== RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** Mock.cs 26 Aug 2004 10:19:11 -0000 1.17 --- Mock.cs 17 Sep 2004 03:33:46 -0000 1.18 *************** *** 1,8 **** using System; using System.Collections; - using System.Reflection; - using NMock.Constraints; ! namespace NMock { public class Mock : IMock --- 1,6 ---- using System; using System.Collections; ! namespace NMock { public class Mock : IMock *************** *** 12,17 **** private bool strict; protected IDictionary methods; ! ! public Mock(string name) { this.name = name; --- 10,15 ---- private bool strict; protected IDictionary methods; ! ! public Mock(string name) { this.name = name; *************** *** 19,28 **** } ! public virtual string Name { get { return name; } set { name = value; } } ! public virtual object MockInstance { --- 17,26 ---- } ! public virtual string Name { get { return name; } set { name = value; } } ! public virtual object MockInstance { *************** *** 36,41 **** set { strict = value; } } ! ! public virtual void Expect(string methodName, params object[] args) { ExpectAndReturn(methodName, null, args); --- 34,39 ---- set { strict = value; } } ! ! public virtual void Expect(string methodName, params object[] args) { ExpectAndReturn(methodName, null, args); *************** *** 44,65 **** public virtual void ExpectNoCall(string methodName, params Type[] argTypes) { ! addExpectation(methodName, new MockNoCall(new MethodSignature(Name, methodName, argTypes))); } ! public virtual void ExpectAndReturn(string methodName, object result, params object[] args) { ! addExpectation(methodName, ! new MockCall(new MethodSignature(Name, methodName, MockCall.GetArgTypes(args)), result, null, args)); } ! public virtual void ExpectAndThrow(string methodName, Exception e, params object[] args) { ! addExpectation(methodName, ! new MockCall(new MethodSignature(Name, methodName, MockCall.GetArgTypes(args)), null, e, args)); } private void addExpectation(string methodName, MockCall call) { ! MethodSignature signature = new MethodSignature(Name, methodName, call.ArgTypes); IMethod method = getMethod(signature); if (method == null) --- 42,61 ---- public virtual void ExpectNoCall(string methodName, params Type[] argTypes) { ! addExpectation(methodName, new MockNoCall(CreateMethodSignature(methodName, argTypes))); } ! public virtual void ExpectAndReturn(string methodName, object result, params object[] args) { ! addExpectation(methodName, new MockCall(CreateMethodSignature(methodName, MockCall.GetArgTypes(args)), result, null, args)); } ! public virtual void ExpectAndThrow(string methodName, Exception e, params object[] args) { ! addExpectation(methodName, new MockCall(CreateMethodSignature(methodName, MockCall.GetArgTypes(args)), null, e, args)); } private void addExpectation(string methodName, MockCall call) { ! ISignature signature = CreateMethodSignature(methodName, call.ArgTypes); IMethod method = getMethod(signature); if (method == null) *************** *** 70,80 **** method.SetExpectation(call); } ! public virtual void SetupResult(string methodName, object returnVal, params Type[] argTypes) { ! SetupResult(new MethodSignature(Name, methodName, argTypes), returnVal); } ! protected void SetupResult(MethodSignature signature, object returnVal) { IMethod method = getMethod(signature); --- 66,76 ---- method.SetExpectation(call); } ! public virtual void SetupResult(string methodName, object returnVal, params Type[] argTypes) { ! SetupResult(CreateMethodSignature(methodName, argTypes), returnVal); } ! protected void SetupResult(ISignature signature, object returnVal) { IMethod method = getMethod(signature); *************** *** 84,97 **** methods[signature.MethodName] = method; } ! method.SetExpectation(new MockCall(signature, returnVal, null, null)); } ! ! public virtual object Invoke(string methodName, params object[] args) { ! MethodSignature signature = new MethodSignature(Name, methodName, MockCall.GetArgTypes(args)); IMethod method = getMethod(signature); if (method == null) { ! if (strict) { throw VerifyException.TooManyCalls(signature, 0, 1); --- 80,93 ---- methods[signature.MethodName] = method; } ! method.SetExpectation(new MockCall(signature, returnVal, null, null)); } ! ! public virtual object Invoke(string methodName, params object[] args) { ! ISignature signature = CreateMethodSignature(methodName, MockCall.GetArgTypes(args)); IMethod method = getMethod(signature); if (method == null) { ! if (strict) { throw VerifyException.TooManyCalls(signature, 0, 1); *************** *** 102,106 **** } ! public virtual void Verify() { foreach (IMethod method in methods.Values) --- 98,102 ---- } ! public virtual void Verify() { foreach (IMethod method in methods.Values) *************** *** 110,123 **** } ! protected virtual IMethod getMethod(MethodSignature signature) { ! return (IMethod)methods[signature.MethodName]; } ! public class Assertion { ! public static void Assert(MethodSignature signature, string message, bool expression) { ! if (!expression) { throw new VerifyException(signature, message); --- 106,124 ---- } ! protected virtual ISignature CreateMethodSignature(string methodName, Type[] args) { ! return new DefaultSignature(Name, methodName, args); } ! ! protected virtual IMethod getMethod(ISignature signature) ! { ! return (IMethod) methods[signature.MethodName]; ! } ! public class Assertion { ! public static void Assert(DefaultSignature signature, string message, bool expression) { ! if (!expression) { throw new VerifyException(signature, message); *************** *** 125,132 **** } ! public static void AssertEquals(MethodSignature signature, string message, ! object expected, object actual) { ! if (!expected.Equals(actual)) { throw new VerifyException(signature, message, expected, actual); --- 126,132 ---- } ! public static void AssertEquals(ISignature signature, string message, object expected, object actual) { ! if (!expected.Equals(actual)) { throw new VerifyException(signature, message, expected, actual); *************** *** 135,137 **** } } ! } --- 135,137 ---- } } ! } \ No newline at end of file |
|
From: Owen R. <exo...@us...> - 2004-09-17 03:33:57
|
Update of /cvsroot/nmock/nmock/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9698/src Modified Files: src.csproj Log Message: - committing jim's changes to add support for mocking methods with ref arguments - refactored signature class to encapsulate methods and properties Index: src.csproj =================================================================== RCS file: /cvsroot/nmock/nmock/src/src.csproj,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** src.csproj 24 Aug 2004 21:15:28 -0000 1.12 --- src.csproj 17 Sep 2004 03:33:46 -0000 1.13 *************** *** 95,98 **** --- 95,103 ---- /> <File + RelPath = "NMock\DefaultSignature.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\DynamicMock.cs" SubType = "Code" *************** *** 120,134 **** /> <File ! RelPath = "NMock\IVerifiable.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "NMock\Method.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "NMock\MethodSignature.cs" SubType = "Code" BuildAction = "Compile" --- 125,139 ---- /> <File ! RelPath = "NMock\ISignature.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "NMock\IVerifiable.cs" SubType = "Code" BuildAction = "Compile" /> <File ! RelPath = "NMock\Method.cs" SubType = "Code" BuildAction = "Compile" *************** *** 205,208 **** --- 210,218 ---- /> <File + RelPath = "NMock\Dynamic\MethodSignature.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\Dynamic\MockTypeIdentifier.cs" SubType = "Code" *************** *** 215,218 **** --- 225,238 ---- /> <File + RelPath = "NMock\Dynamic\PropertySignature.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File + RelPath = "NMock\Dynamic\SignatureFactory.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "NMock\Proxy\MockRealProxy.cs" SubType = "Code" |
|
From: Owen R. <exo...@us...> - 2004-09-17 03:33:57
|
Update of /cvsroot/nmock/nmock/test/NMock In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9698/test/NMock Modified Files: FastErrorHandlingTest.cs MockTest.cs TypeCheckedMockTest.cs VerifyExceptionTest.cs Log Message: - committing jim's changes to add support for mocking methods with ref arguments - refactored signature class to encapsulate methods and properties Index: TypeCheckedMockTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/TypeCheckedMockTest.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TypeCheckedMockTest.cs 24 Aug 2004 21:15:30 -0000 1.1 --- TypeCheckedMockTest.cs 17 Sep 2004 03:33:47 -0000 1.2 *************** *** 1,8 **** using System; using System.Collections; - using System.Reflection; - using NMock.Constraints; - using NUnit.Framework; --- 1,5 ---- *************** *** 178,181 **** --- 175,230 ---- } + public interface IFoo + { + void MethodWithRefParameter(ref int p); + void MethodWithRefParameter(ref byte p); + void MethodWithRefParameter(ref sbyte p); + void MethodWithRefParameter(ref short p); + void MethodWithRefParameter(ref long p); + void MethodWithRefParameter(ref float p); + void MethodWithRefParameter(ref double p); + void MethodWithRefParameter(ref bool p); + void MethodWithRefParameter(ref ushort p); + void MethodWithRefParameter(ref uint p); + void MethodWithRefParameter(ref ulong p); + void MethodWithRefParameter(ref string p); + void MethodWithRefParameter(ref char p); + } + + [Test] + public void CanMockMembersWithRefParameters() + { + DynamicMock mock = new DynamicMock(typeof(IFoo)); + IFoo foo = (IFoo)mock.MockInstance; + + int INT = int.MaxValue; + string STRING = String.Empty; + bool BOOL = true; + char CHAR = char.MaxValue; + byte BYTE = byte.MaxValue; + double DOUBLE = double.MaxValue; + float FLOAT = float.MaxValue; + short SHORT = short.MaxValue; + long LONG = long.MaxValue; + ushort USHORT = ushort.MaxValue; + uint UINT = uint.MaxValue; + ulong ULONG = ulong.MaxValue; + sbyte SBYTE = sbyte.MaxValue; + + foo.MethodWithRefParameter(ref STRING); + foo.MethodWithRefParameter(ref INT); + foo.MethodWithRefParameter(ref BOOL); + foo.MethodWithRefParameter(ref CHAR); + foo.MethodWithRefParameter(ref BYTE); + foo.MethodWithRefParameter(ref DOUBLE); + foo.MethodWithRefParameter(ref FLOAT); + foo.MethodWithRefParameter(ref SHORT); + foo.MethodWithRefParameter(ref LONG); + foo.MethodWithRefParameter(ref USHORT); + foo.MethodWithRefParameter(ref UINT); + foo.MethodWithRefParameter(ref ULONG); + foo.MethodWithRefParameter(ref SBYTE); + } + [Test] public void CannotYetMockMembersWithOnlyAParamsArgument() { Index: FastErrorHandlingTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/FastErrorHandlingTest.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FastErrorHandlingTest.cs 8 Apr 2004 03:47:41 -0000 1.5 --- FastErrorHandlingTest.cs 17 Sep 2004 03:33:47 -0000 1.6 *************** *** 4,8 **** namespace NMock { - /// <summary> /// looking at the code, I think fixing this for one case (SetupResult or Expect) --- 4,7 ---- *************** *** 93,97 **** } - [Test] [ExpectedException(typeof(MissingMethodException))] --- 92,95 ---- *************** *** 127,135 **** catch(ArgumentException e) { ! AssertEquals("method <Bar> is not virtual", e.Message); } } - } - } --- 125,131 ---- catch(ArgumentException e) { ! AssertEquals("method <MockFull.Bar(System.String)> is not virtual", e.Message); } } } } Index: VerifyExceptionTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/VerifyExceptionTest.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** VerifyExceptionTest.cs 24 Aug 2004 16:00:25 -0000 1.2 --- VerifyExceptionTest.cs 17 Sep 2004 03:33:47 -0000 1.3 *************** *** 9,13 **** public class VerifyExceptionTest { ! private readonly MethodSignature signature = new MethodSignature("Foo", "Bar"); [Test] --- 9,13 ---- public class VerifyExceptionTest { ! private readonly DefaultSignature signature = new DefaultSignature("Foo", "Bar"); [Test] Index: MockTest.cs =================================================================== RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** MockTest.cs 24 Aug 2004 16:00:24 -0000 1.14 --- MockTest.cs 17 Sep 2004 03:33:47 -0000 1.15 *************** *** 437,441 **** { MockCall call = new MockCall( ! new MethodSignature("mymock", "call", new Type[] {typeof(int), typeof(string), typeof(bool[]) }), null, null, new object[] {1, "string", new bool[] {true, false}}); --- 437,441 ---- { MockCall call = new MockCall( ! new DefaultSignature("mymock", "call", new Type[] {typeof(int), typeof(string), typeof(bool[]) }), null, null, new object[] {1, "string", new bool[] {true, false}}); |