Ejemplo n.º 1
0
        public async Task EditPost_WhenIdEqualsTeamSeasonIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsCaughtAndTeamSeasonWithIdExists_ShouldRethrowException()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();

            var teamSeasonRepository = A.Fake <ITeamSeasonRepository>();

            A.CallTo(() => teamSeasonRepository.Update(A <TeamSeason> .Ignored)).Throws <DbUpdateConcurrencyException>();
            A.CallTo(() => teamSeasonRepository.TeamSeasonExists(A <int> .Ignored)).Returns(true);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                  teamSeasonRepository, sharedRepository);

            int id         = 1;
            var teamSeason = new TeamSeason
            {
                ID = 1
            };

            // Act
            var func = new Func <Task <IActionResult> >(async() => await testController.Edit(id, teamSeason));

            // Assert
            await func.ShouldThrowAsync <DbUpdateConcurrencyException>();
        }
Ejemplo n.º 2
0
        public async Task EditPost_WhenIdEqualsTeamSeasonIdAndModelStateIsNotValid_ShouldReturnTeamSeasonEditView()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();
            var teamSeasonRepository        = A.Fake <ITeamSeasonRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                teamSeasonRepository, sharedRepository);

            int id         = 1;
            var teamSeason = new TeamSeason
            {
                ID = 1
            };

            testController.ModelState.AddModelError("LongName", "Please enter a long name.");

            // Act
            var result = await testController.Edit(id, teamSeason);

            // Assert
            A.CallTo(() => teamSeasonRepository.Update(A <TeamSeason> .Ignored)).MustNotHaveHappened();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustNotHaveHappened();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(teamSeason);
        }
Ejemplo n.º 3
0
        public async Task EditPost_WhenIdEqualsTeamSeasonIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsCaughtAndTeamSeasonWithIdDoesNotExist_ShouldReturnNotFound()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();

            var teamSeasonRepository = A.Fake <ITeamSeasonRepository>();

            A.CallTo(() => teamSeasonRepository.Update(A <TeamSeason> .Ignored)).Throws <DbUpdateConcurrencyException>();
            A.CallTo(() => teamSeasonRepository.TeamSeasonExists(A <int> .Ignored)).Returns(false);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                  teamSeasonRepository, sharedRepository);

            int id         = 1;
            var teamSeason = new TeamSeason
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, teamSeason);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
Ejemplo n.º 4
0
        public async Task EditPost_WhenIdEqualsTeamSeasonIdAndModelStateIsValidAndDbUpdateConcurrencyExceptionIsNotCaught_ShouldUpdateTeamSeasonInDataStoreAndRedirectToIndexView()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();
            var teamSeasonRepository        = A.Fake <ITeamSeasonRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                teamSeasonRepository, sharedRepository);

            int id         = 1;
            var teamSeason = new TeamSeason
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, teamSeason);

            // Assert
            A.CallTo(() => teamSeasonRepository.Update(teamSeason)).MustHaveHappenedOnceExactly();
            A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
Ejemplo n.º 5
0
        public async Task EditGet_WhenIdIsNotNullAndTeamSeasonIsFound_ShouldReturnTeamSeasonEditView()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();

            var        teamSeasonRepository = A.Fake <ITeamSeasonRepository>();
            TeamSeason?teamSeason           = new TeamSeason();

            A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(A <int> .Ignored)).Returns(teamSeason);

            var sharedRepository = A.Fake <ISharedRepository>();
            var testController   = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                  teamSeasonRepository, sharedRepository);

            int?id = 1;

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

            // Assert
            A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(id.Value)).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <ViewResult>();
            ((ViewResult)result).Model.ShouldBe(teamSeason);
        }
Ejemplo n.º 6
0
        public async Task EditGet_WhenIdIsNull_ShouldReturnNotFound()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();
            var teamSeasonRepository        = A.Fake <ITeamSeasonRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                teamSeasonRepository, sharedRepository);

            int?id = null;

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

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }
Ejemplo n.º 7
0
        public async Task EditPost_WhenIdDoesNotEqualTeamSeasonId_ShouldReturnNotFound()
        {
            // Arrange
            var teamSeasonsIndexViewModel   = A.Fake <ITeamSeasonsIndexViewModel>();
            var teamSeasonsDetailsViewModel = A.Fake <ITeamSeasonsDetailsViewModel>();
            var teamSeasonRepository        = A.Fake <ITeamSeasonRepository>();
            var sharedRepository            = A.Fake <ISharedRepository>();
            var testController = new TeamSeasonsAdminController(teamSeasonsIndexViewModel, teamSeasonsDetailsViewModel,
                                                                teamSeasonRepository, sharedRepository);

            int id         = 0;
            var teamSeason = new TeamSeason
            {
                ID = 1
            };

            // Act
            var result = await testController.Edit(id, teamSeason);

            // Assert
            result.ShouldBeOfType <NotFoundResult>();
        }