Exemplo n.º 1
0
 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);
        }
Exemplo n.º 4
0
        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
        }
Exemplo n.º 5
0
        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();
 }
Exemplo n.º 8
0
 public SqlApplicantData(ApplicantDbContext db)
 {
     this.db = db;
 }
Exemplo n.º 9
0
        public ApplicantRepository(IServiceProvider services)
        {
            _scope = services.CreateScope();

            _databaseContext = _scope.ServiceProvider.GetRequiredService <ApplicantDbContext>();
        }
 public Repository(ApplicantDbContext applicantContext)
 {
     _applicantContext = applicantContext;
 }
Exemplo n.º 11
0
 public ElectorsController(ApplicantDbContext context)
 {
     _context = context;
 }
Exemplo n.º 12
0
 public ApplicantsController(ApplicantDbContext context)
 {
     _context = context;
 }
Exemplo n.º 13
0
 /// <summary>
 /// Parameterized constructor.
 /// Inject the DB context and logging dependencies.
 /// </summary>
 public Repository(ApplicantDbContext applicantContext, ILogger <Repository <TEntity> > logger)
 {
     _applicantContext = applicantContext;
     _logger           = logger;
 }
Exemplo n.º 14
0
 public ApplicantRepository(ApplicantDbContext customerContext) : base(customerContext)
 {
 }
Exemplo n.º 15
0
 public ApplicantRepository(ApplicantDbContext context)
 {
     _context = context;
 }