/// <summary> /// Creates a <see cref="FixedDbContextAccessor{TDbContext}"/>, its <see cref="Microsoft.EntityFrameworkCore.DbContext"/> accessible through the <see cref="DbContext"/> property. /// </summary> private FixedDbContextAccessor <TestDbContext> Create(CreationType creationType) { return(creationType switch { CreationType.Instance => FixedDbContextAccessor.Create(dbContext: this.CreateAndRememberDbContext()), CreationType.Factory => FixedDbContextAccessor.Create(this.CreateAndRememberDbContext), _ => throw new NotImplementedException(), });
public OrderRepoTests() { this.Connection = new SqliteConnection("Filename=:memory:"); this.Connection.Open(); this.DbContext = new ReferenceDbContext( new DbContextOptionsBuilder().UseSqlite(this.Connection).Options); this.DbContext.Database.EnsureCreated(); // Provide the repo access to a fixed DbContext var dbContextAccessor = FixedDbContextAccessor.Create(this.DbContext); this.Repo = new OrderRepo(dbContextAccessor); }