private APIDBContext MockAPIDbContext(int datarowstoadd = 1) { var options = new DbContextOptionsBuilder <APIDBContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new APIDBContext(options); for (int i = 1; i <= datarowstoadd; i++) { var testhi = new HelpInstruction() { Id = i, ExternalId = "test" + i, HostKey = "testhost" + i, LookupKey = "testkey" + i, TooltipText = "test tooltip text" + i }; context.HelpInstructions.Add(testhi); } context.SaveChanges(); return(context); }
public static async void InitialiseData(IServiceProvider svcs) { // but of a hack here but this just ensure that the db exists and that the basic data is configured // helps support basic ui tests as well as expected config for the admin web help instructions using (var servicescope = svcs.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = servicescope.ServiceProvider.GetService <APIDBContext>(); await context.Database.EnsureCreatedAsync(); if (!await context.HelpInstructions.AnyAsync(x => x.HostKey == "HelpInstructionSvc" && x.LookupKey == "Host")) { var hi1 = new HelpInstruction() { HostKey = "HelpInstructionSvc", LookupKey = "Host", TooltipText = "I am the host tooltip text!" }; await context.HelpInstructions.AddAsync(hi1); } if (!await context.HelpInstructions.AnyAsync(x => x.HostKey == "HelpInstructionSvc" && x.LookupKey == "LookupKey")) { var hi2 = new HelpInstruction() { HostKey = "HelpInstructionSvc", LookupKey = "LookupKey", TooltipText = "I am the lookup key tooltip text!" }; await context.HelpInstructions.AddAsync(hi2); } if (!await context.HelpInstructions.AnyAsync(x => x.HostKey == "HelpInstructionSvc" && x.LookupKey == "TooltipText")) { var hi3 = new HelpInstruction() { HostKey = "HelpInstructionSvc", LookupKey = "TooltipText", TooltipText = "I am the tooltip text tooltip text!" }; await context.HelpInstructions.AddAsync(hi3); } await context.SaveChangesAsync(); } }