Exemplo n.º 1
0
        public void ShootAtOpponent_ShouldUseServiceToRegisterTheShot()
        {
            //Arrange
            Guid gameId = Guid.NewGuid();
            GridCoordinateModel coordinateModel = new GridCoordinateModelBuilder().Build();

            ShotResult expectedShotResult = ShotResult.CreateMissed();

            _gameServiceMock.Setup(service =>
                                   service.ShootAtOpponent(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <GridCoordinate>()))
            .Returns(expectedShotResult);

            //Act
            var result = _controller.ShootAtOpponent(gameId, coordinateModel).Result as OkObjectResult;

            //Assert
            Assert.That(result, Is.Not.Null, "An instance of 'OkObjectResult' 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(gameId, _loggedInUser.Id,
                                                            It.Is <GridCoordinate>(
                                                                gc => gc.Row == coordinateModel.Row && gc.Column == coordinateModel.Column)),
                                    Times.Once, "The 'ShootAtOpponent' of the IGameService is not called correctly.");

            Assert.That(result.Value, Is.SameAs(expectedShotResult));
        }
Exemplo n.º 2
0
        public void ShootAtOpponent_ShouldReturnBadRequestWhenAnApplicationExceptionOccurs()
        {
            //Arrange
            Guid gameId = Guid.NewGuid();
            GridCoordinateModel coordinateModel = new GridCoordinateModelBuilder().Build();

            _gameServiceMock.Setup(service =>
                                   service.ShootAtOpponent(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <GridCoordinate>()))
            .Throws <ApplicationException>();

            ActAndAssertShootAtOpponentShouldReturnBadRequest(gameId, coordinateModel);
        }
Exemplo n.º 3
0
        public void ShootAtOpponent_ShouldUseServiceToRegisterTheShot()
        {
            //Arrange
            Guid gameId = Guid.NewGuid();
            GridCoordinateModel coordinateModel = new GridCoordinateModelBuilder().Build();

            ShotResult expectedShotResult = ShotResult.CreateMissed();

            _gameServiceMock.Setup(service =>
                                   service.ShootAtOpponent(gameId, _loggedInUser.Id,
                                                           It.Is <GridCoordinate>(
                                                               gc => gc.Row == coordinateModel.Row && gc.Column == coordinateModel.Column)))
            .Returns(expectedShotResult);

            //Act
            var result = _controller.ShootAtOpponent(gameId, coordinateModel).Result as OkObjectResult;

            //Assert
            Assert.That(result, Is.Not.Null, "An instance of 'OkObjectResult' should be returned.");
            _userManagerMock.Verify();
            _gameServiceMock.Verify();
            Assert.That(result.Value, Is.SameAs(expectedShotResult));
        }