Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              OnlineGameContext onlineGameContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>();
                        if (exceptionHandlerFeature != null)
                        {
                            var logger = loggerFactory.CreateLogger("Global exception logger");
                            logger.LogError(500,
                                            exceptionHandlerFeature.Error,
                                            exceptionHandlerFeature.Error.Message);
                        }

                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("An unexpected fault happened. Try again later.");
                    });
                });
            }

            app.UseCors(c => c.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
            MapperHelper.InitMapperConf();
            app.UseResponseCaching();
            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseMvc();
        }
Beispiel #2
0
        private void SeedInMemoryStore()
        {
            MapperHelper.InitMapperConf();
            using (var context = new OnlineGameContext(_options))
            {
                context.Database.EnsureCreated();
                context.Games.AddRange(GamesTestData.FirstGame, GamesTestData.ThirdGame,
                                       GamesTestData.FourthGame);

                context.SaveChanges();
            }
        }
Beispiel #3
0
        public void Database()
        {
            _options = new DbContextOptionsBuilder <OnlineGameContext>()
                       .UseInMemoryDatabase().Options;

            SeedInMemoryStore();
            var context           = new OnlineGameContext(_options);
            var gameRepository    = new GameRepository(context);
            var commentRepository = new CommentRepository(context);

            PublisherRepository = new PublisherRepository(context);
            GameService         = new GameService(gameRepository, new DefaultValidatorStrategy <GameModel>());
            CommentService      = new CommentService(commentRepository, new DefaultValidatorStrategy <CommentModel>());
        }