public void EditTeam(TeamEditVm teamModel) { var teamToEdit = GetTeam(teamModel.TeamId); validateTeam(teamModel, teamToEdit); saveTeam(teamModel, teamToEdit); }
public void CreateTeam_Should_Create_Team_When_No_Users_Are_Added() { //arrange var teamVm = new TeamEditVm { Name = "C++", Users = null }; //act _teamService.CreateTeam(teamVm); //assert _unit.Team.Get(t => t.Name == "C++").Should().NotBeNull(); }
public void CreateTeam_Should_Add_User_To_The_Team() { //arrange var user = new User { Live = LiveStatuses.Active, FirstName = "Alex", LastName = "Al", Id = 1 }; var teamVm = new TeamEditVm { Name = ".NET", Users = new List<UserVm> { new UserVm(user) } }; _unit.User.Save(user); //act _teamService.CreateTeam(teamVm); //assert _unit.Team.Load(t => t.Name == ".NET").First().Users.Count.Should().Be(1); }
public ActionResult Edit(TeamEditVm model) { if (!ModelState.IsValid) return View(model); try { _service.EditTeam(model); } catch (WarningException exception) { ModelState.AddModelError("", exception.Message); } return Json(new { redirectToUrl = Url.Action("Index") }); }
public void CreateTeam_Should_Add_Many_Users_To_The_Team() { //arrange var users = new List<User> { new User {Live = LiveStatuses.Active, FirstName = "Alex", LastName = "Al", Id = 1}, new User {Live = LiveStatuses.Active, FirstName = "Alex", LastName = "Al", Id = 2} }; var teamVm = new TeamEditVm { Name = ".NET", Users = users.Select(u => new UserVm(u)).ToList() }; users.ForEach(u => _unit.User.Save(u)); //act _teamService.CreateTeam(teamVm); //assert _unit.Team.Load(t => t.Name == ".NET").First().Users.Count.Should().Be(2); }
private void saveTeam(TeamEditVm teamVm, Team editedTeam = null) { var team = editedTeam ?? new Team(); team.Name = teamVm.Name; team.Description = teamVm.Description; team.Live = teamVm.IsDeleted ? LiveStatuses.Deleted : LiveStatuses.Active; addUsersToTeam(team, teamVm.Users); _unit.Team.Save(team); }
public void CreateTeam(TeamEditVm teamModel) { validateTeam(teamModel); saveTeam(teamModel); }
private void validateTeam(TeamEditVm teamVm, Team editedTeam = null) { var comparisonType = StringComparison.OrdinalIgnoreCase; if (editedTeam != null && editedTeam.Name.Equals(teamVm.Name, comparisonType)) { return; } if (_unit.Team.Get(t => t.Name.Equals(teamVm.Name, comparisonType)) != null) { throw new WarningException(string.Format("Team with name {0} already exists", teamVm.Name)); } }
public void EditTeam_Should_Edit_Team_When_No_Users_Are_Added() { //arrange _unit.Team.Save(new Team { Name = ".NET", Id = 1 }); var teamVm = new TeamEditVm { TeamId = 1, Name = "C++", Users = null}; //act _teamService.EditTeam(teamVm); //assert _unit.Team.Get(1).Name.ShouldBeEquivalentTo("C++"); }
public void EditTeam_Should_Delete_User_From_Team() { //arrange var users = new List<User> { new User {Live = LiveStatuses.Active, FirstName = "Alex", LastName = "Al", Id = 1}, new User {Live = LiveStatuses.Active, FirstName = "Alex", LastName = "Al", Id = 2} }; var team = new Team {Name = ".NET", Id = 1, Users = users}; var teamVm = new TeamEditVm(team) { Users = new List<UserVm> { new UserVm(users[0]) } }; users.ForEach(u => _unit.User.Save(u)); _unit.Team.Save(team); //act _teamService.EditTeam(teamVm); //assert _unit.Team.Get(1).Users.Count.ShouldBeEquivalentTo(1); }
public ActionResult Delete(TeamEditVm model) { _service.DeleteTeam(model.TeamId); return RedirectToAction("Index"); }