Mock IOptions in unit test

The Issue

You wish to unit test using the microsoft options Interface, but how do you inject your configuration class into your test framework?

The solution

var options = Options.Create(new MyConfiguration() { Property = value});

That code will create an IOptions<MyConfiguration> class that you constructed, and now you can pass into the custructor of your _sut (System Under Test)

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.