public static void Init(IServiceProvider serviceProvider) { using var applicantDbContext = new ApplicantDbContext(serviceProvider.GetRequiredService <DbContextOptions <ApplicantDbContext> >()); if (applicantDbContext.Applicants.Any()) { return; } applicantDbContext.Applicants.AddRange( new Core.Applicant.Applicant { FirstName = "Joe", LastName = "Bloggs", DateOfBirth = new DateTime(1970, 05, 7), Email = "*****@*****.**" }, new Core.Applicant.Applicant { FirstName = "Henry", LastName = "Tudor", DateOfBirth = new DateTime(1969, 05, 7), Email = "*****@*****.**" } ); applicantDbContext.SaveChanges(); }
public static void Initialize(ApplicantDbContext context) { if (context.Applicants.Any()) { return; } Seed(context); }
public DatabaseTestBase() { var options = new DbContextOptionsBuilder <ApplicantDbContext>().UseInMemoryDatabase("ApplicantDatabase").Options; Context = new ApplicantDbContext(options); Context.Database.EnsureCreated(); DatabaseInitializer.Initialize(Context); }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicantDbContext context) { app.UseRouting(); app.UseControllerEndpoints(); app.UseExceptionHandling(env); app.UseOpenApi(); // Swagger app.UseSwaggerUi3(); // Swagger DbIitializer.SeedDb(context); // Seed/Migrate DB on start }
public RepositoryTests() { var appLogger = A.Fake <ILogger <Repository <Applicant> > >(); _applicantContext = A.Fake <ApplicantDbContext>(); _testeeFake = new Repository <Applicant>(_applicantContext, appLogger); _testee = new Repository <Applicant>(Context, appLogger); _newApplicant = new Applicant { Name = "Ahsan", FamilyName = "Raza", Address = "Berlin", EmailAddress = "*****@*****.**", CountryOfOrigin = "Germany", Age = 30, Hired = true }; }
private static void Seed(ApplicantDbContext context) { var applicants = new[] { new Applicant { Id = 1, Name = "Ahsan", FamilyName = "Raza", Address = "Berlin", EmailAddress = "*****@*****.**", CountryOfOrigin = "Germany", Age = 30, Hired = true }, new Applicant { Id = 2, Name = "JJ", FamilyName = "Kotze", Address = "Berlin", EmailAddress = "*****@*****.**", CountryOfOrigin = "Germany", Age = 26, Hired = true }, new Applicant { Id = 3, Name = "Carl", FamilyName = "Hibbard", Address = "Liverpool", EmailAddress = "*****@*****.**", CountryOfOrigin = "UK", Age = 55, Hired = true } }; context.Applicants.AddRange(applicants); context.SaveChanges(); }
public static void SeedDb(ApplicantDbContext context) { context.Database.Migrate(); }
public SqlApplicantData(ApplicantDbContext db) { this.db = db; }
public ApplicantRepository(IServiceProvider services) { _scope = services.CreateScope(); _databaseContext = _scope.ServiceProvider.GetRequiredService <ApplicantDbContext>(); }
public Repository(ApplicantDbContext applicantContext) { _applicantContext = applicantContext; }
public ElectorsController(ApplicantDbContext context) { _context = context; }
public ApplicantsController(ApplicantDbContext context) { _context = context; }
/// <summary> /// Parameterized constructor. /// Inject the DB context and logging dependencies. /// </summary> public Repository(ApplicantDbContext applicantContext, ILogger <Repository <TEntity> > logger) { _applicantContext = applicantContext; _logger = logger; }
public ApplicantRepository(ApplicantDbContext customerContext) : base(customerContext) { }
public ApplicantRepository(ApplicantDbContext context) { _context = context; }