OperationalStoreOptions in xUnit

I had little issue with creating IOptions<> to use it with xUnit, so below is solution:

var operationalStoreOptions = Options.Create(new OperationalStoreOptions());

Example using
Constructor in my class with DbContext looks like:

public ApiContext(
    DbContextOptions options,
    IOptions<OperationalStoreOptions> operationalStoreOptions)
    : base(options, operationalStoreOptions)

Corresponding lines of code in my xUnit test class:

using IdentityServer4.EntityFramework.Options;
using Microsoft.Extensions.Options;

var options = new DbContextOptionsBuilder<ApiContext>()
                .UseInMemoryDatabase(databaseName: "WebApp")

var operationalStoreOptions = Options.Create(new OperationalStoreOptions());

await using (var context = new ApiContext(options, operationalStoreOptions))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: