Exemplo n.º 1
0
 public TeamEditVm(Team team)
 {
     TeamId = team.Id;
     Name = team.Name;
     Description = team.Description;
     Users = team.Users == null ? new List<UserVm>() : team.Users.Select(u => new UserVm(u)).ToList();
 }
Exemplo n.º 2
0
        private void addUsersToTeam(Team team, IEnumerable<UserVm> users)
        {
            if (team.Users != null) team.Users.Clear();
            if (users == null) return;

            var userIds = users.Select(u => u.UserId);
            team.Users = _unit.User.Load(u => userIds.Contains(u.Id)).ToList();
        }
Exemplo n.º 3
0
        public void Should_Add_New_Team_To_Database()
        {
            // arrange
            var quantity = _teamService.GetAllTeams().Count();
            var team = new Team {
                Name = "NewOne",
                Description = "NONE"
            };

            // act
            _teamService.CreateTeam(new TeamEditVm(team));
            var count = _teamService.GetAllTeams().Count();

            // assert
            count.ShouldBeEquivalentTo(quantity + 1);
        }
Exemplo n.º 4
0
        public void SetUpFixture()
        {
            FakeDi.Register();

            var team = new Team
            {
                Name = ".NET",
                Description = ".NET TEAM"
            };

            var repoUnit = new RepoUnit();
            Ioc.RegisterInstance<RepoUnit>(repoUnit);

            _teamService = new TeamService(repoUnit);
            Ioc.RegisterInstance<TeamService>(_teamService);

            _teamService.CreateTeam(new TeamEditVm(team));

            //Setup Team controller and mock http context
            var dummyRequestContext = new RequestContext(new Mock<HttpContextBase>().Object, new RouteData());

            _teamController = Ioc.Resolve<TeamController>();
            _teamController.Url = new UrlHelper(dummyRequestContext);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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));
            }
        }
Exemplo n.º 7
0
        public void EditTeam_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 team = new Team {Name = ".NET", Id = 1};
            var teamVm = new TeamEditVm(team) { Users = users.Select(u => new UserVm(u)).ToList()};

            users.ForEach(u => _unit.User.Save(u));
            _unit.Team.Save(team);

            //act
            _teamService.EditTeam(teamVm);

            //assert
            _unit.Team.Get(1).Users.Count.Should().Be(2);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public void EditTeam_Should_Add_User_To_The_Team()
        {
            //arrange
            var user = new User {Live = LiveStatuses.Active, FirstName = "Alex", LastName = "Al", Id = 1};
            var team = new Team { Name = ".NET", Id = 1 };
            var teamVm = new TeamEditVm(team) { Users = new List<UserVm> { new UserVm(user) } };

            _unit.User.Save(user);
            _unit.Team.Save(team);

            //act
            _teamService.EditTeam(teamVm);

            //assert
            _unit.Team.Get(1).Users.Count.Should().Be(1);
        }
Exemplo n.º 10
0
 public TeamVm(Team team)
 {
     Id = team.Id;
     Name = team.Name;
 }