Primitive dependencies

Solved!
Posted in General by Mel Grubb Mon Jan 18 2016 20:57:26 GMT+0000 (UTC)·2·Viewed 385 times

Moq has a way of specifying values for primitive dependencies. Is there any way to explain this to SpecsFor without completely taking over the SUT construction via InitializeClassUnderTest? In my case, I'm mocking out a repository that takes some paging and result limits at construction time. As such, I need to provide an integer to the constructor or face an error like "Int32 limit = Required primitive dependency is not explicitly defined"
Matt Honeycutt
Jan 19, 2016

There is a way to do this, but not with Moq. Instead, you'll configure the auto-mocking container. SpecsFor provides the ConfigureContainer method that you can override for this purpose.

This link is for SM 4.0, but the approach is actually the same with SM 3.0 as well: http://structuremap.github.io/registration/inline-dependencies/

Look for the bit about specifying the argument name.

I hope that helps!


Matt Honeycutt marked this as solved
Markdown is allowed