AutoMoq a concrete dependency
See original GitHub issueHi,
I am trying to use a Moq of a concrete dependency.
[Theory, AutoMoqData]
public async Task Can_register_a_single_service_successfully(
[Frozen] Mock<IdentityServerOptions> identityServerOptions,
ServiceDiscoveryUsingIdentityServer sut
)
{...}
This throws an error where AutoFixture is trying to create a real instance of IdentityServerOptions
to inject into my sut
instead of using the frozen mock.
If I remove the sut and manually create passing in the identityServerOptions.Object
then it all works, so my working theory is that autofixture/automoq is not picking up that the frozen moq can satisfy the dependency and so tries to create a new instance.
I also tried Frozen(Matching.DirectBaseType)
as the proxy generated by moq inherits from the requested value, but still no luck.
Is there any way around this as I can’t change IdentityServerOptions
as it’s 3rd party and have more variables to inject to my sut, which makes the workaround a bit messy when I only need to access the one from my example.
Thanks Euan
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (9 by maintainers)
Top GitHub Comments
Finally had a chance to test it and it works great. I made a minor improvement (I know its still not robust enough for all uses) so that you can still request the concrete object instead of the Mock wrapper.
Allows
@Kralizek yes it might be useful to have it in the AutoMoq lib. I’ll add an issue to the backlog, with a proposal for this feature.