We have a unit test written using Moq.Automocker 3.5.0 which attempts to do the following:
IFoo nullFoo = null;
_automocker.Use<IFoo>(nullFoo)
However, since this change to Moq.Automocker, passing a null to Use is no longer allowed.
Is there another way to deal with a nullable type like this?
For anyone else coming to this question, it looks like the developers of Moq have not included the constraint on all signatures of Use(), so changing the example above to:
Should enable the test again, for clarity, on upgrading an internal project I hit this issue, the test resembled:
This resulted in an exception when running the test:
Changed the test to:
No more exception, test passes, sure someone will argue you don't need to do null check constructor injection this way, but having seen the obscure exceptions you get from AutoFac and even .NET, I'll have a null check.