.NET Core Unit Testing – Mock IOptions

You need to manually create and populate an IOptions<SampleOptions> object. You can do so via the Microsoft.Extensions.Options.Options helper class. For example:

IOptions<SampleOptions> someOptions = Options.Create<SampleOptions>(new SampleOptions());

You can simplify that a bit to:

var someOptions = Options.Create(new SampleOptions());

Obviously this isn’t very useful as is. You’ll need to actually create and populate a SampleOptions object and pass that into the Create method.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)