A couple weeks back I threw out a Teaser about a Silverlight AutoMocker... Here's the follow up I promised.
UPDATE: Moq 3.0 released with full Silverlight support http://moq.me/get
I've been working on this off and on for a while now, and finally decided to sit down and finalize (at least this version) of both Moq for Silverlight and an AutoMocking container backed by the Unity IoC from Microsoft.
This isn't by any means "Official", but probably not far from what will be coming out when it's done...
Below are the necessary steps (I can come up with) to get an official version of Moq.
- We need an "Official" build of the Castle.DynamicProxy2 dependency
- Create NAnt build scripts (Jonathon Rossi said he'd try to work on it this weekend 1/23) Thank God! It tried porting the NAnt build to Silverlight and each of the 3 times I got so lost I gave up... :(
- Fix the Castle.Core-Silverlight build (some changes have occurred to the main without being pushed to the Silverlight Version)
- Create an official binaries of
- Port Moq to Silverlight
- I supplied a patch to Daniel a while ago, but he said he wouldn't include it until #1 above.
But until the official versions become available, here are what I have so far!!!
UPDATE: oops, realized I posted the files below as .7z. You can download and install the free open source zip utility here http://www.7-zip.org/
This contains the Moq, Moq-Contrib (w/unity AutoMocker) source
This contains all the binaries you need to run Moq...
Please keep in mind I'm by no means an IoC pro and the whole AutoMocker was a one afternoon attempt at throwing one together that I could use in Silverlight. It's very basic, but seems to support most of what I need for now.
Could an AutoMocking container backed by Moq and Unity be a project that the community needs?
I've been disconnected from the castle dynamic proxy for quite a while. (Last I knew Mr. Rossi was going to get it into the build process) If that's true, building from src would be your best bet. If it's not possible through the NAnt script, then, the way I originally did it, was opening up the Silverlight project in VS and building that way... (I think you have to run the NAnt build at least once for it to setup the AssemblyInfo.cs stuff before you try to vs build)
Hope this helps. (sorry I don't have more info than this)
I'm not sure how to get this into a silverlight version - there doesn't seem to be a Silverlight build. Can you help?
This is really cool...thanks!
I thought you might want to know about an error I received. When mocking an interface containing generic parameter constraints, I receive the error...
System.BadImageFormatException: An attempt was made to load a program with an incorrect format.
...when running the test.
1. Moq-contrib at google code already has an AutoMocker that uses the AutoFac IoC.
2. Take my source, recompile the AutoMocker in .net (make sure to get the correct full-framework dependencies)
Hope that helps...