public void DeleteConfirmedNoId()
        {
            // Act
            ViewResult actual = controller.DeleteConfirmed(null);

            // Assert
            Assert.AreEqual("Error", actual.ViewName);
        }
Example #2
0
        public void GamesControllerDeleteConfirmed()
        {
            var gamesController = new GamesController(null);

            var result = gamesController.DeleteConfirmed(1);

            Assert.IsNotNull(result);
        }
        public void DeleteConfirmedTest()
        {
            // Arrange
            GamesController controller = new GamesController();

            // Act
            var result = controller.DeleteConfirmed(0);

            // Assert
            Assert.IsNotNull(result);
        }
        public void DeleteConfirmed_ExceptionCaught_RethrowsException()
        {
            // Arrange
            var controller = new GamesController(_service, _sharedService);

            int id = 1;

            A.CallTo(() => _service.DeleteGame(A <int> .Ignored, null)).Throws <Exception>();

            // Act
            // Assert
            Assert.ThrowsAsync <Exception>(async() => await controller.DeleteConfirmed(id));
        }
        public async void TestDelete_InvalidGame_ShouldFail(string value)
        {
            // Arrange
            GamesController controller = new GamesController(_context, _webHostEnvironment);
            int             gameId     = int.Parse(value);

            try
            {
                // Act
                var result = await controller.DeleteConfirmed(gameId);
            }
            // Assert
            catch (Exception ex)
            {
                Assert.Equal("System.ArgumentNullException", ex.GetType().ToString());
            }
        }
Example #6
0
        public async void GamesController_Game_Delete_Confirmed()
        {
            //Arrange
            var mockGameRepository = new MockGameRepository().MockDeleteGame();

            var controller = new GamesController(mockGameRepository.Object);

            //act
            var result = await controller.DeleteConfirmed(1);

            //assert

            Assert.IsAssignableFrom <ActionResult <Game> >(result);

            // mockGameRepository.VerifyGetGameByID(Times.Once());
            mockGameRepository.VerifyDeleteGame(Times.Once());
        }
Example #7
0
        public void DeleteConfirmed_ReturnRedirectToAction_WhenGameIsDeleted()
        {
            var options = new DbContextOptionsBuilder <GameDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;

            var id         = 1;
            var context    = new GameDbContext(options);
            var controller = new GamesController(context);

            SeedData(context);

            var result = (RedirectToActionResult)controller.DeleteConfirmed(id);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Equal("Index", redirectToActionResult.ActionName);
        }
        public async Task DeleteConfirmed_HappyPath()
        {
            // Arrange
            var controller = new GamesController(_service, _sharedService);

            int id = 1;

            // Act
            var result = await controller.DeleteConfirmed(id);

            // Assert
            A.CallTo(() => _service.DeleteGame(id, null)).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <RedirectToRouteResult>(result);
            var resultAsRedirectToRouteResult = result as RedirectToRouteResult;

            Assert.AreEqual("Index", resultAsRedirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual(GamesService.SelectedSeason, resultAsRedirectToRouteResult.RouteValues["seasonID"]);
        }
        public async Task DeleteConfirmed_ShouldDeleteGameFromDataStore()
        {
            // Arrange
            var gamesIndexViewModel   = A.Fake <IGamesIndexViewModel>();
            var gamesDetailsViewModel = A.Fake <IGamesDetailsViewModel>();
            var gameService           = A.Fake <IGameService>();
            var gameRepository        = A.Fake <IGameRepository>();
            var teamRepository        = A.Fake <ITeamRepository>();
            var seasonRepository      = A.Fake <ISeasonRepository>();
            var sharedRepository      = A.Fake <ISharedRepository>();
            var testController        = new GamesController(gamesIndexViewModel, gamesDetailsViewModel, gameService,
                                                            gameRepository, teamRepository, seasonRepository, sharedRepository);

            int id = 1;

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

            // Assert
            A.CallTo(() => gameService.DeleteGameAsync(id)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }