When I write unit tests I like to use Rhino Mocks.
So when I started my first Windows Store application I naturally started with my unit tests first. When I tried to add RhinoMocks via NuGet I recieved the following error
Could not install package 'RhinoMocks 3.6.1'. You are trying to install this package into a project that targets '.NETCore,Version=v4.5', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author.
I had the same issue with Moq.
Is there a mocking framework for .NETCor,Version=v4.5?
Here are my suggestions, be aware I haven't tested any of these myself yet. Here is a link to an article discussing the first two options.
Most mocking frameworks are based on
Reflection.Emit
. UnfortunatelyReflection.Emit
isn't in WinRT. This means you can't do dynamic proxies. (I.e. Run-time mocking). This leaves pre-generation of mocks that get referenced at compile-time. The only framework I know of is an experimental branch of Moq: https://github.com/mbrit/moqrtI know the original question is old but there are many of us still out there trying to accomplish mocking in Windows Store Apps.
I have recently started to use MoqaLate which states: Mocking for Windows Phone & Windows Store apps. It actually physically creates the MockingClasses after you Build your solution. So, after build you will have a folder with some Mock implementation of your classes.
I think is not the best option. Run-time mocking will be the ideal but in the meantime it creates the mocks for me.
Actually, Philipp Dolder, one of the contributors to FakeItEasy has come up with an interesting and working approach based on Portable Class Libraries. http://www.planetgeek.ch/2013/02/01/fakeiteasy-and-windows-store-apps-are-becoming-friends/
In essence, he proposes the following solution:
I made this for use with Windows Phone 7, should work with Win 8 as it's just a post build step:
http://dontcodetired.com/blog/post/Introducing-%28probably%29-The-Worlds-Only-Mocking-Framework-for-Windows-Phone-7-%28WP7%29.aspx