public void AddNewGame() { var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var newGame = new Game { Title = "DDD" }; //Arrange using (var context = new GameManagementContext(ContextOptions)) { fixture.Inject(context); var command = new Add.Command { Title = newGame.Title }; var handler = fixture.Create <Add.CommandHandler>(); //Act var response = handler.Handle(command, new System.Threading.CancellationToken()).Result; var game = context.Games.SingleOrDefaultAsync(g => g.Title == newGame.Title).Result; //Assert Assert.True(response.Success); Assert.NotNull(game); Assert.Equal(newGame.Title, game.Title); } }
public void DeleteGame() { var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var gameId = 1; //Arrange using (var context = new GameManagementContext(ContextOptions)) { fixture.Inject(context); var command = new Delete.Command { Id = gameId }; var handler = fixture.Create <Delete.CommandHandler>(); //Act var response = handler.Handle(command, new System.Threading.CancellationToken()).Result; var game = context.Games.Find(gameId); //Assert Assert.True(response.Success); Assert.Null(game); } }
public void EditGame_ChangeTitle() { var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var gameId = 1; var newTitle = "111"; //Arrange using (var context = new GameManagementContext(ContextOptions)) { fixture.Inject(context); var command = new Edit.Command { Id = gameId, Title = newTitle }; var handler = fixture.Create <Edit.CommandHandler>(); var oldTitle = context.Games.Find(gameId).Title; //Act var response = handler.Handle(command, new System.Threading.CancellationToken()).Result; var game = context.Games.Find(gameId); //Assert Assert.True(response.Success); Assert.NotNull(game); Assert.Equal(newTitle, game.Title); Assert.NotEqual(newTitle, oldTitle); } }
private void Seed() { using (var context = new GameManagementContext(ContextOptions)) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.AddRange(SeedPlatforms); context.AddRange(SeedGames); context.SaveChanges(); } }
public void EditGame_AddPlatform() { var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var gameId = 1; var gameTitle = ((Game)SeedGames[0]).Title; var platforms = new[] { (Platform)SeedPlatforms[0] }; //Arrange using (var context = new GameManagementContext(ContextOptions)) { fixture.Inject(context); var command = new Edit.Command { Id = gameId, Title = gameTitle, Platforms = platforms }; var handler = fixture.Create <Edit.CommandHandler>(); //Act var response = handler.Handle(command, new System.Threading.CancellationToken()).Result; var game = context.Games .Include(g => g.GamePlatforms) .ThenInclude(p => p.Platform) .SingleOrDefaultAsync(g => g.Id == gameId).Result; //Assert Assert.True(response.Success); Assert.NotNull(game); Assert.Equal(gameTitle, game.Title); Assert.Equal(platforms[0].Id, game.GamePlatforms.FirstOrDefault()?.Platform.Id); Assert.Equal(platforms[0].Name, game.GamePlatforms.FirstOrDefault()?.Platform.Name); } }
public void AddNewGame_WithPlatform() { var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); var newGameTitle = "DDD"; var newGamePlatform = (Platform)SeedPlatforms[0]; //Arrange using (var context = new GameManagementContext(ContextOptions)) { fixture.Inject(context); var command = new Add.Command { Title = newGameTitle, Platforms = new [] { newGamePlatform } }; var handler = fixture.Create <Add.CommandHandler>(); //Act var response = handler.Handle(command, new System.Threading.CancellationToken()).Result; var game = context.Games .Include(g => g.GamePlatforms) .ThenInclude(p => p.Platform) .SingleOrDefaultAsync(g => g.Title == newGameTitle).Result; //Assert Assert.True(response.Success); Assert.NotNull(game); Assert.Equal(newGameTitle, game.Title); Assert.Equal(newGamePlatform.Id, game.GamePlatforms.FirstOrDefault()?.Platform.Id); Assert.Equal(newGamePlatform.Name, game.GamePlatforms.FirstOrDefault()?.Platform.Name); } }
public void ListAllGames() { var fixture = new Fixture(); fixture.Customize(new AutoMoqCustomization()); //Arrange using (var context = new GameManagementContext(ContextOptions)) { fixture.Inject(context); var command = new List.Query(); var handler = fixture.Create <List.QueryHandler>(); //Act var games = handler.Handle(command, new System.Threading.CancellationToken()).Result; //Assert Assert.Equal(SeedGames.Length, games.Length); Assert.Equal(((Game)SeedGames[0]).Title, games[0].Title); } }
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, GameManagementContext dataContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } dataContext.Database.Migrate(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( "default", "{controller=Home}/{action=Index}/{id?}"); }); }
public QueryHandler(GameManagementContext context) { _context = context; }
public CommandHandler(GameManagementContext context) { _context = context; }