Can I “inherit” a delegate? Looking for ways to combine Moq and MSpec without conflicts around It

StackOverflow https://stackoverflow.com/questions/2890032

Question

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.

Was it helpful?

Solution

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top