public async Task Should_throw_when_adding_game_to_player_for_unknown_player()
        {
            var player = new PlayerBuilder()
                         .Einstein
                         .Build();
            var game = Player.Game.From(player.Id, new GameBuilder().FirstPlayerEinstein.RandomId);

            // Act
            await Assert.ThrowsAsync <UpdateException>(() => _repository.AddOrUpdatePlayerGameAsync(player.Id, game));
        }
        public async Task Should_create_player_only_once()
        {
            var builder = new PlayerBuilder()
                          .Eiffel
                          .AddGame(b => b.SecondPlayerEiffel);
            await _repository.CreatePlayerIfNotExistingAsync(builder);

            // Act
            var hasCreated = await _repository.CreatePlayerIfNotExistingAsync(builder);

            hasCreated.Should().BeFalse();
        }
        public async Task Should_create_player()
        {
            var builder = new PlayerBuilder()
                          .Eiffel
                          .AddGame(b => b.SecondPlayerEiffel);
            var player = builder.Build(); // need to get another one since mongodb will alter it (to add id for example)

            // Act
            var hasCreated = await _repository.CreatePlayerIfNotExistingAsync(builder);

            hasCreated.Should().BeTrue();
        }
        public async Task Should_add_game_to_player_when_game_is_not_there()
        {
            var builder = new PlayerBuilder().Einstein;
            var player  = builder.Build();
            await _repository.CreatePlayerIfNotExistingAsync(player);

            var game = Player.Game.From(player.Id, new GameBuilder().FirstPlayerEinstein.CardBattle.RandomId);

            // Act
            await _repository.AddOrUpdatePlayerGameAsync(player.Id, game);

            var games = await _repository.GetPlayerGamesAsync(player.Id);

            games.Should().ContainEquivalentOf(game, options => options.WithMongoDateTime());
        }
        public async Task Should_get_active_games_only_where_player_is_in()
        {
            var player2 = new PlayerBuilder()
                          .Einstein
                          .AddGame(b => b.FirstPlayerEinstein.InGame)
                          .AddGame(b => b.FirstPlayerEinstein.Finished)
                          .Build();
            await _repository.CreatePlayerIfNotExistingAsync(player2);

            // Act
            var games = await _repository.GetPlayerGamesAsync(PlayerData.Einstein.ID, GameStatus.InGame);

            games.Should().BeEquivalentTo(
                player2.Games.Where(g => g.Status == GameStatus.InGame),
                options => options.WithMongoDateTime());
        }
        public async Task Should_get_games_where_player_is_in()
        {
            var player1 = new PlayerBuilder()
                          .Eiffel
                          .AddGame(b => b.SecondPlayerEiffel)
                          .Build();
            await _repository.CreatePlayerIfNotExistingAsync(player1);

            var player2 = new PlayerBuilder()
                          .Einstein
                          .AddGame(b => b.FirstPlayerEinstein)
                          .Build();
            await _repository.CreatePlayerIfNotExistingAsync(player2);

            // Act
            var games = await _repository.GetPlayerGamesAsync(PlayerData.Einstein.ID);

            games.Should().BeEquivalentTo(player2.Games, options => options.WithMongoDateTime());
        }
        public async Task Should_update_player_game_player_when_already_there()
        {
            var gameBuilder = new GameBuilder()
                              .FirstPlayerEinstein
                              .TicTacToe
                              .RandomId;
            var playerBuilder = new PlayerBuilder()
                                .Einstein
                                .AddGame(gameBuilder);
            var player = playerBuilder.Build();
            await _repository.CreatePlayerIfNotExistingAsync(player);

            gameBuilder.TimedOut.StartedEndedAt(DateTime.UtcNow.AddDays(1), DateTime.UtcNow.AddDays(3));
            var updatedGame = Player.Game.From(player.Id, gameBuilder);

            // Act
            await _repository.AddOrUpdatePlayerGameAsync(player.Id, updatedGame);

            var games = await _repository.GetPlayerGamesAsync(player.Id);

            games.Single().Should().BeEquivalentTo(updatedGame, options => options.WithMongoDateTime());
        }