How to unit test a method which is decorated with an aspect that inject a dependency? #234
-
I've tried to find an answer to this problem in documentation and previous issues here but without any luck. I have an aspect which injects a particular dependency (IDistributedCache) using [IntroduceDependency]-attribute. This aspect is added to a function in a class, in this case called ContentService like this (simplifed example):
Then in my unit test I instantiate an object using a mocked version of ILogger like this (in short):
However this call throws an exception since ContentService now also expects to have IDistributedCache in the constructor. How can I fix this issue? Is it possible to disable the aspect in unit tests, or inject IDistributedCache in some way? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is not yet supported. You need to build your instance using the DI container, i.e. through reflection. |
Beta Was this translation helpful? Give feedback.
It is not yet supported. You need to build your instance using the DI container, i.e. through reflection.