public void CheckFunctionDelete()
        {
            // Add an initial League object to the database prior to deleting
            League league = new League();

            league.LeagueId = 1;
            league.Year     = "2007";
            databaseContext.League.Add(league);
            databaseContext.SaveChanges();

            // Count the number of leagues in the database
            var preCountTask = databaseContext.League.CountAsync();

            preCountTask.Wait();
            int preCount = preCountTask.Result;

            // Create the controller and call the Create method
            LeaguesController controller = new LeaguesController(databaseContext);
            var resultTask = controller.DeleteConfirmed(1);

            resultTask.Wait();
            IActionResult result = resultTask.Result as IActionResult;

            // Count the number of leagues in the database after the change
            var postCountTask = databaseContext.League.CountAsync();

            postCountTask.Wait();
            int postCount = postCountTask.Result;

            // Check that there is one more league in the database than what was
            //  in it previous to the Create method call
            Assert.AreEqual(preCount - 1, postCount);
        }
예제 #2
0
        public async Task DeleteConfirmed_ShouldDeleteLeagueFromDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var leaguesIndexViewModel   = A.Fake <ILeaguesIndexViewModel>();
            var leaguesDetailsViewModel = A.Fake <ILeaguesDetailsViewModel>();
            var leagueRepository        = A.Fake <ILeagueRepository>();
            var sharedRepository        = A.Fake <ISharedRepository>();
            var testController          = new LeaguesController(leaguesIndexViewModel, leaguesDetailsViewModel,
                                                                leagueRepository, sharedRepository);

            int id = 1;

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

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