| 123456789101112131415161718192021222324 |
- using Diligent.WebAPI.Data;
- using Diligent.WebAPI.Data.Entities;
- using Microsoft.EntityFrameworkCore;
-
- namespace Diligent.WebAPI.Tests
- {
- public static class Helpers<T> where T : class
- {
- public static async Task<DatabaseContext> GetDatabaseContext(List<T> applicants)
- {
- var options = new DbContextOptionsBuilder<DatabaseContext>()
- .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
- .Options;
- var databaseContext = new DatabaseContext(options);
- databaseContext.Database.EnsureCreated();
- if (!await databaseContext.Set<T>().AnyAsync())
- {
- await databaseContext.Set<T>().AddRangeAsync(applicants);
- await databaseContext.SaveChangesAsync();
- }
- return databaseContext;
- }
- }
- }
|