예제 #1
0
        public void TestGetDrivers()
        {
            var options = new DbContextOptionsBuilder <DgtDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var context = new DgtDbContext(options);

            context.Database.EnsureCreated();
            DgtDbInitializer.Initialize(context);

            DriverRepository driverRepository = new DriverRepository(context);
            DriverService    driverService    = new DriverService(driverRepository);
            var drivers = driverService.GetDrivers();

            Assert.True(drivers.Count() == 2);
        }
예제 #2
0
파일: Startup.cs 프로젝트: daniel-gil/dgt
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            app.UseStaticFiles();
            // Add MVC to the request pipeline.
            app.UseCors(builder =>
                        builder.AllowAnyOrigin()
                        .AllowAnyHeader()
                        .AllowAnyMethod());


            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "DGT Project API V1");
            });


            app.UseHttpsRedirection();
            app.UseMvc();


            var serviceScopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>();

            using (var serviceScope = serviceScopeFactory.CreateScope())
            {
                var dbContext = serviceScope.ServiceProvider.GetService <DgtDbContext>();
                dbContext.Database.EnsureCreated();
                DgtDbInitializer.Initialize(dbContext);
            }
        }