public void CreatePlayerGame() { using (var context = new AppDbContext(CreateNewContextOptions())) { PlayerService playerService = new PlayerService(context); GameService gameService = new GameService(context); playerService.CreatePlayer(new PlayerCreateCommand { Name = "ZTO" }); playerService.CreatePlayer(new PlayerCreateCommand { Name = "CS" }); var gcCommand = new GameCreateCommand { ChallengerId = 1, TargetId = 2 }; int gameId = gameService.CreateGame(gcCommand); gcCommand.Id = gameId; gameService.CreatePlayerGames(gcCommand); var expected1 = playerService.GetPlayerDetails("ZTO"); var expected2 = playerService.GetPlayerDetails("CS"); Assert.Equal(2, context.PlayerGames.Count()); Assert.Equal(1, expected1.Games.Count()); Assert.Equal(1, expected2.Games.Count()); } }
public int CreateGame(GameCreateCommand command) { Game game = command.ToGame(); _context.Games.Add(game); _context.SaveChanges(); return(game.Id); }
public IActionResult Create(GameCreateCommand cmd) { cmd.Id = _gameService.CreateGame(cmd); _gameService.CreatePlayerGames(cmd); _deckService.CreateDeck(cmd.ToChallengerDeck()); _deckService.CreateDeck(cmd.ToTargetDeck()); return(RedirectToAction(nameof(Index))); }
public void TestWriteToDatabase() { using (var context = new AppDbContext(CreateNewContextOptions())) { var service = new GameService(context); GameCreateCommand command1 = new GameCreateCommand(); GameCreateCommand command2 = new GameCreateCommand(); service.CreateGame(command1); service.CreateGame(command2); var result1 = context.Games.Find(1); var result2 = context.Games.Find(2); Assert.Equal(2, context.Games.Count()); } }
public void GetPlayerDetails() { using (var context = new AppDbContext(CreateNewContextOptions())) { var playerService = new PlayerService(context); var gameService = new GameService(context); PlayerCreateCommand player = new PlayerCreateCommand { Name = "ZTO" }; GameCreateCommand game1 = new GameCreateCommand(); GameCreateCommand game2 = new GameCreateCommand(); PlayerGame pg1 = new PlayerGame { PlayerId = 1, GameId = 1 }; PlayerGame pg2 = new PlayerGame { PlayerId = 1, GameId = 2 }; playerService.CreatePlayer(player); gameService.CreateGame(game1); gameService.CreateGame(game2); context.PlayerGames.AddRange(pg1, pg2); context.SaveChanges(); var players = playerService.GetPlayerDetails("ZTO"); var games = players.Games; Assert.IsType <PlayerViewModel>(players); Assert.IsType <List <GameViewModel> >(players.Games); Assert.Equal("ZTO", players.Name); Assert.Equal(2, games.Count()); } }
public void CreatePlayerGames(GameCreateCommand cmd) { _context.PlayerGames.Add(cmd.ToPGChallenger()); _context.PlayerGames.Add(cmd.ToPGTarget()); _context.SaveChanges(); }
public async Task <ActionResult <long> > Create(GameCreateCommand command) { return(Ok(await _mediator.Send(command))); }