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
(24) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Jeremy <Je...@Du...> - 2003-09-18 17:34:35
|
I'm perusing the source to learn about design (and to learn about NMock), and noticed this nit: There's a method, DynamicMockTest.CanBeCustomisedByOverridingCallMethod, in which a CustomMock is used, which actually overrides Invoke, not Call. I realize this is minor and was recently changed, but thought you might want to keep the test names in line with the implementation. -Jeremy -- ---------------------------------------------- Profit is a powerful motive. Temper it with morality. http://www.reclaimdemocracy.org/ -- |
|
From: Steve F. <st...@m3...> - 2003-09-18 07:14:34
|
glad you like it. We haven't found this to be a problem yet. I guess the invitable question is have you profiled your tests and found the proportion of time this takes? I suppose it could be done, but you'd have to be careful about making sure that the mock class is regenerated when the original changes. S. Jeremy wrote: > I just discovered NMock, and am darned glad to see it. I'm in the > process of writing some unit tests for code which runs against a > particularly poorly designed 3rd-party interface, and was painfully > implementing some mocks for it. > > But (you knew that was coming) I am concerned with the test run-time > overhead of dynamically generating a mock over a given type. > > I was wondering how difficult it would be to serialize the generated > type into code? I don't see any obvious way to do it, but I thought > I might be missing something. > > I'd like to be able to dynamically generate a mock, then store the > generated mock as code for later use. > > If I had a clue to go about it, I'd submit the feature code myself. > ;) > > Thanks for the great work! I'm quite excited about it. -Jeremy -- "A LISP programmer knows the value of everything but the cost of nothing. A C programmer knows the cost of everything but the value of nothing." (Todd Proebsting) |
|
From: Jeremy <Je...@Du...> - 2003-09-17 21:21:59
|
I just discovered NMock, and am darned glad to see it. I'm in the process of writing some unit tests for code which runs against a particularly poorly designed 3rd-party interface, and was painfully implementing some mocks for it.
But (you knew that was coming) I am concerned with the test run-time overhead of dynamically generating a mock over a given type.
I was wondering how difficult it would be to serialize the generated type into code? I don't see any obvious way to do it, but I thought I might be missing something.
I'd like to be able to dynamically generate a mock, then store the generated mock as code for later use.
If I had a clue to go about it, I'd submit the feature code myself. ;)
Thanks for the great work! I'm quite excited about it.
-Jeremy
--
----------------------------------------------
Profit is a powerful motive. Temper it with morality.
http://www.reclaimdemocracy.org/
--
|
|
From: Vaughn, C. <Va...@va...> - 2003-09-10 15:10:41
|
It seems like there's a problem with 2-d arrays. The following test:
public interface I2darray
{
string [,] TwoDArray { get; }
}
public void TestGet2dArray()
{
IMock foo = new DynamicMock( typeof( I2darray ) );
foo.ExpectAndReturn( "TwoDArray", new string[,] { {
"bob", "bill" } } );
string [,] data =
((I2darray)foo.MockInstance).TwoDArray;
}
...generates this error:
TestCase 'Explorer.Tests.NMockTest.TestGet2dArray' failed: Method
get_TwoDArray in type ProxyI2darray from assembly DynamicProxyAssembly,
Version=0.0.0.0 does not have an implementation.
at System.Reflection.Emit.TypeBuilder.TermCreateClass(TypeToken
handle, Module module)
at System.Reflection.Emit.TypeBuilder.CreateType()
C:\data\projects\NMock\src\Dynamic\ClassGenerator.cs(46,0): at
NMock.Dynamic.ClassGenerator.Generate()
C:\data\projects\NMock\src\DynamicMock.cs(34,0): at
NMock.DynamicMock.get_MockInstance()
c:\data\projects\nmock\tests\clifftest.cs(209,0): at
Explorer.Tests.NMockTest.TestGet2dArray()
Clifton F. Vaughn
Senior Business Analyst
Information Technology
Valassis / IT Division
19975 Victor Parkway Livonia, MI 48152
Tel 734.591.3000 Ext. 16726 Fax 734.632.6151
va...@va...
www.valassis.com
This message may have included proprietary or protected information. This
message and the information contained herein are not to be further
communicated without my express written consent.
|
|
From: Vaughn, C. <Va...@va...> - 2003-09-09 13:01:22
|
I discovered this problem with VB code because you can easily create
properties that take arguments, but I recreated it in C# with an indexer.
Here's a test to reveal the bug:
public interface IDiffIndexers
{
object this[ int index ] { get; }
object this[ int index, int index2 ] { get; }
}
public void TestGetItem()
{
IMock foo = new DynamicMock( typeof( IDiffIndexers )
);
foo.ExpectAndReturn( "Item", "bob", 0 );
Assertion.AssertEquals( "retval", "bob",
((IDiffIndexers)foo.MockInstance)[0] );
}
... and my hack of a fix....
void checkMethodIsValidIfNoConstraints(MethodSignature
signature)
{
foreach(Type argType in signature.argumentTypes)
{
if(typeof(IConstraint).IsAssignableFrom(argType)) return;
}
Type[] allTypes = new InterfaceLister().List(type);
foreach (Type t in allTypes)
{
string [] prefixes = new string[] { "",
"get_", "set_" };
foreach ( string prefix in prefixes )
{
MethodInfo method =
t.GetMethod(prefix + signature.methodName,
ClassGenerator.ALL_INSTANCE_METHODS, null,
signature.argumentTypes,
null);
if(method != null)
{
if(!method.IsVirtual)
{
throw new
ArgumentException(String.Format("method <{0}> is not virtual", signature ));
}
return;
}
}
}
throw new
MissingMethodException(String.Format("method <{0}> not defined", signature
));
}
cliff
Clifton F. Vaughn
Senior Business Analyst
Information Technology
Valassis / IT Division
19975 Victor Parkway Livonia, MI 48152
Tel 734.591.3000 Ext. 16726 Fax 734.632.6151
va...@va...
www.valassis.com
This message may have included proprietary or protected information. This
message and the information contained herein are not to be further
communicated without my express written consent.
|
|
From: Vaughn, C. <Va...@va...> - 2003-08-22 22:50:19
|
Hello, Great job on the work done so far. I really love this stuff. I've noticed a few spots where the class name isn't printed with the method name when there's an error. Check out FastErrorHandlingTest.cs to see what I'm talking about. Again, thanx for all the hard work. Clifton F. Vaughn Senior Business Analyst Information Technology Valassis / IT Division 19975 Victor Parkway Livonia, MI 48152 Tel 734.591.3000 Ext. 16726 Fax 734.632.6151 va...@va... www.valassis.com This message may have included proprietary or protected information. This message and the information contained herein are not to be further communicated without my express written consent. |
|
From: <ma...@us...> - 2003-08-22 09:41:38
|
Update of /cvsroot/nmock/nmock/test/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv26528/test/NMock/Dynamic
Modified Files:
ClassGeneratorTest.cs
Log Message:
Support for struct and decimal
Index: ClassGeneratorTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** ClassGeneratorTest.cs 20 Aug 2003 06:19:29 -0000 1.15
--- ClassGeneratorTest.cs 21 Aug 2003 00:26:16 -0000 1.16
***************
*** 28,31 ****
--- 28,33 ----
bool boolReturn();
double doubleReturn();
+ decimal decimalReturn();
+ MyStruct structReturn();
IThingy AThingy();
MyEnum getEnum();
***************
*** 35,38 ****
--- 37,54 ----
}
+ 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
{
***************
*** 171,174 ****
--- 187,211 ----
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()
|
|
From: Vaughn, C. <Va...@va...> - 2003-08-22 09:20:21
|
Hey Steve,
the problem was that structs were being returned with junk data, but I just
checked out Tim's code and that addressed it.
The other thing I noticed is that the patch that's on the site that
addresses a bug with checking return types in
DynamicMock.checkReturnTypeIsValid doesn't seem to be incorporated in the
CVS source tree. It's a good fix and should be in there.
cliff
>Fixed it last night (in CVS). What's the error you're getting with this
>code?
>S.
Vaughn, Clifton wrote:
> Hey,
>
> I looks like someone beat me to the internal method bug. The only thing I
> can't seem to get working in my code is this test.
>
> public interface IFoo2
> {
> System.Drawing.Color color { get; }
> DateTime date { get; }
> System.Int32 anint { get; }
> System.Object anobj { get; }
> }
>
> public void TestColor()
> {
> IMock foo = new DynamicMock( typeof( IFoo2 ) );
> foo.ExpectAndReturn( "color",
> System.Drawing.Color.Black );
> foo.ExpectAndReturn( "date", DateTime.Now.Date );
> System.Drawing.Color c =
> ((IFoo2)foo.MockInstance).color;
> DateTime d = ((IFoo2)foo.MockInstance).date;
>
> Assertion.AssertEquals( "color",
> System.Drawing.Color.Black, c );
> Assertion.AssertEquals( "date", DateTime.Now.Date, d
> );
> }
>
> I've studied the ClassGenerator, cruised the web, and tried all kinds of
> hacks and I can't get it to work. Can someone please help me out with
this?
>
>
> Clifton F. Vaughn
> Senior Business Analyst
> Information Technology
> Valassis / IT Division
> 19975 Victor Parkway Livonia, MI 48152
> Tel 734.591.3000 Ext. 16726 Fax 734.632.6151
> va...@va...
> www.valassis.com
>
> This message may have included proprietary or protected information. This
> message and the information contained herein are not to be further
> communicated without my express written consent.
>
>
|
|
From: Vaughn, C. <Va...@va...> - 2003-08-22 05:17:12
|
Since I don't see any explicit tests for SetupResult(), can someone tell my why SetupResult() takes variable types instead of objects. cliff Clifton F. Vaughn Senior Business Analyst Information Technology Valassis / IT Division 19975 Victor Parkway Livonia, MI 48152 Tel 734.591.3000 Ext. 16726 Fax 734.632.6151 va...@va... www.valassis.com This message may have included proprietary or protected information. This message and the information contained herein are not to be further communicated without my express written consent. |
|
From: <ma...@us...> - 2003-08-22 04:19:11
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv26528/src/NMock/Dynamic
Modified Files:
ClassGenerator.cs
Log Message:
Support for struct and decimal
Index: ClassGenerator.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/ClassGenerator.cs,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** ClassGenerator.cs 20 Aug 2003 06:19:30 -0000 1.18
--- ClassGenerator.cs 21 Aug 2003 00:26:16 -0000 1.19
***************
*** 192,195 ****
--- 192,201 ----
il.Emit(boxingOpCodes[returnType]);
}
+ else if (returnType.IsValueType)
+ {
+ il.Emit(OpCodes.Unbox, returnType);
+ il.Emit(OpCodes.Ldobj, returnType);
+ }
+
il.DeclareLocal(returnType);
il.Emit(OpCodes.Stloc_1);
|
|
From: Steve F. <st...@m3...> - 2003-08-20 18:09:57
|
Fixed it last night (in CVS). What's the error you're getting with this
code?
S.
Vaughn, Clifton wrote:
> Hey,
>
> I looks like someone beat me to the internal method bug. The only thing I
> can't seem to get working in my code is this test.
>
> public interface IFoo2
> {
> System.Drawing.Color color { get; }
> DateTime date { get; }
> System.Int32 anint { get; }
> System.Object anobj { get; }
> }
>
> public void TestColor()
> {
> IMock foo = new DynamicMock( typeof( IFoo2 ) );
> foo.ExpectAndReturn( "color",
> System.Drawing.Color.Black );
> foo.ExpectAndReturn( "date", DateTime.Now.Date );
> System.Drawing.Color c =
> ((IFoo2)foo.MockInstance).color;
> DateTime d = ((IFoo2)foo.MockInstance).date;
>
> Assertion.AssertEquals( "color",
> System.Drawing.Color.Black, c );
> Assertion.AssertEquals( "date", DateTime.Now.Date, d
> );
> }
>
> I've studied the ClassGenerator, cruised the web, and tried all kinds of
> hacks and I can't get it to work. Can someone please help me out with this?
>
>
> Clifton F. Vaughn
> Senior Business Analyst
> Information Technology
> Valassis / IT Division
> 19975 Victor Parkway Livonia, MI 48152
> Tel 734.591.3000 Ext. 16726 Fax 734.632.6151
> va...@va...
> www.valassis.com
>
> This message may have included proprietary or protected information. This
> message and the information contained herein are not to be further
> communicated without my express written consent.
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by Dice.com.
> Did you know that Dice has over 25,000 tech jobs available today? From
> careers in IT to Engineering to Tech Sales, Dice has tech jobs from the
> best hiring companies. http://www.dice.com/index.epl?rel_code=104
> _______________________________________________
> Nmock-general mailing list
> Nmo...@li...
> https://lists.sourceforge.net/lists/listinfo/nmock-general
--
"A LISP programmer knows the value of everything but the cost of nothing.
A C programmer knows the cost of everything but the value of nothing."
(Todd Proebsting)
|
|
From: Vaughn, C. <Va...@va...> - 2003-08-20 15:42:25
|
Hey,
I looks like someone beat me to the internal method bug. The only thing I
can't seem to get working in my code is this test.
public interface IFoo2
{
System.Drawing.Color color { get; }
DateTime date { get; }
System.Int32 anint { get; }
System.Object anobj { get; }
}
public void TestColor()
{
IMock foo = new DynamicMock( typeof( IFoo2 ) );
foo.ExpectAndReturn( "color",
System.Drawing.Color.Black );
foo.ExpectAndReturn( "date", DateTime.Now.Date );
System.Drawing.Color c =
((IFoo2)foo.MockInstance).color;
DateTime d = ((IFoo2)foo.MockInstance).date;
Assertion.AssertEquals( "color",
System.Drawing.Color.Black, c );
Assertion.AssertEquals( "date", DateTime.Now.Date, d
);
}
I've studied the ClassGenerator, cruised the web, and tried all kinds of
hacks and I can't get it to work. Can someone please help me out with this?
Clifton F. Vaughn
Senior Business Analyst
Information Technology
Valassis / IT Division
19975 Victor Parkway Livonia, MI 48152
Tel 734.591.3000 Ext. 16726 Fax 734.632.6151
va...@va...
www.valassis.com
This message may have included proprietary or protected information. This
message and the information contained herein are not to be further
communicated without my express written consent.
|
|
From: <sm...@us...> - 2003-08-20 07:21:48
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv962/src/NMock/Dynamic
Modified Files:
ClassGenerator.cs
Log Message:
Do not override methods that are only Assembly-accessible
Index: ClassGenerator.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/ClassGenerator.cs,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** ClassGenerator.cs 13 Aug 2003 21:16:30 -0000 1.17
--- ClassGenerator.cs 20 Aug 2003 06:19:30 -0000 1.18
***************
*** 80,88 ****
private bool ShouldImplement(MethodInfo methodInfo)
{
! if (!methodInfo.IsVirtual || methodInfo.IsFinal)
{
methodsToIgnore.Add(methodInfo.Name);
}
! return !methodsToIgnore.Contains(methodInfo.Name);
}
--- 80,88 ----
private bool ShouldImplement(MethodInfo methodInfo)
{
! if ( (! methodInfo.IsVirtual) || methodInfo.IsFinal || methodInfo.IsAssembly)
{
methodsToIgnore.Add(methodInfo.Name);
}
! return ! methodsToIgnore.Contains(methodInfo.Name);
}
|
|
From: <sm...@us...> - 2003-08-20 07:21:47
|
Update of /cvsroot/nmock/nmock/test/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv962/test/NMock/Dynamic
Modified Files:
ClassGeneratorTest.cs
Log Message:
Do not override methods that are only Assembly-accessible
Index: ClassGeneratorTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** ClassGeneratorTest.cs 13 Aug 2003 21:19:58 -0000 1.14
--- ClassGeneratorTest.cs 20 Aug 2003 06:19:29 -0000 1.15
***************
*** 361,369 ****
}
! [Test] [ExpectedException(typeof(TypeLoadException))] public void CannotMockClassWithInternalMethodBecauseOfAssemblyVisibility()
{
! new ClassGenerator(typeof(ClassWithInternalMethod), mock).Generate();
}
-
}
}
--- 361,370 ----
}
! [Test] public void IgnoresInternalMethodsBecauseOfAssemblyVisibility()
{
! ArrayList methodsToIgnore = new ArrayList();
! new ClassGenerator(typeof(ClassWithInternalMethod), mock, methodsToIgnore).Generate();
! Assertion.Assert("Should include InternalMethod", methodsToIgnore.Contains("InternalMethod"));
}
}
}
|
|
From: Joe W. <jo...@tr...> - 2003-08-14 12:39:48
|
Mike Roberts said: > Would anyone like me to setup mail for CruiseControl? One option is to > create 2 mailing lists on the SF project one of which CCNet can send > all build events to, and one of which it can send just 'status change' > events to. If you want to go with this kind of thing, an admin will > need to create the mailing lists. Mike, can you send all events to the main mailing list. If it's too heavy we'll change it later. cheers -joe |
|
From: <sm...@us...> - 2003-08-13 21:23:43
|
Update of /cvsroot/nmock/nmock/test/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv15955/test/NMock
Modified Files:
DynamicMockTest.cs MockTest.cs
Log Message:
Changed Call to Invoke
Index: DynamicMockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/DynamicMockTest.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** DynamicMockTest.cs 8 Aug 2003 00:05:03 -0000 1.14
--- DynamicMockTest.cs 13 Aug 2003 21:19:58 -0000 1.15
***************
*** 24,28 ****
public CustomMock(Type t) : base(t) {}
! public override object Call(string name, params object[] args)
{
return "CUSTOM";
--- 24,28 ----
public CustomMock(Type t) : base(t) {}
! public override object Invoke(string name, params object[] args)
{
return "CUSTOM";
***************
*** 149,153 ****
m2.Expect("y", thingy);
! m2.Call("y", thingy);
m2.Verify();
}
--- 149,153 ----
m2.Expect("y", thingy);
! m2.Invoke("y", thingy);
m2.Verify();
}
***************
*** 160,164 ****
m2.Expect("y", thingy);
! m2.Call("y", "something else");
}
--- 160,164 ----
m2.Expect("y", thingy);
! m2.Invoke("y", "something else");
}
Index: MockTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/MockTest.cs,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** MockTest.cs 13 Aug 2003 19:42:39 -0000 1.10
--- MockTest.cs 13 Aug 2003 21:19:58 -0000 1.11
***************
*** 29,33 ****
{
mock.Expect("myMethod");
! mock.Call("myMethod");
mock.Verify();
}
--- 29,33 ----
{
mock.Expect("myMethod");
! mock.Invoke("myMethod");
mock.Verify();
}
***************
*** 42,52 ****
{
mock.Expect("myMethod");
! mock.Call("myMethod");
! mock.Call("myMethod");
}
[Test] public void IgnoresUnexpectedCalls()
{
! mock.Call("myMethod");
mock.Verify();
}
--- 42,52 ----
{
mock.Expect("myMethod");
! mock.Invoke("myMethod");
! mock.Invoke("myMethod");
}
[Test] public void IgnoresUnexpectedCalls()
{
! mock.Invoke("myMethod");
mock.Verify();
}
***************
*** 57,63 ****
mock.Expect("myMethod");
mock.Expect("myMethod");
! mock.Call("myMethod");
! mock.Call("myMethod");
! mock.Call("myMethod");
mock.Verify();
}
--- 57,63 ----
mock.Expect("myMethod");
mock.Expect("myMethod");
! mock.Invoke("myMethod");
! mock.Invoke("myMethod");
! mock.Invoke("myMethod");
mock.Verify();
}
***************
*** 68,73 ****
mock.Expect("myMethod");
mock.Expect("myMethod");
! mock.Call("myMethod");
! mock.Call("myMethod");
mock.Verify();
}
--- 68,73 ----
mock.Expect("myMethod");
mock.Expect("myMethod");
! mock.Invoke("myMethod");
! mock.Invoke("myMethod");
mock.Verify();
}
***************
*** 76,80 ****
{
mock.Expect("myMethod", new IsEqual("hello"), new IsAnything());
! mock.Call("myMethod", "hello", null);
mock.Verify();
}
--- 76,80 ----
{
mock.Expect("myMethod", new IsEqual("hello"), new IsAnything());
! mock.Invoke("myMethod", "hello", null);
mock.Verify();
}
***************
*** 83,87 ****
{
mock.Expect("myMethod", new IsEqual("hello"), new IsAnything());
! mock.Call("myMethod", "world", null);
}
--- 83,87 ----
{
mock.Expect("myMethod", new IsEqual("hello"), new IsAnything());
! mock.Invoke("myMethod", "world", null);
}
***************
*** 89,93 ****
{
mock.Expect("myMethod");
! mock.Call("myMethod", "world", null);
mock.Verify();
}
--- 89,93 ----
{
mock.Expect("myMethod");
! mock.Invoke("myMethod", "world", null);
mock.Verify();
}
***************
*** 98,104 ****
mock.Expect("myMethod2");
mock.Expect("myMethod3");
! mock.Call("myMethod1");
! mock.Call("myMethod2");
! mock.Call("myMethod3");
mock.Verify();
}
--- 98,104 ----
mock.Expect("myMethod2");
mock.Expect("myMethod3");
! mock.Invoke("myMethod1");
! mock.Invoke("myMethod2");
! mock.Invoke("myMethod3");
mock.Verify();
}
***************
*** 109,115 ****
mock.Expect("myMethod2");
mock.Expect("myMethod3");
! mock.Call("myMethod3");
! mock.Call("myMethod1");
! mock.Call("myMethod2");
mock.Verify();
}
--- 109,115 ----
mock.Expect("myMethod2");
mock.Expect("myMethod3");
! mock.Invoke("myMethod3");
! mock.Invoke("myMethod1");
! mock.Invoke("myMethod2");
mock.Verify();
}
***************
*** 121,128 ****
mock.Expect("myMethod3");
! mock.Call("myMethod2");
! mock.Call("myMethod3");
! mock.Call("myMethod1");
! mock.Call("myMethod3");
mock.Verify();
}
--- 121,128 ----
mock.Expect("myMethod3");
! mock.Invoke("myMethod2");
! mock.Invoke("myMethod3");
! mock.Invoke("myMethod1");
! mock.Invoke("myMethod3");
mock.Verify();
}
***************
*** 132,136 ****
object something = new object();
mock.ExpectAndReturn("myMethod", something);
! object result = mock.Call("myMethod");
mock.Verify();
Assertion.AssertSame(something, result);
--- 132,136 ----
object something = new object();
mock.ExpectAndReturn("myMethod", something);
! object result = mock.Invoke("myMethod");
mock.Verify();
Assertion.AssertSame(something, result);
***************
*** 141,145 ****
object something = new object();
mock.ExpectAndReturn("myMethod", something, new IsEqual("hello"));
! object result = mock.Call("myMethod", "hello");
mock.Verify();
Assertion.AssertSame(something, result);
--- 141,145 ----
object something = new object();
mock.ExpectAndReturn("myMethod", something, new IsEqual("hello"));
! object result = mock.Invoke("myMethod", "hello");
mock.Verify();
Assertion.AssertSame(something, result);
***************
*** 150,154 ****
object something = new object();
mock.ExpectAndReturn("myMethod", something, new IsEqual("hello"));
! object result = mock.Call("myMethod", "bye");
mock.Verify();
Assertion.AssertSame(something, result);
--- 150,154 ----
object something = new object();
mock.ExpectAndReturn("myMethod", something, new IsEqual("hello"));
! object result = mock.Invoke("myMethod", "bye");
mock.Verify();
Assertion.AssertSame(something, result);
***************
*** 163,169 ****
mock.ExpectAndReturn("myMethod", anotherthing);
mock.ExpectAndReturn("myMethod", x);
! Assertion.AssertSame(something, mock.Call("myMethod"));
! Assertion.AssertSame(anotherthing, mock.Call("myMethod"));
! Assertion.AssertEquals(x, mock.Call("myMethod"));
mock.Verify();
}
--- 163,169 ----
mock.ExpectAndReturn("myMethod", anotherthing);
mock.ExpectAndReturn("myMethod", x);
! Assertion.AssertSame(something, mock.Invoke("myMethod"));
! Assertion.AssertSame(anotherthing, mock.Invoke("myMethod"));
! Assertion.AssertEquals(x, mock.Invoke("myMethod"));
mock.Verify();
}
***************
*** 172,176 ****
{
mock.ExpectAndReturn("myMethod", null);
! Assertion.AssertNull(mock.Call("myMethod"));
mock.Verify();
}
--- 172,176 ----
{
mock.ExpectAndReturn("myMethod", null);
! Assertion.AssertNull(mock.Invoke("myMethod"));
mock.Verify();
}
***************
*** 180,184 ****
object o = new object();
mock.Expect("myMethod", o);
! mock.Call("myMethod", o);
}
--- 180,184 ----
object o = new object();
mock.Expect("myMethod", o);
! mock.Invoke("myMethod", o);
}
***************
*** 186,190 ****
{
mock.Expect("myMethod", new object());
! mock.Call("myMethod", new object());
}
--- 186,190 ----
{
mock.Expect("myMethod", new object());
! mock.Invoke("myMethod", new object());
}
***************
*** 194,200 ****
mock.Expect("myMethod", null, "zzz");
mock.Expect("myMethod", "zzz", null);
! mock.Call("myMethod", "???", "???");
! mock.Call("myMethod", "???", "zzz");
! mock.Call("myMethod", "zzz", "???");
}
--- 194,200 ----
mock.Expect("myMethod", null, "zzz");
mock.Expect("myMethod", "zzz", null);
! mock.Invoke("myMethod", "???", "???");
! mock.Invoke("myMethod", "???", "zzz");
! mock.Invoke("myMethod", "zzz", "???");
}
***************
*** 203,219 ****
mock.SetupResult("myMethod", "hello");
mock.SetupResult("anotherMethod", "world");
! Assertion.AssertEquals("hello", mock.Call("myMethod"));
! Assertion.AssertEquals("hello", mock.Call("myMethod"));
! Assertion.AssertEquals("hello", mock.Call("myMethod"));
! Assertion.AssertEquals("hello", mock.Call("myMethod"));
! Assertion.AssertEquals("world", mock.Call("anotherMethod"));
! Assertion.AssertEquals("world", mock.Call("anotherMethod"));
mock.SetupResult("myMethod", "bye");
! Assertion.AssertEquals("bye", mock.Call("myMethod"));
! Assertion.AssertEquals("bye", mock.Call("myMethod"));
! Assertion.AssertEquals("world", mock.Call("anotherMethod"));
mock.SetupResult("myMethod", null);
! Assertion.AssertNull(mock.Call("myMethod"));
! Assertion.AssertNull(mock.Call("myMethod"));
mock.Verify();
}
--- 203,219 ----
mock.SetupResult("myMethod", "hello");
mock.SetupResult("anotherMethod", "world");
! Assertion.AssertEquals("hello", mock.Invoke("myMethod"));
! Assertion.AssertEquals("hello", mock.Invoke("myMethod"));
! Assertion.AssertEquals("hello", mock.Invoke("myMethod"));
! Assertion.AssertEquals("hello", mock.Invoke("myMethod"));
! Assertion.AssertEquals("world", mock.Invoke("anotherMethod"));
! Assertion.AssertEquals("world", mock.Invoke("anotherMethod"));
mock.SetupResult("myMethod", "bye");
! Assertion.AssertEquals("bye", mock.Invoke("myMethod"));
! Assertion.AssertEquals("bye", mock.Invoke("myMethod"));
! Assertion.AssertEquals("world", mock.Invoke("anotherMethod"));
mock.SetupResult("myMethod", null);
! Assertion.AssertNull(mock.Invoke("myMethod"));
! Assertion.AssertNull(mock.Invoke("myMethod"));
mock.Verify();
}
***************
*** 222,226 ****
{
mock.ExpectAndThrow("myMethod", new System.IO.IOException());
! mock.Call("myMethod");
}
--- 222,226 ----
{
mock.ExpectAndThrow("myMethod", new System.IO.IOException());
! mock.Invoke("myMethod");
}
***************
*** 228,232 ****
{
mock.ExpectNoCall("myMethod");
! mock.Call("myMethod");
}
--- 228,232 ----
{
mock.ExpectNoCall("myMethod");
! mock.Invoke("myMethod");
}
***************
*** 243,249 ****
mock.Expect("x");
mock.Expect("y");
! mock.Call("x");
! mock.Call("y");
! mock.Call("z");
}
--- 243,249 ----
mock.Expect("x");
mock.Expect("y");
! mock.Invoke("x");
! mock.Invoke("y");
! mock.Invoke("z");
}
***************
*** 253,257 ****
{
mock.ExpectNoCall("x");
! mock.Call("x");
Fail("Expected VerifyException");
}
--- 253,257 ----
{
mock.ExpectNoCall("x");
! mock.Invoke("x");
Fail("Expected VerifyException");
}
***************
*** 285,290 ****
{
mock.Expect("x");
! mock.Call("x");
! mock.Call("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
--- 285,290 ----
{
mock.Expect("x");
! mock.Invoke("x");
! mock.Invoke("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
***************
*** 321,325 ****
mock.Expect("x");
mock.Expect("x");
! mock.Call("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
--- 321,325 ----
mock.Expect("x");
mock.Expect("x");
! mock.Invoke("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
***************
*** 339,345 ****
mock.Expect("x");
mock.Expect("x");
! mock.Call("x");
! mock.Call("x");
! mock.Call("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
--- 339,345 ----
mock.Expect("x");
mock.Expect("x");
! mock.Invoke("x");
! mock.Invoke("x");
! mock.Invoke("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
***************
*** 360,365 ****
mock.Expect("x");
mock.Expect("x");
! mock.Call("x");
! mock.Call("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
--- 360,365 ----
mock.Expect("x");
mock.Expect("x");
! mock.Invoke("x");
! mock.Invoke("x");
mock.Verify();
Assertion.Fail("Expected VerifyException");
***************
*** 377,382 ****
try
{
! mock.Expect("x", new object[] {1, 2, 3} );
! mock.Call("x", new object[] {2, 3});
Assertion.Fail("Expected VerifyException");
}
--- 377,382 ----
try
{
! mock.Expect("x", 1, 2, 3 );
! mock.Invoke("x", 2, 3 );
Assertion.Fail("Expected VerifyException");
}
***************
*** 398,402 ****
mock.Expect("x", new IsAnything(), (IConstraint)Constraint.MockInstance);
! mock.Call("x", "hello", "world");
Assertion.Fail("Expected VerifyException");
}
--- 398,402 ----
mock.Expect("x", new IsAnything(), (IConstraint)Constraint.MockInstance);
! mock.Invoke("x", "hello", "world");
Assertion.Fail("Expected VerifyException");
}
|
|
From: <sm...@us...> - 2003-08-13 21:23:43
|
Update of /cvsroot/nmock/nmock/test/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv15955/test/NMock/Dynamic
Modified Files:
ClassGeneratorTest.cs
Log Message:
Changed Call to Invoke
Index: ClassGeneratorTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** ClassGeneratorTest.cs 13 Aug 2003 20:44:12 -0000 1.13
--- ClassGeneratorTest.cs 13 Aug 2003 21:19:58 -0000 1.14
***************
*** 82,92 ****
public class InvocationHandlerImpl : IInvocationHandler
{
! public string invokedMethodName;
! public object[] invokedArgs;
! public object Call(string methodName, params object[] args)
{
! invokedMethodName = methodName;
! invokedArgs = args;
return null;
}
--- 82,93 ----
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;
}
***************
*** 98,103 ****
ClassGenerator cg = new ClassGenerator(typeof(IThingy), handler);
IThingy thingy = (IThingy)cg.Generate();
thingy.NoArgs();
! Assertion.AssertEquals("NoArgs", handler.invokedMethodName);
}
}
--- 99,108 ----
ClassGenerator cg = new ClassGenerator(typeof(IThingy), handler);
IThingy thingy = (IThingy)cg.Generate();
+
+ handler.expectedMethodName = "NoArgs";
+
thingy.NoArgs();
!
! Assertion.Assert("Should have been called ", handler.wasCalled);
}
}
|
|
From: <sm...@us...> - 2003-08-13 21:23:42
|
Update of /cvsroot/nmock/nmock/src/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv15955/src/NMock
Modified Files:
Mock.cs IInvocationHandler.cs
Log Message:
Changed Call to Invoke
Index: Mock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Mock.cs,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** Mock.cs 8 Aug 2003 00:05:02 -0000 1.11
--- Mock.cs 13 Aug 2003 21:19:58 -0000 1.12
***************
*** 82,86 ****
}
! public virtual object Call(string methodName, params object[] args)
{
MethodSignature signature = new MethodSignature(Name, methodName, MockCall.GetArgTypes(args));
--- 82,86 ----
}
! public virtual object Invoke(string methodName, params object[] args)
{
MethodSignature signature = new MethodSignature(Name, methodName, MockCall.GetArgTypes(args));
Index: IInvocationHandler.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/IInvocationHandler.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** IInvocationHandler.cs 13 Aug 2003 19:42:39 -0000 1.1
--- IInvocationHandler.cs 13 Aug 2003 21:19:58 -0000 1.2
***************
*** 4,10 ****
{
/// <summary>
! /// Make a call to a mocked up method name to check it meets its expectations.
/// </summary>
! object Call(string methodName, params object[] args);
}
}
--- 4,12 ----
{
/// <summary>
! /// Processes a method invocation on a proxy instance and returns the result.
! /// This method will be invoked on an invocation handler when a method is invoked on a proxy instance
! /// with which the invocation handler is associated.
/// </summary>
! object Invoke(string methodName, params object[] args);
}
}
|
|
From: <sm...@us...> - 2003-08-13 21:16:56
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv15350/src/NMock/Dynamic
Modified Files:
ClassGenerator.cs
Log Message:
Changed Call to Invoke
Index: ClassGenerator.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/ClassGenerator.cs,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** ClassGenerator.cs 13 Aug 2003 20:44:13 -0000 1.16
--- ClassGenerator.cs 13 Aug 2003 21:16:30 -0000 1.17
***************
*** 175,179 ****
private void EmitMethodCall(ILGenerator il)
{
! MethodInfo call = typeof(IInvocationHandler).GetMethod("Call");
il.EmitCall(OpCodes.Callvirt, call, null);
}
--- 175,179 ----
private void EmitMethodCall(ILGenerator il)
{
! MethodInfo call = typeof(IInvocationHandler).GetMethod("Invoke");
il.EmitCall(OpCodes.Callvirt, call, null);
}
|
|
From: <sm...@us...> - 2003-08-13 21:00:34
|
Update of /cvsroot/nmock/nmock/src/NMock/Remoting
In directory sc8-pr-cvs1:/tmp/cvs-serv8466/src/NMock/Remoting
Modified Files:
RemotingMock.cs
Removed Files:
RemotingClassGenerator.cs
Log Message:
Pushed parameters into fields in ClassGenerator
Moved superclassIfTypeIsAnInterface into field
Removed RemotingClasssGenerator
Index: RemotingMock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Remoting/RemotingMock.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RemotingMock.cs 13 Jul 2003 13:27:07 -0000 1.1
--- RemotingMock.cs 13 Aug 2003 20:44:12 -0000 1.2
***************
*** 1,4 ****
--- 1,5 ----
using System;
using NMock.Dynamic;
+ using System.Collections;
namespace NMock.Remoting
***************
*** 6,12 ****
public class RemotingMock : DynamicMock
{
! public RemotingMock(Type type) : base(type)
! {
! }
public MarshalByRefObject MarshalByRefInstance
--- 7,11 ----
public class RemotingMock : DynamicMock
{
! public RemotingMock(Type type) : base(type, "Mock" + type.Name, typeof(MarshalByRefObject)) { }
public MarshalByRefObject MarshalByRefInstance
***************
*** 16,24 ****
return (MarshalByRefObject)MockInstance;
}
- }
-
- protected override ClassGenerator createClassGenerator()
- {
- return new RemotingClassGenerator();
}
}
--- 15,18 ----
--- RemotingClassGenerator.cs DELETED ---
|
|
From: <sm...@us...> - 2003-08-13 21:00:34
|
Update of /cvsroot/nmock/nmock/test/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv8466/test/NMock/Dynamic
Modified Files:
ClassGeneratorTest.cs
Log Message:
Pushed parameters into fields in ClassGenerator
Moved superclassIfTypeIsAnInterface into field
Removed RemotingClasssGenerator
Index: ClassGeneratorTest.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/test/NMock/Dynamic/ClassGeneratorTest.cs,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** ClassGeneratorTest.cs 13 Aug 2003 19:42:37 -0000 1.12
--- ClassGeneratorTest.cs 13 Aug 2003 20:44:12 -0000 1.13
***************
*** 95,101 ****
[Test] public void CreateGenericProxy()
{
- ClassGenerator cg = new ClassGenerator();
InvocationHandlerImpl handler = new InvocationHandlerImpl();
! IThingy thingy = (IThingy)cg.Generate(typeof(IThingy), handler);
thingy.NoArgs();
Assertion.AssertEquals("NoArgs", handler.invokedMethodName);
--- 95,101 ----
[Test] public void CreateGenericProxy()
{
InvocationHandlerImpl handler = new InvocationHandlerImpl();
! ClassGenerator cg = new ClassGenerator(typeof(IThingy), handler);
! IThingy thingy = (IThingy)cg.Generate();
thingy.NoArgs();
Assertion.AssertEquals("NoArgs", handler.invokedMethodName);
***************
*** 111,117 ****
[SetUp] public void SetUp()
{
- cg = new ClassGenerator();
mock = new Mock("Test Mock");
! thingy = (IThingy)cg.Generate(typeof(IThingy), mock);
}
--- 111,117 ----
[SetUp] public void SetUp()
{
mock = new Mock("Test Mock");
! cg = new ClassGenerator(typeof(IThingy), mock);
! thingy = (IThingy)cg.Generate();
}
***************
*** 289,294 ****
[Test] public void CanExtendAbstractClass()
{
! cg = new ClassGenerator();
! AbstractThingy s = (AbstractThingy)cg.Generate(typeof(AbstractThingy), mock);
mock.ExpectAndReturn("VirtualMethod", "hello");
--- 289,294 ----
[Test] public void CanExtendAbstractClass()
{
! cg = new ClassGenerator(typeof(AbstractThingy), mock);
! AbstractThingy s = (AbstractThingy)cg.Generate();
mock.ExpectAndReturn("VirtualMethod", "hello");
***************
*** 324,328 ****
[Test] public void CanExtendConcreteClass()
{
! ConcreteThing concrete = (ConcreteThing)(new ClassGenerator()).Generate(typeof(ConcreteThing), mock);
mock.Expect("NoArgs");
--- 324,328 ----
[Test] public void CanExtendConcreteClass()
{
! ConcreteThing concrete = (ConcreteThing)(new ClassGenerator(typeof(ConcreteThing), mock)).Generate();
mock.Expect("NoArgs");
***************
*** 334,339 ****
[Test] public void CannotOverrideNonVirtualFeatures()
{
! cg = new ClassGenerator();
! AbstractThingy s = (AbstractThingy)cg.Generate(typeof(AbstractThingy), mock);
mock.SetupResult("NonVirtualMethod", "non virtual method");
--- 334,339 ----
[Test] public void CannotOverrideNonVirtualFeatures()
{
! cg = new ClassGenerator(typeof(AbstractThingy), mock);
! AbstractThingy s = (AbstractThingy)cg.Generate();
mock.SetupResult("NonVirtualMethod", "non virtual method");
***************
*** 347,352 ****
[Test] public void DoesNotOverrideToString()
{
! cg = new ClassGenerator();
! AbstractThingy s = (AbstractThingy)cg.Generate(typeof(AbstractThingy), mock);
mock.SetupResult("ToString", "to string");
--- 347,352 ----
[Test] public void DoesNotOverrideToString()
{
! cg = new ClassGenerator(typeof(AbstractThingy), mock);
! AbstractThingy s = (AbstractThingy)cg.Generate();
mock.SetupResult("ToString", "to string");
***************
*** 358,362 ****
[Test] [ExpectedException(typeof(TypeLoadException))] public void CannotMockClassWithInternalMethodBecauseOfAssemblyVisibility()
{
! new ClassGenerator().Generate(typeof(ClassWithInternalMethod), mock);
}
--- 358,362 ----
[Test] [ExpectedException(typeof(TypeLoadException))] public void CannotMockClassWithInternalMethodBecauseOfAssemblyVisibility()
{
! new ClassGenerator(typeof(ClassWithInternalMethod), mock).Generate();
}
|
|
From: <sm...@us...> - 2003-08-13 20:58:32
|
Update of /cvsroot/nmock/nmock/src/NMock
In directory sc8-pr-cvs1:/tmp/cvs-serv8466/src/NMock
Modified Files:
DynamicMock.cs
Log Message:
Pushed parameters into fields in ClassGenerator
Moved superclassIfTypeIsAnInterface into field
Removed RemotingClasssGenerator
Index: DynamicMock.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/DynamicMock.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** DynamicMock.cs 8 Aug 2003 00:05:03 -0000 1.14
--- DynamicMock.cs 13 Aug 2003 20:44:12 -0000 1.15
***************
*** 10,23 ****
{
! private object obj;
private Type type;
private IList ignoredMethodNames;
public DynamicMock(Type type) : this(type, "Mock" + type.Name) {}
! public DynamicMock(Type type, string name) : base(name)
{
this.ignoredMethodNames = new ArrayList();
this.type = type;
}
--- 10,27 ----
{
! private object mockInstance;
private Type type;
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(name)
{
this.ignoredMethodNames = new ArrayList();
this.type = type;
+ this.superclassIfTypeIsInterface = superclassIfTypeIsInterface;
}
***************
*** 26,34 ****
get
{
! if (obj == null)
{
! generate();
}
! return obj;
}
}
--- 30,38 ----
get
{
! if (mockInstance == null)
{
! mockInstance = CreateClassGenerator().Generate();
}
! return mockInstance;
}
}
***************
*** 42,54 ****
}
! private void generate()
! {
! ClassGenerator cg = createClassGenerator();
! obj = cg.Generate(type, this, ignoredMethodNames);
! }
!
! protected virtual ClassGenerator createClassGenerator()
{
! return new ClassGenerator();
}
--- 46,52 ----
}
! private ClassGenerator CreateClassGenerator()
{
! return new ClassGenerator(type, this, ignoredMethodNames, superclassIfTypeIsInterface);
}
|
|
From: <sm...@us...> - 2003-08-13 20:58:31
|
Update of /cvsroot/nmock/nmock/src
In directory sc8-pr-cvs1:/tmp/cvs-serv8466/src
Modified Files:
src.csproj
Log Message:
Pushed parameters into fields in ClassGenerator
Moved superclassIfTypeIsAnInterface into field
Removed RemotingClasssGenerator
Index: src.csproj
===================================================================
RCS file: /cvsroot/nmock/nmock/src/src.csproj,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** src.csproj 13 Aug 2003 19:42:39 -0000 1.7
--- src.csproj 13 Aug 2003 20:44:12 -0000 1.8
***************
*** 185,193 ****
/>
<File
- RelPath = "NMock\Remoting\RemotingClassGenerator.cs"
- SubType = "Code"
- BuildAction = "Compile"
- />
- <File
RelPath = "NMock\Remoting\RemotingMock.cs"
SubType = "Code"
--- 185,188 ----
|
|
From: <sm...@us...> - 2003-08-13 20:58:31
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv8466/src/NMock/Dynamic
Modified Files:
ClassGenerator.cs
Log Message:
Pushed parameters into fields in ClassGenerator
Moved superclassIfTypeIsAnInterface into field
Removed RemotingClasssGenerator
Index: ClassGenerator.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/ClassGenerator.cs,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** ClassGenerator.cs 13 Aug 2003 19:42:39 -0000 1.15
--- ClassGenerator.cs 13 Aug 2003 20:44:13 -0000 1.16
***************
*** 9,37 ****
public class ClassGenerator
{
! public static readonly string INVOCATION_HANDLER_FIELD_NAME = "_invocationHandler";
internal const System.Reflection.BindingFlags ALL_INSTANCE_METHODS
= BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
! public virtual object Generate(Type type, IInvocationHandler handler)
{
! return Generate(type, handler, new ArrayList());
}
! public virtual object Generate(Type type, IInvocationHandler handler, IList methodsToIgnore)
{
methodsToIgnore.Add("Equals");
methodsToIgnore.Add("ToString");
! TypeBuilder typeBuilder = GetTypeBuilder("Proxy" + type.Name, type);
! MethodImplementor methodImplementor = new MethodImplementor(typeBuilder,
! typeBuilder.DefineField(ClassGenerator.INVOCATION_HANDLER_FIELD_NAME,
! typeof(IInvocationHandler), FieldAttributes.Public));
foreach (Type currentType in new InterfaceLister().List(type))
{
foreach ( MethodInfo methodInfo in currentType.GetMethods(ALL_INSTANCE_METHODS) )
{
! if (ShouldImplement(methodInfo, methodsToIgnore))
{
methodImplementor.Implement(methodInfo);
--- 9,74 ----
public class ClassGenerator
{
! public const string INVOCATION_HANDLER_FIELD_NAME = "_invocationHandler";
internal const System.Reflection.BindingFlags ALL_INSTANCE_METHODS
= BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
! readonly protected Type type;
! readonly protected IInvocationHandler handler;
! readonly protected IList methodsToIgnore;
! readonly protected Type superclassIfTypeIsInterface;
!
! public ClassGenerator(Type type, IInvocationHandler handler)
! : this(type, handler, new ArrayList()) {}
!
! public ClassGenerator(Type type, IInvocationHandler handler, IList methodsToIgnore)
! : this(type, handler, methodsToIgnore, null) {}
!
! public ClassGenerator(Type type, IInvocationHandler handler, IList methodsToIgnore, Type superclassIfTypeIsInterface)
{
! this.type = type;
! this.handler = handler;
! this.methodsToIgnore = methodsToIgnore;
! this.superclassIfTypeIsInterface = superclassIfTypeIsInterface;
}
!
! public virtual object Generate()
{
methodsToIgnore.Add("Equals");
methodsToIgnore.Add("ToString");
! TypeBuilder typeBuilder = CreateTypeBuilder();
! MethodImplementor methodImplementor =
! new MethodImplementor(typeBuilder, DefineInvocationHandlerField(typeBuilder));
+ ImplementMethods(methodImplementor);
+ return CreateProxyInstance(typeBuilder.CreateType());
+ }
+
+ TypeBuilder CreateTypeBuilder()
+ {
+ AppDomain appDomain = AppDomain.CurrentDomain;
+ AssemblyName assemblyName = new AssemblyName();
+ assemblyName.Name = "DynamicProxyAssembly";
+ AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
+ ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MockModule");
+ return moduleBuilder.DefineType(ProxyClassName, TypeAttributes.Public, ProxySuperClass, ProxyInterfaces);
+ }
+
+ private FieldBuilder DefineInvocationHandlerField(TypeBuilder typeBuilder)
+ {
+ return typeBuilder.DefineField(
+ ClassGenerator.INVOCATION_HANDLER_FIELD_NAME,
+ typeof(IInvocationHandler), FieldAttributes.Public);
+ }
+
+ private void ImplementMethods(MethodImplementor methodImplementor)
+ {
foreach (Type currentType in new InterfaceLister().List(type))
{
foreach ( MethodInfo methodInfo in currentType.GetMethods(ALL_INSTANCE_METHODS) )
{
! if (ShouldImplement(methodInfo))
{
methodImplementor.Implement(methodInfo);
***************
*** 39,46 ****
}
}
- return CreateProxyInstance(typeBuilder, handler);
}
! bool ShouldImplement(MethodInfo methodInfo, IList methodsToIgnore)
{
if (!methodInfo.IsVirtual || methodInfo.IsFinal)
--- 76,82 ----
}
}
}
! private bool ShouldImplement(MethodInfo methodInfo)
{
if (!methodInfo.IsVirtual || methodInfo.IsFinal)
***************
*** 51,77 ****
}
! TypeBuilder GetTypeBuilder(string name, Type originalType)
! {
! AppDomain appDomain = AppDomain.CurrentDomain;
! AssemblyName assemblyName = new AssemblyName();
! assemblyName.Name = "DynamicProxyAssembly";
! AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
! ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MockModule");
! return moduleBuilder.DefineType(name, TypeAttributes.Public, getSuperClass(originalType), getInterfaces(originalType));
! }
!
! protected virtual Type getSuperClass(Type originalType)
! {
! return (originalType.IsInterface) ? null : originalType;
! }
!
! protected virtual Type[] getInterfaces(Type originalType)
! {
! return (originalType.IsInterface) ? new Type[] { originalType } : new Type[0];
! }
!
! object CreateProxyInstance(TypeBuilder typeBuilder, IInvocationHandler handler)
{
- Type proxyType = typeBuilder.CreateType();
object result = Activator.CreateInstance(proxyType);
--- 87,92 ----
}
! private object CreateProxyInstance(Type proxyType)
{
object result = Activator.CreateInstance(proxyType);
***************
*** 82,85 ****
--- 97,104 ----
}
+ public string ProxyClassName { get { return "Proxy" + type.Name; } }
+ public Type ProxySuperClass { get { return type.IsInterface ? superclassIfTypeIsInterface : type; } }
+ public Type[] ProxyInterfaces { get { return type.IsInterface ? new Type[] { type } : new Type[0]; } }
+
}
|
|
From: <sm...@us...> - 2003-08-13 20:09:04
|
Update of /cvsroot/nmock/nmock/src/NMock/Dynamic
In directory sc8-pr-cvs1:/tmp/cvs-serv30014/src/NMock/Dynamic
Modified Files:
ClassGenerator.cs
Log Message:
Added IInvocationHandler and generalised DynamicProxy generation
(with Jon Tirsen)
Index: ClassGenerator.cs
===================================================================
RCS file: /cvsroot/nmock/nmock/src/NMock/Dynamic/ClassGenerator.cs,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** ClassGenerator.cs 25 Jul 2003 15:52:12 -0000 1.14
--- ClassGenerator.cs 13 Aug 2003 19:42:39 -0000 1.15
***************
*** 9,27 ****
public class ClassGenerator
{
! internal const System.Reflection.BindingFlags ALL_INSTANCE_METHODS
! = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
! public virtual object Generate(Type type, IMock mock)
{
! return Generate(type, mock, new ArrayList());
}
! public virtual object Generate(Type type, IMock mock, IList methodsToIgnore)
{
methodsToIgnore.Add("Equals");
methodsToIgnore.Add("ToString");
! TypeBuilder typeBuilder = GetTypeBuilder("Mock" + type.Name, type);
! MethodImplementor methodImplementor = new MethodImplementor(typeBuilder);
foreach (Type currentType in new InterfaceLister().List(type))
--- 9,31 ----
public class ClassGenerator
{
! public static readonly string INVOCATION_HANDLER_FIELD_NAME = "_invocationHandler";
! internal const System.Reflection.BindingFlags ALL_INSTANCE_METHODS
! = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
!
! public virtual object Generate(Type type, IInvocationHandler handler)
{
! return Generate(type, handler, new ArrayList());
}
! public virtual object Generate(Type type, IInvocationHandler handler, IList methodsToIgnore)
{
methodsToIgnore.Add("Equals");
methodsToIgnore.Add("ToString");
! TypeBuilder typeBuilder = GetTypeBuilder("Proxy" + type.Name, type);
! MethodImplementor methodImplementor = new MethodImplementor(typeBuilder,
! typeBuilder.DefineField(ClassGenerator.INVOCATION_HANDLER_FIELD_NAME,
! typeof(IInvocationHandler), FieldAttributes.Public));
foreach (Type currentType in new InterfaceLister().List(type))
***************
*** 35,44 ****
}
}
! return CreateProxyInstance(typeBuilder, mock);
}
bool ShouldImplement(MethodInfo methodInfo, IList methodsToIgnore)
{
! if (!methodInfo.IsVirtual || methodInfo.IsFinal) {
methodsToIgnore.Add(methodInfo.Name);
}
--- 39,49 ----
}
}
! return CreateProxyInstance(typeBuilder, handler);
}
bool ShouldImplement(MethodInfo methodInfo, IList methodsToIgnore)
{
! if (!methodInfo.IsVirtual || methodInfo.IsFinal)
! {
methodsToIgnore.Add(methodInfo.Name);
}
***************
*** 50,54 ****
AppDomain appDomain = AppDomain.CurrentDomain;
AssemblyName assemblyName = new AssemblyName();
! assemblyName.Name = "DynamicMockAssembly";
AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MockModule");
--- 55,59 ----
AppDomain appDomain = AppDomain.CurrentDomain;
AssemblyName assemblyName = new AssemblyName();
! assemblyName.Name = "DynamicProxyAssembly";
AssemblyBuilder assemblyBuilder = appDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run);
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule("MockModule");
***************
*** 66,233 ****
}
! object CreateProxyInstance(TypeBuilder typeBuilder, IMock mock)
! {
! Type proxyType = typeBuilder.CreateType();
! object result = Activator.CreateInstance(proxyType);
! FieldInfo underlyingMock = proxyType.GetField("underlyingMock");
! underlyingMock.SetValue(result, mock);
! return result;
! }
}
! public class MethodImplementor
! {
! private BoxingOpCodes boxingOpCodes = new BoxingOpCodes();
! private TypeBuilder typeBuilder;
! private FieldBuilder mockFieldBuilder;
! public MethodImplementor(TypeBuilder aTypeBuilder)
! {
! typeBuilder = aTypeBuilder;
! mockFieldBuilder = typeBuilder.DefineField("underlyingMock", typeof(IMock), FieldAttributes.Public);
! }
! public virtual void Implement(MethodInfo methodInfo)
! {
! Type returnType = methodInfo.ReturnType;
! ParameterInfo[] parameterInfo = methodInfo.GetParameters();
! Type[] paramTypes = ExtractParameterTypes(parameterInfo);
! ILGenerator il = CreateILGenerator(methodInfo, returnType, paramTypes);
! EmitMethodSignature(methodInfo, paramTypes, il);
! EmitMethodCall(il);
! EmitMethodReturn(returnType, il);
! }
! private Type[] ExtractParameterTypes(ParameterInfo[] parameters)
! {
! Type[] paramTypes = new Type[parameters.Length];
! for (int i = 0; i < parameters.Length; ++i)
! {
! paramTypes[i] = parameters[i].ParameterType;
! }
! return paramTypes;
! }
! private ILGenerator CreateILGenerator(MethodInfo methodInfo, Type returnType, Type[] paramTypes)
! {
! MethodBuilder methodBuilder =
! typeBuilder.DefineMethod(methodInfo.Name, MethodAttributes.Public | MethodAttributes.Virtual, returnType, paramTypes);
! return methodBuilder.GetILGenerator();
! }
! private void EmitMethodSignature(MethodInfo methodInfo, Type[] paramTypes, ILGenerator il)
! {
il.DeclareLocal( typeof(object) );
! il.Emit(OpCodes.Ldarg_0);
! il.Emit(OpCodes.Ldfld, mockFieldBuilder);
! il.Emit(OpCodes.Ldstr, StripGetSetPrefix(methodInfo));
! il.Emit(OpCodes.Ldc_I4_S, paramTypes.Length);
! il.Emit(OpCodes.Newarr, typeof(object));
! if (paramTypes.Length > 0)
! {
! il.Emit(OpCodes.Stloc_0);
! il.Emit(OpCodes.Ldloc_0);
! for(int i = 0; i < paramTypes.Length; i++)
! {
! il.Emit(OpCodes.Ldc_I4_S, i);
! il.Emit(OpCodes.Ldarg_S, i + 1);
! if (paramTypes[i].IsPrimitive || paramTypes[i].IsValueType)
! {
! il.Emit(OpCodes.Box, paramTypes[i]);
! }
! il.Emit(OpCodes.Stelem_Ref);
! il.Emit(OpCodes.Ldloc_0);
! }
! }
! }
! private void EmitMethodCall(ILGenerator il)
! {
! MethodInfo call = typeof(IMock).GetMethod("Call");
! il.EmitCall(OpCodes.Callvirt, call, null);
! }
! private void EmitMethodReturn(Type returnType, ILGenerator il)
! {
! if (returnType == typeof(void))
! {
! il.Emit(OpCodes.Pop);
! }
! else
! {
! if (returnType.IsPrimitive || returnType.IsEnum)
! {
! il.Emit(OpCodes.Unbox, returnType);
! il.Emit(boxingOpCodes[returnType]);
! }
! il.DeclareLocal(returnType);
! il.Emit(OpCodes.Stloc_1);
! Label l = il.DefineLabel();
! il.Emit(OpCodes.Br_S, l);
! il.MarkLabel(l);
! il.Emit(OpCodes.Ldloc_1);
! }
! il.Emit(OpCodes.Ret);
! }
! private string StripGetSetPrefix(MethodInfo methodInfo)
! {
! string methodName;
! methodName = methodInfo.Name;
! if (methodName.StartsWith("get_") || methodName.StartsWith("set_"))
! {
! methodName = methodName.Substring(4);
! }
! return methodName;
! }
! }
! public class BoxingOpCodes
! {
! private static IDictionary boxingOpCodes;
! public OpCode this[Type aType]
! {
! get
! {
! return GetOpCode(aType);
! }
! }
! private static OpCode GetOpCode( Type aType )
! {
! if (boxingOpCodes == null)
! {
! boxingOpCodes = new Hashtable();
! boxingOpCodes[typeof(sbyte)] = OpCodes.Ldind_I1;
! boxingOpCodes[typeof(short)] = OpCodes.Ldind_I2;
! boxingOpCodes[typeof(int)] = OpCodes.Ldind_I4;
! boxingOpCodes[typeof(long)] = OpCodes.Ldind_I8;
! boxingOpCodes[typeof(byte)] = OpCodes.Ldind_U1;
! boxingOpCodes[typeof(ushort)] = OpCodes.Ldind_U2;
! boxingOpCodes[typeof(uint)] = OpCodes.Ldind_U4;
! boxingOpCodes[typeof(ulong)] = OpCodes.Ldind_I8;
! boxingOpCodes[typeof(float)] = OpCodes.Ldind_R4;
! boxingOpCodes[typeof(double)] = OpCodes.Ldind_R8;
! boxingOpCodes[typeof(char)] = OpCodes.Ldind_U2;
! boxingOpCodes[typeof(bool)] = OpCodes.Ldind_I1;
! }
! if (boxingOpCodes.Contains(aType))
! {
! return (OpCode)boxingOpCodes[aType];
! }
! else
! {
! return OpCodes.Ldind_I1;
! }
! }
! }
}
--- 71,238 ----
}
! object CreateProxyInstance(TypeBuilder typeBuilder, IInvocationHandler handler)
! {
! Type proxyType = typeBuilder.CreateType();
! object result = Activator.CreateInstance(proxyType);
! FieldInfo handlerField = proxyType.GetField(INVOCATION_HANDLER_FIELD_NAME);
! handlerField.SetValue(result, handler);
! return result;
! }
}
! public class MethodImplementor
! {
! private BoxingOpCodes boxingOpCodes = new BoxingOpCodes();
! private TypeBuilder typeBuilder;
! private FieldBuilder handlerFieldBuilder;
! public MethodImplementor(TypeBuilder aTypeBuilder, FieldBuilder handlerFieldBuilder)
! {
! typeBuilder = aTypeBuilder;
! this.handlerFieldBuilder = handlerFieldBuilder;
! }
! public virtual void Implement(MethodInfo methodInfo)
! {
! Type returnType = methodInfo.ReturnType;
! ParameterInfo[] parameterInfo = methodInfo.GetParameters();
! Type[] paramTypes = ExtractParameterTypes(parameterInfo);
! ILGenerator il = CreateILGenerator(methodInfo, returnType, paramTypes);
! EmitMethodSignature(methodInfo, paramTypes, il);
! EmitMethodCall(il);
! EmitMethodReturn(returnType, il);
! }
! private Type[] ExtractParameterTypes(ParameterInfo[] parameters)
! {
! Type[] paramTypes = new Type[parameters.Length];
! for (int i = 0; i < parameters.Length; ++i)
! {
! paramTypes[i] = parameters[i].ParameterType;
! }
! return paramTypes;
! }
! private ILGenerator CreateILGenerator(MethodInfo methodInfo, Type returnType, Type[] paramTypes)
! {
! MethodBuilder methodBuilder =
! typeBuilder.DefineMethod(methodInfo.Name, MethodAttributes.Public | MethodAttributes.Virtual, returnType, paramTypes);
! return methodBuilder.GetILGenerator();
! }
! private void EmitMethodSignature(MethodInfo methodInfo, Type[] paramTypes, ILGenerator il)
! {
il.DeclareLocal( typeof(object) );
! il.Emit(OpCodes.Ldarg_0);
! il.Emit(OpCodes.Ldfld, handlerFieldBuilder);
! il.Emit(OpCodes.Ldstr, StripGetSetPrefix(methodInfo));
! il.Emit(OpCodes.Ldc_I4_S, paramTypes.Length);
! il.Emit(OpCodes.Newarr, typeof(object));
! if (paramTypes.Length > 0)
! {
! il.Emit(OpCodes.Stloc_0);
! il.Emit(OpCodes.Ldloc_0);
! for(int i = 0; i < paramTypes.Length; i++)
! {
! il.Emit(OpCodes.Ldc_I4_S, i);
! il.Emit(OpCodes.Ldarg_S, i + 1);
! if (paramTypes[i].IsPrimitive || paramTypes[i].IsValueType)
! {
! il.Emit(OpCodes.Box, paramTypes[i]);
! }
! il.Emit(OpCodes.Stelem_Ref);
! il.Emit(OpCodes.Ldloc_0);
! }
! }
! }
! private void EmitMethodCall(ILGenerator il)
! {
! MethodInfo call = typeof(IInvocationHandler).GetMethod("Call");
! il.EmitCall(OpCodes.Callvirt, call, null);
! }
! private void EmitMethodReturn(Type returnType, ILGenerator il)
! {
! if (returnType == typeof(void))
! {
! il.Emit(OpCodes.Pop);
! }
! else
! {
! if (returnType.IsPrimitive || returnType.IsEnum)
! {
! il.Emit(OpCodes.Unbox, returnType);
! il.Emit(boxingOpCodes[returnType]);
! }
! il.DeclareLocal(returnType);
! il.Emit(OpCodes.Stloc_1);
! Label l = il.DefineLabel();
! il.Emit(OpCodes.Br_S, l);
! il.MarkLabel(l);
! il.Emit(OpCodes.Ldloc_1);
! }
! il.Emit(OpCodes.Ret);
! }
! private string StripGetSetPrefix(MethodInfo methodInfo)
! {
! string methodName;
! methodName = methodInfo.Name;
! if (methodName.StartsWith("get_") || methodName.StartsWith("set_"))
! {
! methodName = methodName.Substring(4);
! }
! return methodName;
! }
! }
! public class BoxingOpCodes
! {
! private static IDictionary boxingOpCodes;
! public OpCode this[Type aType]
! {
! get
! {
! return GetOpCode(aType);
! }
! }
! private static OpCode GetOpCode( Type aType )
! {
! if (boxingOpCodes == null)
! {
! boxingOpCodes = new Hashtable();
! boxingOpCodes[typeof(sbyte)] = OpCodes.Ldind_I1;
! boxingOpCodes[typeof(short)] = OpCodes.Ldind_I2;
! boxingOpCodes[typeof(int)] = OpCodes.Ldind_I4;
! boxingOpCodes[typeof(long)] = OpCodes.Ldind_I8;
! boxingOpCodes[typeof(byte)] = OpCodes.Ldind_U1;
! boxingOpCodes[typeof(ushort)] = OpCodes.Ldind_U2;
! boxingOpCodes[typeof(uint)] = OpCodes.Ldind_U4;
! boxingOpCodes[typeof(ulong)] = OpCodes.Ldind_I8;
! boxingOpCodes[typeof(float)] = OpCodes.Ldind_R4;
! boxingOpCodes[typeof(double)] = OpCodes.Ldind_R8;
! boxingOpCodes[typeof(char)] = OpCodes.Ldind_U2;
! boxingOpCodes[typeof(bool)] = OpCodes.Ldind_I1;
! }
! if (boxingOpCodes.Contains(aType))
! {
! return (OpCode)boxingOpCodes[aType];
! }
! else
! {
! return OpCodes.Ldind_I1;
! }
! }
! }
}
|