コード例 #1
0
        public ActionResult Edit(TournamentViewModel tournamentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var tournament = tournamentViewModel.ToDomain();
                    _tournamentService.Edit(tournament);
                    return(RedirectToAction("Index"));
                }

                return(View(tournamentViewModel));
            }
            catch (TournamentValidationException ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(View(tournamentViewModel));
            }
        }
コード例 #2
0
        public async Task EditShouldReturnTournamentNotfound()
        {
            //Arrange
            const string       databaseName = "TournamentEditNotfound";
            ITournamentService service      = await GetTournamentService(databaseName);

            //Act
            int tournamentId = -1;
            TournamentFormModel expectedTournament = new TournamentFormModel()
            {
                Id    = tournamentId,
                Name  = "SofiaOpen",
                Place = "Sofia"
            };

            await service.Edit(expectedTournament);

            var actualTournament = service.ById(tournamentId);

            //Assert
            Assert.True(actualTournament == null);
        }
コード例 #3
0
        public async Task EditShouldEditTournamentByModel()
        {
            //Arrange
            const string       databaseName = "TournamentEdit";
            ITournamentService service      = await GetTournamentService(databaseName);

            //Act
            int tournamentId = 1;
            TournamentFormModel expectedTournament = new TournamentFormModel()
            {
                Id    = tournamentId,
                Name  = "SofiaOpen",
                Place = "Sofia"
            };

            await service.Edit(expectedTournament);

            var actualTournament = service.ById(tournamentId);

            //Assert
            Assert.Equal(expectedTournament.Name, actualTournament.Name);
            Assert.Equal(expectedTournament.Place, actualTournament.Place);
        }