コード例 #1
0
ファイル: TeamService.cs プロジェクト: rnofenko/Calendar
        public void EditTeam(TeamEditVm teamModel)
        {
            var teamToEdit = GetTeam(teamModel.TeamId);

            validateTeam(teamModel, teamToEdit);

            saveTeam(teamModel, teamToEdit);
        }
コード例 #2
0
ファイル: TeamUserTest.cs プロジェクト: rnofenko/Calendar
        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();
        }
コード例 #3
0
ファイル: TeamUserTest.cs プロジェクト: rnofenko/Calendar
        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);
        }
コード例 #4
0
ファイル: TeamController.cs プロジェクト: rnofenko/Calendar
 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") });
 }
コード例 #5
0
ファイル: TeamUserTest.cs プロジェクト: rnofenko/Calendar
        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);
        }
コード例 #6
0
ファイル: TeamService.cs プロジェクト: rnofenko/Calendar
        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);
        }
コード例 #7
0
ファイル: TeamService.cs プロジェクト: rnofenko/Calendar
        public void CreateTeam(TeamEditVm teamModel)
        {
            validateTeam(teamModel);

            saveTeam(teamModel);
        }
コード例 #8
0
ファイル: TeamService.cs プロジェクト: rnofenko/Calendar
        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));
            }
        }
コード例 #9
0
ファイル: TeamUserTest.cs プロジェクト: rnofenko/Calendar
        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++");
        }
コード例 #10
0
ファイル: TeamUserTest.cs プロジェクト: rnofenko/Calendar
        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);
        }
コード例 #11
0
ファイル: TeamController.cs プロジェクト: rnofenko/Calendar
 public ActionResult Delete(TeamEditVm model)
 {
     _service.DeleteTeam(model.TeamId);
     return RedirectToAction("Index");
 }