nomad-software/dunit — pull request #12 by chris0210 (2014-02-27 14:58:46+00:00)
Title: Attempt to implement mocking of shared methods/shared objects.

Here is my attempt to implement mocking for ```shared``` methods. The major problem here is that you can only call ```shared``` methods on ```shared``` objects. The current implementation of ```getMock()``` always returns a not ```shared``` object - therefore no ```shared``` method could be called.

It was not possible to do things like that:
```d
static class T
shared void foo();

mixin Mockable!(T);
}

shared auto t = T.getMock(); // doesn't return shared object
t.mockMethod("foo", ...); // shared object can't call unshared method "mockMethod"
```

The solution I present here enables mocking of ```shared``` object by using the ```Mockable``` mixin in the following way:
```d
static class T
// ...

mixin Mockable!(shared T);
}
```

By specifying the ```shared``` qualifier the ```getMock()``` method will return a shared object. All methods of the mock - like ```mockMethod()``` or ```assertMethodCalls``` -will by qualified as ```shared``` and so you can call them.

The only two problems here are:
- overloading shared methods leads to code duplication. I solved this using mixins.
- std.traits doesn't seem to offer a way to determine if a type is shared. I solved this using a hack with stringof()

What's your opinion on this solution?