public async Task DeleteGame_WhenCurrentGameIsFoundAndNotDeleted_ShouldReturnBadRequest()
        {
            // Arrange
            var  gameRepository = A.Fake <IGameRepository>();
            Game?game           = new Game();

            A.CallTo(() => gameRepository.GetGameAsync(A <int> .Ignored)).Returns(game);

            var sharedRepository = A.Fake <ISharedRepository>();

            A.CallTo(() => sharedRepository.SaveChangesAsync()).Returns(0);

            var mapper        = A.Fake <IMapper>();
            var linkGenerator = A.Fake <LinkGenerator>();
            var gameService   = A.Fake <IGameService>();

            var testController =
                new GamesController(gameRepository, sharedRepository, mapper, linkGenerator, gameService);

            int id = 1;

            // Act
            var result = await testController.DeleteGame(id);

            // Assert
            A.CallTo(() => gameRepository.GetGameAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => gameService.DeleteGameAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.Result.ShouldBeOfType <BadRequestResult>();
        }
        public async Task DeleteGame_WhenExceptionIsCaught_ShouldReturnInternalServerError()
        {
            // Arrange
            var gameRepository = A.Fake <IGameRepository>();

            A.CallTo(() => gameRepository.GetGameAsync(A <int> .Ignored)).Throws <Exception>();

            var sharedRepository = A.Fake <ISharedRepository>();
            var mapper           = A.Fake <IMapper>();
            var linkGenerator    = A.Fake <LinkGenerator>();
            var gameService      = A.Fake <IGameService>();

            var testController =
                new GamesController(gameRepository, sharedRepository, mapper, linkGenerator, gameService);

            int id = 1;

            // Act
            var result = await testController.DeleteGame(id);

            // Assert
            result.Result.ShouldBeOfType <ObjectResult>();
            ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError);
            ((ObjectResult)result.Result).Value.ShouldBe("Database failure");
        }
        public async Task DeleteGame_WhenCurrentGameIsNotFound_ShouldReturnNotFoundResult()
        {
            // Arrange
            var  gameRepository = A.Fake <IGameRepository>();
            Game?game           = null;

            A.CallTo(() => gameRepository.GetGameAsync(A <int> .Ignored)).Returns(game);

            var sharedRepository = A.Fake <ISharedRepository>();
            var mapper           = A.Fake <IMapper>();
            var linkGenerator    = A.Fake <LinkGenerator>();
            var gameService      = A.Fake <IGameService>();

            var testController =
                new GamesController(gameRepository, sharedRepository, mapper, linkGenerator, gameService);

            int id = 1;

            // Act
            var result = await testController.DeleteGame(id);

            // Assert
            A.CallTo(() => gameRepository.GetGameAsync(id)).MustHaveHappenedOnceExactly();
            result.Result.ShouldBeOfType <NotFoundObjectResult>();
            ((NotFoundObjectResult)result.Result).Value.ShouldBe($"Could not find game with ID of {id}");
        }
Пример #4
0
        public void DeleteGame_should_delete_game()
        {
            //Act
            var actionResult = _gamesController.DeleteGame(It.IsAny <int>());

            //Assert
            actionResult.Should().BeOfType <OkNegotiatedContentResult <string> >();
        }
Пример #5
0
        public void GivenAGame_WhenDeleteRequestIsReceived_ThenTheGameIsDeleted()
        {
            var game = _mockGame.Object;

            _mockGameRegistry
            .Setup(x => x.GetGame(game.Id))
            .Returns(game);

            var result = _controller.DeleteGame(game.Id) as NoContentResult;

            result.Should().NotBeNull();
            _mockGameRegistry.Verify(x => x.DeleteGame(game.Id), Times.Once);
        }
Пример #6
0
        public void IssueErrorAndMessageShouldDeleteGamesFail()
        {
            // Arrange

            // Act
            var result     = sutFailure.DeleteGame(1, baseRequest);
            var message    = ((BaseResult)((NotFoundObjectResult)result.Result.Result).Value).Message;
            var statusCode = ((NotFoundObjectResult)result.Result.Result).StatusCode;

            // Assert
            Assert.That(result.Result, Is.InstanceOf <ActionResult <Game> >());
            Assert.That(message, Is.EqualTo("Status Code 404: Game not Deleted"));
            Assert.That(statusCode, Is.EqualTo(404));
        }
Пример #7
0
        public void SuccessfullyDeleteGames()
        {
            // Arrange

            // Act
            var result     = sutSuccess.DeleteGame(1, baseRequest);
            var message    = ((BaseResult)((OkObjectResult)result.Result.Result).Value).Message;
            var statusCode = ((OkObjectResult)result.Result.Result).StatusCode;

            // Assert
            Assert.That(result.Result, Is.InstanceOf <ActionResult <Game> >());
            Assert.That(message, Is.EqualTo("Status Code 200: Game Deleted"));
            Assert.That(statusCode, Is.EqualTo(200));
        }
Пример #8
0
        public async Task DeleteGame_NegativeId_NotFoundResult()
        {
            // Arrange
            const int gameIdToDelete = -10;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Game expectedGame = GetFakeList().Where(d => d.ID == gameIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GamesController gamesController = new GamesController(context);
                var             actionResult    = (await gamesController.DeleteGame(gameIdToDelete));
                var             result          = actionResult.Result;

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Пример #9
0
        public async Task DeleteGame_ExistingId_TaskActionResultContainsDeletedGame()
        {
            // Arrange
            const int gameIdToDelete = 3;

            InitializeInmemoryDatabase(out DbContextOptions <GameReviewsContext> options, GetFakeList());
            Game expectedGame = GetFakeList().Where(d => d.ID == gameIdToDelete).FirstOrDefault();

            // Act
            using (var context = new GameReviewsContext(options))
            {
                GamesController gamesController = new GamesController(context);
                var             actionResult    = (await gamesController.DeleteGame(gameIdToDelete));
                var             result          = actionResult.Result;
                Game            actualGame      = actionResult.Value;

                // Assert
                Assert.IsNotType <NotFoundResult>(result);
                Assert.True(context.Games.Find(gameIdToDelete) == null);
                Assert.True(AreEqual(expectedGame, actualGame));
            }
        }