Moq for Silverlight patch

44 views
Skip to first unread message

Staxxx

unread,
Jan 1, 2009, 6:30:01 PM1/1/09
to moq...@googlegroups.com
Attached is a patch that will give Moq Silverlight support.

It's using the version of the DynamicProxy2 for Silverlight that you can re-create with the latest patch in this email thread... (Not sure when Hammett will get that patch applied, however here's a head start for the Moq project)


Also, I took a quick look at porting the test project, however xunit doesn't have any silverlight support, so I just used microsoft's silvelright unit testing framework... (That's the big TODO on this project. Get the tests supported in the native testing framework)

Any thoughts?

Thanks,
Jason Jarrett
MoqForSilverlight.patch

Daniel Cazzulino

unread,
Jan 1, 2009, 9:24:22 PM1/1/09
to moq...@googlegroups.com
Have been reading your thread in Castle DP. You've been hard at work!

I will try to take a look at this soon. Thanks a lot for your contribution.

>(That's the big TODO on this project. Get the tests supported in the native testing framework)

dunno what you mean by "native" testing framework. there's no such thing as it's not part of .NET and you need a specific version of VS in order to get Microsoft's. In addition, xUnit is much nicer than VSTS still... Don't see this happening anytime soon, I'm afraid... 
--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471

Daniel Cazzulino

unread,
Jan 1, 2009, 9:25:52 PM1/1/09
to moq...@googlegroups.com
also, please let us know when the DP patch you submitted is applied, so that we can sync at that point and incorporate your changes to Moq too into the trunk.

thanks!

Staxxx

unread,
Jan 1, 2009, 9:50:38 PM1/1/09
to moq...@googlegroups.com
I will for sure keep u guys up to date when the DP patch is applied...

Also about the testing framework, I'm not married to any testing framework in particular.  I only did the quick hack port to use the ms test version so I could verify that the tests worked in silverlight. I tried a quick port for xunit to, however there's too much stuff in there to make a clean silverlight version w/out much more work than I wanted to do...

Thanks for taking a look, hoping we all can get this port completed soon...

Staxxx

unread,
Jan 3, 2009, 12:11:40 AM1/3/09
to moq...@googlegroups.com
Hey Daniel,

When Silverlight in Moq is up and running would the Contrib project be interested in an AutoMocker for Silverlight? I wrote a quick one using the new Unity container from MS...

Any thoughts?

Daniel Cazzulino

unread,
Feb 6, 2009, 6:05:45 PM2/6/09
to moq...@googlegroups.com
we have an automocker for the desktop running on Autofac.
have you tried porting autofact to silverlight instead?
maybe there's nothing to port and the binaries "just work" ? :)

/kzu


--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Daniel Cazzulino

unread,
Feb 6, 2009, 6:07:56 PM2/6/09
to moq...@googlegroups.com
btw, do you have a twitter account I could use to ping you if I get into trouble merging this? (about to do it now!)


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Staxxx

unread,
Feb 6, 2009, 6:30:25 PM2/6/09
to moq...@googlegroups.com
Hey Daniel,

Twitter: staxmanade

I have a working version of moq for Silverlight in one of my latest blogs using a trunk version from not too long ago. I know you've been making changes recently and would be nice to sync the Silverlight version with those.

About the automocker, it might be nice to have different container implementations on the contrib project as we don't use autofaq but do use unity. If you give me access I'd be happy to contribute the unity version.

I've heard through the grapevine there is an early beta/port for silverlight of autofaq so I think we could look at having both containers supported in the contrib project.

Any thoughts?

FYI: In the patch there's a block of code in the "Stub" stuff that was a little over my head and I didn't spend much time looking at that I couldn't easily port to silverlight.

Daniel Cazzulino

unread,
Feb 6, 2009, 6:50:20 PM2/6/09
to moq...@googlegroups.com
I always thought about an automocker as a black box that you souldn't need to care about which DI container is under under the covers.

I understand that might be a challenge with explicit registration overrides...

I'll follow up on twitter. Just made you a contributor on moq-contrib. Go ahead with your unity automocker!

thanks!


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Daniel Cazzulino

unread,
Feb 6, 2009, 6:51:23 PM2/6/09
to moq...@googlegroups.com
also, could you attach this patch (if you could sync with the current trunk before, that would be AWESOME, as I've been working quite hard on Moq the last couple weeks) to the corresponding Issue at http://code.google.com/p/moq/issues/detail?id=73 ?


/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


On Thu, Jan 1, 2009 at 9:30 PM, Staxxx <sta...@gmail.com> wrote:

Staxxx

unread,
Feb 7, 2009, 12:58:44 AM2/7/09
to moq...@googlegroups.com
Ok, I got latest on the Moq trunk and applied that to my version of the silverlight build however ran into a couple snags...

1. Indy.IL2CPU.IL.ILReader contains a reference that gives me the following error.

Error 6 'System.Reflection.MethodBody' is inaccessible due to its protection level C:\Code\moq-dev2\moq\Source\IL\ILReader.cs 24 20 Moq.Silverlight

2. I get the following error when I comment the code above that is not compiling.

Error 6 'System.Reflection.Module' does not contain a definition for 'ResolveField' and no extension method 'ResolveField' accepting a first argument of type 'System.Reflection.Module' could be found (are you missing a using directive or an assembly reference?) C:\Code\moq-dev2\moq\Source\IL\ILReader.cs 149 54 Moq.Silverlight


I see that the ILReader was checked in to support issue 130. Maybe we can look at not having that feature in silverlight by wrapping some compiler if/endif's around that? Or is there another way?

Given the above, I also don't have up-to-date tests.

I'd like to leverage the same test .cs files in a different silverlight project that just link back to the original files. However xUnit doesn't exist in silverlight. Jeff Wilcox from Microsoft had a blogpost about how to plug in a ported NUnit to leverage the browsers silverlight testing harness, however I don't want/have time to port xunit like this.

I have an idea, but don't want to put the time unless you're ok with this idea because it would require modifying all the assertions in the main testing project.

One suggestion would be to follow something like this in my blog http://staxmanade.blogspot.com/2009/02/fluent-specification-extensions.html to abstract away the assertions. This way we could have different testing frameworks implementing the assertions (xunit for full framework, Microsoft.Testing.Silverlight for the silverlight version).

Sorry the above email is a little scattered...

Any thoughts?

Daniel Cazzulino

unread,
Feb 7, 2009, 7:53:06 AM2/7/09
to moq...@googlegroups.com
inline

On Sat, Feb 7, 2009 at 3:58 AM, Staxxx <sta...@gmail.com> wrote:
Ok, I got latest on the Moq trunk and applied that to my version of the silverlight build however ran into a couple snags...

1. Indy.IL2CPU.IL.ILReader contains a reference that gives me the following error.

Error 6 'System.Reflection.MethodBody' is inaccessible due to its protection level C:\Code\moq-dev2\moq\Source\IL\ILReader.cs 24 20 Moq.Silverlight

2. I get the following error when I comment the code above that is not compiling.

Error 6 'System.Reflection.Module' does not contain a definition for 'ResolveField' and no extension method 'ResolveField' accepting a first argument of type 'System.Reflection.Module' could be found (are you missing a using directive or an assembly reference?) C:\Code\moq-dev2\moq\Source\IL\ILReader.cs 149 54 Moq.Silverlight


I see that the ILReader was checked in to support issue 130. Maybe we can look at not having that feature in silverlight by wrapping some compiler if/endif's around that? Or is there another way?

yup, I guess there's no way around that. I'd go for a separate project on a separate folder (i..e trunk\Silverlight) which would contain the test project as well as the source project, both linking back to the "main" files. That makes it easier to pinpoint compilation errors during development, rather than just CSC.
 

Given the above, I also don't have up-to-date tests.

I'd like to leverage the same test .cs files in a different silverlight project that just link back to the original files. However xUnit doesn't exist in silverlight. Jeff Wilcox from Microsoft had a blogpost about how to plug in a ported NUnit to leverage the browsers silverlight testing harness, however I don't want/have time to port xunit like this.

will contact Brad Wilson to see if he has plans to do that. I don't think it should be too hard. Between porting all our tests, and porting xUnit, I'd choose porting xUnit any day :)
 

I have an idea, but don't want to put the time unless you're ok with this idea because it would require modifying all the assertions in the main testing project.

One suggestion would be to follow something like this in my blog http://staxmanade.blogspot.com/2009/02/fluent-specification-extensions.html to abstract away the assertions. This way we could have different testing frameworks implementing the assertions (xunit for full framework, Microsoft.Testing.Silverlight for the silverlight version).

the main problem with this is the Assert.Throws<T>(() => methodCall()), which you can hardly emulate with a fluent API...
 

Staxxx

unread,
Feb 7, 2009, 8:35:23 PM2/7/09
to moq...@googlegroups.com
How tough would it be to refactor out the ILReader dependency for silverlight?

Below is an NDepend query showing usage...



Moq  (Sat 07 Feb 16:41 most recent)

SELECT METHODS OUT OF TYPES "Indy.IL2CPU.IL.ILReader" WHERE IsUsing "Indy.IL2CPU.IL.ILReader" ORDER BY DepthOfIsUsing

17 items 

--------------------------------------------------+--------------+
                                                  |DepthOfIsUsing|
methods                                           | "Indy.IL2CPU.|
                                                  |IL.ILReader"  |
--------------------------------------------------+--------------+
Moq.Extensions.GetEvent<TMock>(Action<TMock>)     |1             |
                                                  |              |
Moq.Mock.CreateSetterCall<T1,TCall>(Mock<T1>,Actio|1             |
n<T1>,Func<Mock,Expression,MethodInfo,Expression,T|              |
Call>)                                            |              |
                                                  |              |
Moq.MethodCall.RaisesImpl<TMock>(Action<TMock>,Del|2             |
egate)                                            |              |
                                                  |              |
Moq.Mock<T>.Raise(Action<T>,EventArgs)            |2             |
                                                  |              |
Moq.Mock.VerifySet<T>(Mock<T>,Action<T>,String)   |2             |
                                                  |              |
Moq.Mock.SetupSet<T1>(Mock<T1>,Action<T1>)        |2             |
                                                  |              |
Moq.Mock.SetupSet<T1,TProperty>(Mock<T1>,Action<T1|2             |
>)                                                |              |
                                                  |              |
Moq.MethodCall<TMock>.Raises<T1>(Action<TMock>,Fun|3             |
c<T1,EventArgs>)                                  |              |
                                                  |              |
Moq.MethodCall<TMock>.Raises(Action<TMock>,Func<Ev|3             |
entArgs>)                                         |              |
                                                  |              |
Moq.MethodCall<TMock>.Raises<T1,T2,T3,T4>(Action<T|3             |
Mock>,Func<T1,T2,T3,T4,EventArgs>)                |              |
                                                  |              |
Moq.MethodCall<TMock>.Raises<T1,T2,T3>(Action<TMoc|3             |
k>,Func<T1,T2,T3,EventArgs>)                      |              |
                                                  |              |
Moq.MethodCall<TMock>.Raises<T1,T2>(Action<TMock>,|3             |
Func<T1,T2,EventArgs>)                            |              |
                                                  |              |
Moq.Mock<T>.SetupSet<TProperty>(Action<T>)        |3             |
                                                  |              |
Moq.Mock<T>.SetupSet(Action<T>)                   |3             |
                                                  |              |
Moq.Mock<T>.VerifySet(Action<T>)                  |3             |
                                                  |              |
Moq.Mock<T>.VerifySet(Action<T>,String)           |3             |
                                                  |              |
Moq.MethodCall<TMock>.Raises(Action<TMock>,EventAr|4             |
gs)                                               |              |
                                                  |              |
--------------------------------------------------+--------------+
Sum:                                              |43            |
                                                  |              |
Average:                                          |2.5294        |
                                                  |              |
Minimum:                                          |1             |
                                                  |              |
Maximum:                                          |4             |
                                                  |              |
Standard deviation:                               |0.7759356     |
                                                  |              |
Variance:                                         |0.602076      |
                                                  |              |
--------------------------------------------------+--------------+

Daniel Cazzulino

unread,
Feb 7, 2009, 11:17:58 PM2/7/09
to moq...@googlegroups.com

It would basically mean cutting functionality out :(

/kzu from mobile

On Sat, Feb 7, 2009 at 4:53 AM, Daniel Cazzulino <kzu.net@gmail.com> wrote: > > inline > > On Sat...

--~--~---------~--~----~------------~-------~--~----~ Post: moq...@googlegroups.com Unsubscribe: ...

Reply all
Reply to author
Forward
0 new messages