Exemplo n.º 1
0
        public ActionResult Edit(TeamViewModel team, string submit)
        {
            if (submit == "submit")
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        var dbTeam = Mapper.Map<DbTeam>(team);
                        _teamService.UpdateTeam(dbTeam);

                        return RedirectToAction("Index");
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", ex.Message);
                    }
                }
            }
            else
            {
                try
                {
                    Delete(team);
                    return RedirectToAction("Index");
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                }
            }

            return View(team);
        }
        public void Delete_NoErrors_CallsDeleteTeam()
        {
            var viewModel = new TeamViewModel
            {
                TeamId = TeamId,
            };

            sut.Edit(viewModel, "delete");

            _teamService.Received(1).DeleteTeam(Arg.Any<DbTeam>());
        }
        public void Create_MissingRequiredFieldLocation_DoesNotCallCreateTeam()
        {
            sut.ModelState.AddModelError("", "Location field is required");
            var viewModel = new TeamViewModel
            {
                TeamId = TeamId,
                Name = "Test",
                Division = "Western",
                Conference = "Madeup"
            };

            sut.Create(viewModel);

            _teamService.DidNotReceive().CreateTeam(Arg.Any<DbTeam>());
        }
        public void Create_AllRequiredFieldsPresent_CallsCreateTeam()
        {
            var viewModel = new TeamViewModel
            {
                TeamId = TeamId,
                Location = "Minnesota",
                Name = "Test",
                Division = "Western",
                Conference = "Madeup"
            };

            sut.Create(viewModel);

            _teamService.Received(1).CreateTeam(Arg.Any<DbTeam>());
        }
Exemplo n.º 5
0
 public void Delete(TeamViewModel team)
 {
     var dbTeam = Mapper.Map<DbTeam>(team);
     _teamService.DeleteTeam(dbTeam);
 }