public async void ShouldDeleteGame() { //arrange BoardContext context = new ContextBuilder().BuildClean(); Game game = new GameBuilder(context) .Build(); var newGame = context.Add(game); context.SaveChanges(); //act var command = new DeleteGameCommand(); command.Id = newGame.Entity.Id; var handler = new DeleteGameCommand.Handler(context); var result = await handler.Handle(command, default); //assert var deletedGame = context.Games .Where(x => x.Id == newGame.Entity.Id) .FirstOrDefault(); Assert.Null(deletedGame); }
public async void ShouldReturnEditGameViewModel() { //arrange BoardContext context = new ContextBuilder().BuildClean(); string expectedName = "Posiadlosc szalenstwa"; int expectedAge = 5; int expectedMaxAmount = 6; int expectedMinAmount = 1; Game game = new GameBuilder(context) .WithName(expectedName) .WithMaxPlayersAmount(expectedMaxAmount) .WithMinPlayersAmount(expectedMinAmount) .WithMinPlayersAge(expectedAge) .Build(); var newGame = context.Add(game); context.SaveChanges(); //act var query = new EditGameViewQuery(); query.Id = newGame.Entity.Id; var handler = new EditGameViewQuery.Handler(context); var result = await handler.Handle(query, default); //assert Assert.Equal(expectedAge, result.MinimalPlayersAge); Assert.Equal(expectedMaxAmount, result.MaximalPlayersAmount); Assert.Equal(expectedMinAmount, result.MinimalPlayersAmount); Assert.Equal(expectedName, result.Name); }
public async void ShouldGetGamesList() { //arrange BoardContext context = new ContextBuilder().BuildClean(); context.Add(new GameBuilder(context).Build()); context.Add(new GameBuilder(context).Build()); context.SaveChanges(); //act var query = new GetAllGamesQuery(); var handler = new GetAllGamesQuery.Handler(context); var result = await handler.Handle(query, default); //assert int expectedAmount = 2; Assert.Equal(2, result.Count); }
public async void ShouldEditGame() { //arrange BoardContext context = new ContextBuilder().BuildClean(); string expectedName = "Teraformacja marsa"; int expectedMaxAmount = 6; int expectedAge = 5; int expectedMinAmount = 1; string givenName = "Szybki Talizman"; int givenMaxAmount = 3; int givenAge = 4; int givenMinAmount = 2; Game game = new GameBuilder(context) .WithName(givenName) .WithMaxPlayersAmount(givenMaxAmount) .Build(); var newGame = context.Add(game); context.SaveChanges(); //act var query = new EditGameCommand(); query.Id = newGame.Entity.Id; query.MaximalPlayersAmount = expectedMaxAmount; query.Name = expectedName; query.MinimalPlayersAge = expectedAge; query.MinimalPlayersAmount = expectedMinAmount; var handler = new EditGameCommand.Handler(context); var result = await handler.Handle(query, default); //assert var createdGame = context.Games .Where(x => x.Id == newGame.Entity.Id) .Include(x => x.Visits) .FirstOrDefault(); Assert.Equal(expectedMaxAmount, createdGame.MaximalPlayersAmount); Assert.Equal(expectedName, createdGame.Name); }
public async void ShouldCreateVisit() { //arrange BoardContext context = new ContextBuilder().BuildClean(); var newGame = context.Add(new Game()); context.SaveChanges(); //act var query = new GameDetailQuery(); query.Id = newGame.Entity.Id; var handler = new GameDetailQuery.Handler(context); var result = await handler.Handle(query, default); //assert var game = context.Games .Where(x => x.Id == newGame.Entity.Id) .Include(x => x.Visits) .FirstOrDefault(); int expectedAmount = 1; Assert.Equal(expectedAmount, game.Visits.Count); }