2

After I managed to get multiple Database Context working in asp.net boilerplate (with some help here ASP.NET Boilerplate multiple databases and DbContexts), I ran into another problem. In the unit tests, when I use one of the additional database contexts like so:

 using (var uow = this.UnitOfWorkManager.Begin())
 {
   var r = this.SlipLineRepository.GetAll().ToList();
 }

I get this error:

Abp.AbpException : Could not resolve DbContextOptions for SlipStreamAPI.SlipStreamDB.miSlipLiveContext, SlipStreamAPI.EntityFrameworkCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.

So my questions are: 1) Is it possible to test against in memory DB contexts, if they are the second, third, etc context? 2) If it is, what should I do to make it work?

Bertus van Zyl
  • 582
  • 5
  • 17

1 Answers1

3

You should register DbContextOptions in ServiceCollectionRegistrar.cs:

public static void Register(IIocManager iocManager)
{
    // ...

    var builder = new DbContextOptionsBuilder<miSlipLiveContext>();
    builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);

    iocManager.IocContainer.Register(
        Component
            .For<DbContextOptions<miSlipLiveContext>>()
            .Instance(builder.Options)
            .LifestyleSingleton()
    );
}
aaron
  • 39,695
  • 6
  • 46
  • 102