Beispiel #1
0
        public SmilesServiceTests()
        {
            var options = new DbContextOptionsBuilder <SmilesDbContext>()
                          .UseNpgsql("Host=localhost;Database=smilesdb;Username=postgres;Password=Password1")
                          .Options;
            var dataContext = new SmilesDbContext(options);

            _unitOfWork    = new UnitOfWork(dataContext);
            _smilesService = new SmilesService(_unitOfWork);
        }
Beispiel #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SmilesDbContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "SMILES API v1");
                    c.SwaggerEndpoint("/swagger/v2/swagger.json", "SMILES API v2");
                }
                                 );
            }

            try
            {
                db.Database.Migrate();
            }
            catch (Exception ex)
            {
                // Probably DB engine is not running
                Console.WriteLine($"Database engine is not ready: {ex.Message}");
                Environment.Exit(-1);
            }


            app.UseRouting();

            app.UseAuthorization();

            // Not a good idea in a production environment
            app.UseCors(config =>
            {
                config.AllowAnyOrigin();
                config.AllowAnyMethod();
                config.AllowAnyHeader();
            });

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #3
0
 public SmilesRepository(SmilesDbContext dbContext) : base(dbContext)
 {
 }