I have these projects/DLLs:
mylib
project - the project with logic I'm testingmylib_test
project - the nunit test project testingmylib
otherlib.dll
- a 3rd party DLL thatmylib
usesotherlib_mock.dll
- a mock ofotherlib.dll
that I want to use when testing. It contains all the types that are inotherlib.dll
with the same interfaces, except that it always returns mock data instead of actually doing the work thatotherlib.dll
does.
I want that mylib
will use otherlib.dll
in regular operation but when unit tests are run from mylib_test
- otherlib_mock.dll
will be used by mylib
.
Currently, all the types are in the same namespace as otherlib.dll
so if I modify mylib
to reference otherlib_mock.dll
instead of otherlib.dll
- everything works with the mock types. Can somehow do this automatically for testing and not for regular operation?
Option 2 is: I have the code of otherlib_mock.dll
. I could change its namespace to be different than otherlib.dll
and then I could reference them both in mylib
. Now, I toggle between the mocked and non-mocked behavior by switching between the namespaces. Can I put the using
lines in #if
and #else
so that I use the otherlib.dll
namespace in regular operation and the otherlib_mock.dll
namespace when running tests?