You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Helpers.cs 858B

123456789101112131415161718192021222324
  1. using Diligent.WebAPI.Data;
  2. using Diligent.WebAPI.Data.Entities;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Diligent.WebAPI.Tests
  5. {
  6. public static class Helpers
  7. {
  8. public static async Task<DatabaseContext> GetDatabaseContext(List<Applicant> applicants)
  9. {
  10. var options = new DbContextOptionsBuilder<DatabaseContext>()
  11. .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
  12. .Options;
  13. var databaseContext = new DatabaseContext(options);
  14. databaseContext.Database.EnsureCreated();
  15. if (!await databaseContext.Applicants.AnyAsync())
  16. {
  17. await databaseContext.Applicants.AddRangeAsync(applicants);
  18. await databaseContext.SaveChangesAsync();
  19. }
  20. return databaseContext;
  21. }
  22. }
  23. }