コード例 #1
0
        public void CanCreateAGameThatIsPrivate()
        {
            var date = DateTime.Now;
            SetupMockSportLocationAndGameRepos();
            _mockGameRepo = new Mock<IPickUpGameRepository>();
            _pickUpGame = new PickUpGame(date, _sport, _location) { IsPrivate = true };
            var nonPrivateGame = new PickUpGame(date, _sport, _location);
            _mockGameFactory = new Mock<IGameFactory>();
            _mockGameFactory.Setup(x => x.CreatePickUpGame(It.IsAny<DateTime>(), It.IsAny<Sport>(), It.IsAny<Location>(), true)).Returns(
                _pickUpGame);
            _mockGameFactory.Setup(x => x.CreatePickUpGame(It.IsAny<DateTime>(), It.IsAny<Sport>(), It.IsAny<Location>(), false)).Returns(
                nonPrivateGame);
            _mockGameRepo.Setup(x => x.SavePickUpGame(It.IsAny<PickUpGame>())).Verifiable();

            const string location = LocationName;

            var request = new CreatePickupGameRequest
            {
                DateTime = date.ToLongDateString(),
                Location = location,
                MaxPlayers = 5,
                MinPlayers = 3,
                Sport = SoccerName,
                IsPrivate = true
            };

            var handler = CreateHandler();

            var response = handler.Handle(request);

            _mockGameRepo.Verify(x => x.SavePickUpGame(_pickUpGame), Times.AtLeastOnce());

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
        }
コード例 #2
0
        public void CanCheckToSeeIfGameIsFull()
        {
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location());
            game.MaxPlayers = 0;

            Assert.True(game.IsFull());
        }
コード例 #3
0
        public void CanSearchForGamesViaLocationAndSportType()
        {
            var soccer = TestData.CreateSoccerGame();
            var basketball = TestData.CreateBasketballGame();
            var location1 = TestData.CreateLocationBend();
            var location2 = TestData.CreateLocationHamsterville();

            var soccerGame1 = new PickUpGame(DateTime.Now, soccer, location1);
            var soccerGame2 = new PickUpGame(DateTime.Now, soccer, location2);
            var basketballGame = new PickUpGame(DateTime.Now, basketball, location1);

            var listOfGames = new List<PickUpGame> { soccerGame1, soccerGame2, basketballGame };

            var request = new SearchForPickupGameRequest { Location = location1.Name, Sport = soccer.Name };

            _gameRepository.Setup(x => x.FindPickUpGameByLocation(It.Is<string>(d => d == location1.Name)))
                .Returns(listOfGames.Where(x => x.Location == location1.Name).ToList());

            var handler = new SearchForPickupGameRequestHandle(_gameRepository.Object);

            var response = handler.Handle(request);

            Assert.That(response.GamesFound.Count, Is.EqualTo(1));
            Assert.That(response.GamesFound[0].Location, Is.EqualTo(location1.Name));
            Assert.That(response.GamesFound[0].Sport, Is.EqualTo(soccer.Name));
        }
コード例 #4
0
        public void CannotAddPlayerToGameIfAtMaxCapacity()
        {
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location());
             game.MaxPlayers = 0;

             var exception = Assert.Throws(typeof (Exception), () => game.AddPlayer("Profile1"));
             Assert.AreEqual(exception.Message, "The game is already at capacity.");
        }
コード例 #5
0
        public void CannotJoinGameIfFull()
        {
            var request = new JoinGameRequest { GameId = "1", ProfileId = "123" };
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location()) { MaxPlayers = 0 };

            _mockGameRepo.Setup(x => x.GetPickUpGameById(request.GameId)).Returns(game);

            var handler = new JoinGameRequestHandler(_mockGameRepo.Object);
            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.GameIsFull));
        }
コード例 #6
0
        public void CanJoinGame()
        {
            var request = new JoinGameRequest { GameId = "1", ProfileId = "123" };
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location());

            _mockGameRepo.Setup(x => x.GetPickUpGameById(request.GameId)).Returns(game);

            var handler = new JoinGameRequestHandler(_mockGameRepo.Object);
            var response = handler.Handle(request);

            _mockGameRepo.Verify(x => x.AddPlayerToGame(game.Id, request.ProfileId));
            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
        }
コード例 #7
0
        public void ReturnsEarlyIfGameIsNowFull()
        {
            var request = CreateAcceptGameRequest();
            var gameWithoutTeams = new PickUpGame { MaxPlayers = 0 };
            _gameRepo.Setup(x => x.GetPickUpGameById(request.GameId)).Returns(gameWithoutTeams);
            var handler = new AcceptPickupGameInviteRequestHandle(_gameRepo.Object, _inviteRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status == ResponseCodes.GameIsFull);
            _gameRepo.Verify(x => x.GetPickUpGameById(request.GameId));
            _inviteRepo.Verify(x => x.Delete(request.InviteId), Times.Once());
            _gameRepo.Verify(x => x.AddPlayerToGame(request.GameId, request.ProfileId), Times.Never());
        }
コード例 #8
0
        public void RemovesGamesThatOld()
        {
            var game1 = new PickUpGame(DateTime.Now, new Sport(), new Location());
            var game2 = new PickUpGame(DateTime.Now, new Sport(), new Location());
            var game3 = new PickUpGame(DateTime.Now, new Sport(), new Location());
            var games = new List<PickUpGame> {game1, game2, game3};
            var gameRepo = new Mock<IPickUpGameRepository>();
            gameRepo.Setup(x => x.GetGamesWithinDateRange(It.IsAny<DateTime>(), It.IsAny<DateTime>())).Returns(games);

            var gameCleaner = new OldGameRemover(gameRepo.Object);

            gameCleaner.CleanForPastMinutes(15);

            gameRepo.Verify(x => x.DeleteGame(game1.Id));
            gameRepo.Verify(x => x.DeleteGame(game2.Id));
            gameRepo.Verify(x => x.DeleteGame(game3.Id));
        }
コード例 #9
0
        public void GamesReturnWithPlayerIds()
        {
            var soccer = TestData.CreateSoccerGame();
            var location1 = TestData.CreateLocationBend();
            var soccerGame1 = new PickUpGame(DateTime.Now, soccer, location1);
            const string expected = "Boop";
            soccerGame1.PlayersIds.Add(expected);
            var listOfGames = new List<PickUpGame> { soccerGame1 };
            var request = new SearchForPickupGameRequest { Location = location1.Name, Sport = soccer.Name };
            _gameRepository.Setup(x => x.FindPickUpGameByLocation(It.Is<string>(d => d == location1.Name)))
                .Returns(listOfGames.Where(x => x.Location == location1.Name).ToList());
            var handler = new SearchForPickupGameRequestHandle(_gameRepository.Object);

            var response = handler.Handle(request);

            Assert.That(response.GamesFound.Count, Is.EqualTo(1));
            Assert.That(response.GamesFound[0].PlayersIds, Has.Member(expected));
        }
コード例 #10
0
        public void FiltersOutGamesThatProfilesIsAPartOf()
        {
            var soccer = TestData.CreateSoccerGame();
            var location1 = TestData.CreateLocationBend();
            var location2 = TestData.CreateLocationHamsterville();
            var soccerGame1 = new PickUpGame(DateTime.Now, soccer, location1);
            const string profileId = "Profile1";
            soccerGame1.PlayersIds.Add(profileId);
            var soccerGame2 = new PickUpGame(DateTime.Now, soccer, location2);
            var listOfGames = new List<PickUpGame> { soccerGame1, soccerGame2 };
            _gameRepository.Setup(x => x.FindPickUpGameByLocation(It.IsAny<string>())).Returns(listOfGames);
            var request = new SearchForPickupGameRequest { Location = location1.Name, Sport = soccer.Name, ProfileId = profileId};
            var handler = new SearchForPickupGameRequestHandle(_gameRepository.Object);

            var response = handler.Handle(request);

            Assert.That(response.GamesFound.Count, Is.EqualTo(1));
            Assert.That(response.GamesFound[0], Is.Not.EqualTo(soccerGame1));
        }
コード例 #11
0
        public void CanOnlyDeleteIfOwnerOfGame()
        {
            var pickUpGame = new PickUpGame(DateTime.Now, new Sport(), new Location()) {Creator = "MooCreator"};

            var pickUpGameRepo = new Mock<IPickUpGameRepository>();
            pickUpGameRepo.Setup(x => x.GetPickUpGameById(pickUpGame.Id)).Returns(pickUpGame);

            var request = new DeletePickUpGameRequest
            {
                GameId = pickUpGame.Id,
                ProfileId = "CowCreator"
            };

            var handler = new DeletePickUpGameRequestHandle(pickUpGameRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.NotCreator));
            pickUpGameRepo.Verify(x => x.DeleteGame(pickUpGame.Id), Times.Never());
        }
コード例 #12
0
        public void CanGetCurrentInvitesToOtherGames()
        {
            var inviteRepo = new Mock<IInviteRepository>();
            var gameRepo = new Mock<IPickUpGameRepository>();

            var request = new GetCurrentGameInviteRequest
                              {
                                  ProfileId = "123"
                              };
            var invite = new Invite { EventId = "1234" };
            inviteRepo.Setup(x => x.GetInvitesToProfile(request.ProfileId)).Returns(new List<Invite> { invite });
            var gameWithoutTeams = new PickUpGame();
            gameRepo.Setup(x => x.GetPickUpGameById(invite.EventId)).Returns(gameWithoutTeams);

            var handler = new GetCurrentGameInviteHandle(inviteRepo.Object, gameRepo.Object);

            var response = handler.Handle(request);

            Assert.That(response.GamesWithoutTeams, Is.Not.Empty);
            Assert.That(response.GamesWithoutTeams[0], Is.SameAs(gameWithoutTeams));
        }
コード例 #13
0
        public void CanGetGamesForProfile()
        {
            var profileId = "1234";
            var pickUpGame = new PickUpGame(DateTime.Now, new Sport(), new Location());
            var gameWithTeams = new TeamGame(DateTime.Now, new Sport(), new Location());
            var gameRepo = new Mock<IPickUpGameRepository>();
            var teamRepo = new Mock<ITeamGameRepository>();
            gameRepo.Setup(x => x.GetPickupGamesForProfile(profileId)).Returns(new List<PickUpGame> { pickUpGame });
            teamRepo.Setup(x => x.GetTeamGamesForProfile(profileId)).Returns(new List<TeamGame> { gameWithTeams });

            var request = new GetGamesForProfileRequest
                              {
                                  ProfileId = profileId
                              };

            var handler = new GetGamesForProfileRequestHandle(gameRepo.Object, teamRepo.Object);

            var response = handler.Handle(request);

            //Assert.That(response.TeamGames[0], Is.SameAs(gameWithTeams));
            Assert.That(response.PickupGames[0], Is.SameAs(pickUpGame));
        }
コード例 #14
0
        private void CreateExtraGames()
        {
            for (var k = 0; k < 100; k++)
            {
                var randomNumber = new Random(k);
                Console.WriteLine("Creating record: " + k);
                var game = new PickUpGame(DateTime.Now, new Sport(), new Location());
                game.MaxPlayers = 5;
                game.MinPlayers = 3;
                game.IsPrivate = true;
                game.Sport = SportIds[((int)(randomNumber.NextDouble() * SportIds.Count))];
                game.Location = LocationIds[((int)(randomNumber.NextDouble() * LocationIds.Count))];
                for (int i = 0; i < 5; i++)
                {
                    var profileId = ProfileIds[((int)(randomNumber.NextDouble() * ProfileIds.Count))];
                    if (game.PlayersIds.Contains(profileId))
                        continue;
                    game.AddPlayer(profileId);
                }
                game.Creator = Profile1Id;

                new PickUpGameRepository().SavePickUpGame(game);
            }
        }
コード例 #15
0
        public void CanCreateAGameWithNoTeams()
        {
            SetupMockSportLocationAndGameRepos();
            var request = new CreatePickupGameRequest
                              {
                                  DateTime = "03/03/03 12:00",
                                  Location = LocationName,
                                  MaxPlayers = 5,
                                  MinPlayers = 3,
                                  Sport = SoccerName
                              };
            var gameWithoutTeams = new PickUpGame(DateTime.Parse(request.DateTime), _sport, _location);
            _mockGameFactory.Setup(
                x => x.CreatePickUpGame(It.Is<DateTime>(d => d == DateTime.Parse(request.DateTime))
                    , It.Is<Sport>(d => d == _sport), It.Is<Location>(d => d == _location), It.IsAny<bool>())).Returns(
                    gameWithoutTeams);
            _mockGameRepo.Setup(x => x.SavePickUpGame(It.Is<PickUpGame>(d => d == gameWithoutTeams)));

            var handler = CreateHandler();

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
        }
コード例 #16
0
        public void IfNoSportWasSpecifiedItDoesNotFilter()
        {
            var soccer = TestData.CreateSoccerGame();
            var location1 = TestData.CreateLocationBend();
            var soccerGame1 = new PickUpGame(DateTime.Now, soccer, location1);
            var listOfGames = new List<PickUpGame> { soccerGame1 };
            _gameRepository.Setup(x => x.FindPickUpGameByLocation(It.Is<string>(d => d == location1.Name)))
                .Returns(listOfGames.Where(x => x.Location == location1.Name).ToList());
            var request = new SearchForPickupGameRequest { Location = location1.Name, Sport = string.Empty };

            var handler = new SearchForPickupGameRequestHandle(_gameRepository.Object);

            var response = handler.Handle(request);

            Assert.That(response.GamesFound.Count, Is.EqualTo(1));
            Assert.That(response.GamesFound[0].Location, Is.EqualTo(location1.Name));
            Assert.That(response.GamesFound[0].Sport, Is.EqualTo(soccer.Name));
        }
コード例 #17
0
 private void MapPlayersInGame(IDbCommand dbCmd, PickUpGame game)
 {
     game.PlayersIds =
         dbCmd.Select<PlayerInGameLink>(x => x.GameId == game.Id).Select(x => x.PlayerId).ToList();
 }
コード例 #18
0
 private void AssertGameWithTeamsWasCreatedAndDataLinesUp(PickUpGame game)
 {
     Assert.NotNull(game);
     Assert.That(game.Sport, Is.EqualTo("Soccer"));
     Assert.That(game.Location, Is.EqualTo(_location.Name));
 }
コード例 #19
0
 public void SavePickUpGame(PickUpGame game)
 {
     using (IDbConnection db = _connectionFactory.OpenDbConnection())
     using (IDbCommand dbCmd = db.CreateCommand())
     {
         dbCmd.Save(game);
         foreach (var playerId in game.PlayersIds)
         {
             AddPlayerToGame(game.Id, playerId);
         }
     }
 }
コード例 #20
0
 public void SetUp()
 {
     _sport = new Sport { Name = SoccerName };
     _location = new Location { Name = LocationName };
     _pickUpGame = new PickUpGame(DateTime.Now, _sport, _location);
 }
コード例 #21
0
        public PickUpGame CreateGameWithProfile1AndProfile2()
        {
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location());
            game.MaxPlayers = 5;
            game.MinPlayers = 3;
            game.IsPrivate = true;
            game.Sport = Basketballname;
            game.Location = LocationPortland;
            game.AddPlayer(Profile1Id);
            game.AddPlayer(Profile2Id);
            game.Creator = Profile1Id;
            game.GameName = "Cool Game";

            new PickUpGameRepository().SavePickUpGame(game);
            PickUpGame = game;
            return game;
        }
コード例 #22
0
        public PickUpGame CreateGameWithProfile1()
        {
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location());
            game.MaxPlayers = 5;
            game.MinPlayers = 3;
            game.IsPrivate = true;
            game.Sport = SoccerName;
            game.Location = LocationBendName;
            game.AddPlayer(Profile1Id);
            game.Creator = Profile1Id;
            game.GameName = "1 Player game";

            new PickUpGameRepository().SavePickUpGame(game);
            PickUpGame = game;
            return game;
        }
コード例 #23
0
        private PickUpGame CreatePickUpGameOnly()
        {
            var game = new PickUpGame(DateTime.Now, new Sport(), new Location());
            game.MaxPlayers = 5;
            game.MinPlayers = 3;
            game.IsPrivate = true;
            game.Sport = "Soccer";
            game.Location = "Bend";
            game.AddPlayer(_profile.ProfileName);
            game.Creator = _profile.ProfileName;
            game.ExactLocation = "A road in space";
            game.GameName = "A game name";

            _repo.SavePickUpGame(game);
            return game;
        }
コード例 #24
0
 public void SetUp()
 {
     _game = new PickUpGame(DateTime.Now, new Sport(), new Location());
 }