public GridCoordinateModelBuilder()
 {
     _model = new GridCoordinateModel
     {
         Row    = RandomGenerator.Next(1, 11),
         Column = RandomGenerator.Next(1, 11)
     };
 }
        private void ActAndAssertShootAtOpponentShouldReturnBadRequest(Guid gameId, GridCoordinateModel coordinateModel)
        {
            //Act
            var result = _controller.ShootAtOpponent(gameId, coordinateModel).Result as BadRequestObjectResult;

            //Assert
            Assert.That(result, Is.Not.Null, "An instance of 'BadRequestObjectResult' should be returned.");
            _userManagerMock.Verify();
            _gameServiceMock.Verify();
            var serializableError = result.Value as SerializableError;

            Assert.IsNotNull(serializableError, "The 'BadRequestObjectResult' should contain a ModelState error collection");
            Assert.That(serializableError.Count, Is.EqualTo(1), "The 'BadRequestObjectResult' should exactly one error");
        }
        public async Task <IActionResult> ShootAtOpponent(Guid id, GridCoordinateModel model)
        {
            var currentUser = await _userManager.GetUserAsync(User);

            try
            {
                ShotResult result = _gameService.ShootAtOpponent(id, currentUser.Id, new GridCoordinate(model.Row, model.Column));
                return(Ok(result));
            }
            catch (DataNotFoundException)
            {
                ModelState.AddModelError("gameNotFound", $"Could not find a game with id {id}");
            }
            catch (ApplicationException applicationException)
            {
                ModelState.AddModelError("applicationException", applicationException.Message);
            }
            return(BadRequest(ModelState));
        }
Exemple #4
0
        private void ActAndAssertShootAtOpponentShouldReturnBadRequest(Guid gameId, GridCoordinateModel coordinateModel)
        {
            //Act
            var result = _controller.ShootAtOpponent(gameId, coordinateModel).Result as BadRequestObjectResult;

            //Assert
            Assert.That(result, Is.Not.Null, "An instance of 'BadRequestObjectResult' should be returned.");

            _userManagerMock.Verify(manager => manager.GetUserAsync(It.IsAny <ClaimsPrincipal>()), Times.Once,
                                    "The 'GetUserAsync' of the UserManager is not called");
            _gameServiceMock.Verify(service =>
                                    service.ShootAtOpponent(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <GridCoordinate>()), Times.Once,
                                    "The 'ShootAtOpponent' of the IGameService is not called.");

            var serializableError = result.Value as SerializableError;

            Assert.IsNotNull(serializableError, "The 'BadRequestObjectResult' should contain a ModelState error collection");
            Assert.That(serializableError.Count, Is.EqualTo(1), "The 'BadRequestObjectResult' should exactly one error");
        }