public static async Task <CustomerContext> GetInMemoryCustomerDbContext(string dbName) { var dbContextOptions = new DbContextOptionsBuilder <CustomerContext>() .UseInMemoryDatabase(databaseName: dbName) .Options; var customerContext = new CustomerContext(dbContextOptions); customerContext.AddRange(GetMockCustomerData()); await customerContext.SaveChangesAsync(); return(customerContext); }
public CustomerControllerTest() { dbContextOptions = new DbContextOptionsBuilder <CustomerContext>() .UseInMemoryDatabase(databaseName: "in-memory") .Options; using (var dbContext = new CustomerContext(dbContextOptions)) { dbContext.AddRange(GetFakeData()); dbContext.SaveChanges(); } logger = new Mock <ILogger <CustomerController> >().Object; }
public static void PopulateDatabase() { using var context = new CustomerContext(quiet: true); context.AddRange( new Customer { Name = new Name { First = "Arthur", MiddleInitial = "J", Last = "Vickers" } }, new Customer { Name = new Name { First = "Wendy", MiddleInitial = "F", Last = "Vickers" } }, new Customer { Name = new Name { First = "George", Last = "Martin" } }, new Customer { Name = new Name { First = "Martin", Last = "Clunes" } }); context.SaveChanges(); }