views:

111

answers:

1

I have started to use MSpec for BDD, and since long ago I use Moq as my mocking framework. However, they both define It, which means I can't have using Moq and using Machine.Specifications in the same code file without having to specify the namespace explicitly each time I use It. Anyone who's used MSpec knows this isn't really an option.

I googled for solutions to this problem, and this blogger mentions having forked MSpec for himself, and implemented paralell support for Given, When, Then.

I'd like to do this, but I can't figure out how to declare for example Given without having to go through the entire framework looking for references to Establish, and changing code there to match that I want either to be OK.

For reference, the Establish, Because and It are declared in the following way:

public delegate void Establish();
public delegate void Because();
public delegate void It();

What I need is to somehow declare Given, so that everywhere the code looks for an Establish, Given is also OK.

+1  A: 

Rather than using fully qualified type names to overcome the clash, you could use "using" to alias the type names, e.g.:

using MadeUpName = System.Windows.Forms.SomeClass;

You can then use MadeUpName without the clash.

MadeUpName obj = new MadeUpName();
chibacity
This is an acceptable workaround at the moment, but it does mean that I have to include the using statements at the top of each spec file. Is there no way I can avoid that?
Tomas Lycken
Not as far as I know. Are you adding your spec files through VS? You may be able to modify the existing VS template to include the boilerplate, in the same way as you get a load of default using imports in the bog standard class template file.
chibacity
I suppose that's good enough. Thanks!
Tomas Lycken
I know the answer was not along the inheriting from delegates lines (can't be done), but the solution does get the job done - no upvote? :)
chibacity