public void CanAddGameName()
        {
            SetupMockSportLocationAndGameRepos();
            _mockGameRepo = new Mock<IPickUpGameRepository>();
            const string location = LocationName;
            const string profile1 = "Profile1";

            var request = new CreatePickupGameRequest
                              {
                                  DateTime = "03/03/03 12:00",
                                  Location = location,
                                  MaxPlayers = 5,
                                  MinPlayers = 3,
                                  Sport = SoccerName,
                                  Creator = profile1,
                                  GameName = "This is a game name"
                              };

            var handler = CreateHandler();

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
            _mockGameRepo.Verify(x => x.SavePickUpGame(It.Is<PickUpGame>(y => y.GameName == request.GameName)));
        }
        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));
        }
        public void ThrowsExceptionWhenThereIsNoSportSpecified()
        {
            SetupMockSportLocationAndGameRepos();

            var request = new CreatePickupGameRequest
                              {
                                  Location = "Loc",
                                  Sport = null,
                                  DateTime = "Sometime"
                              };
            var handler = CreateHandler();

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.SportNotSpecified));
        }
        public void ThrowsExceptionWhenTheDateCantBeParsed()
        {
            SetupMockSportLocationAndGameRepos();

            var request = new CreatePickupGameRequest
                              {
                                  Location = "Moo",
                                  Sport = SoccerName,
                                  DateTime = "BadDate"
                              };
            var handler = CreateHandler();

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.CouldNotParseDate));
        }
        public void ResponseReturnsWithGameIdOfCreatedGame()
        {
            SetupMockSportLocationAndGameRepos();
            _mockGameRepo = new Mock<IPickUpGameRepository>();
            const string location = LocationName;

            var request = new CreatePickupGameRequest
            {
                DateTime = "03/03/03 12:00",
                Location = location,
                MaxPlayers = 5,
                MinPlayers = 3,
                Sport = SoccerName
            };

            var handler = CreateHandler();

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
            Assert.That(response.GameId, Is.EqualTo(_pickUpGame.Id));
        }
        public void CanCreateGamesWithExactLocations()
        {
            SetupMockSportLocationAndGameRepos();
            _mockGameRepo = new Mock<IPickUpGameRepository>();
            const string location = LocationName;

            var request = new CreatePickupGameRequest
                              {
                                  DateTime = "03/03/03 12:00",
                                  Location = location,
                                  MaxPlayers = 5,
                                  MinPlayers = 3,
                                  ExactLocation = "Some Place",
                                  Sport = SoccerName
                              };

            var handler = CreateHandler();

            var response = handler.Handle(request);

            Assert.That(response.Status, Is.EqualTo(ResponseCodes.Success));
            _mockGameRepo.Verify(x => x.SavePickUpGame(It.Is<PickUpGame>(y => y.ExactLocation == request.ExactLocation)));
        }
        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));
        }