Esempio n. 1
0
        public MatchPlayer(User player, Team team)
        {
            Arg.NotNull(player, "player");
              Arg.NotNull(team, "team");

              Player = player;
              Team = team;
        }
Esempio n. 2
0
        public virtual void AddTeam(Team team)
        {
            Arg.NotNull(team, "team");

              if (Meets.Any()) {
            throw new Exception("This division already has a schedule, teams cannot be added");
              }

              if (!Teams.Contains(team)) {
            Teams.Add(team);
            team.Division = this;
              }
        }
Esempio n. 3
0
        public Meet(Team team1, Team team2, int week)
            : this()
        {
            Arg.NotNull(team1, "team1");
              Arg.NotNull(team2, "team2");
              Arg.Require(team1.Division == team2.Division, "teams must be in the same division");
              Arg.Require(week >= 0, "week must be >= 0");

              Division = team1.Division;
              Week = week;

              Teams.Add(team1);
              Teams.Add(team2);
        }
Esempio n. 4
0
 private DashboardViewModel CreateIndexViewModel(User user, Team team, IRepository repository)
 {
     var model = new DashboardViewModel();
       model.UserIsAdmin = user.IsInRole(Roles.Administrators);
       model.UserFullName = user.FullName;
       model.SkillLevelCalculation = new SkillLevelCalculationViewModel(user, repository);
       if (null != team) {
     model.CurrentSeasonStats = GetCurrentSeasonStatsViewModel(user, team);
     model.HasCurrentSeasonStats = model.CurrentSeasonStats != null;
     model.LastMeetStats = GetLastMeetStats(user, team);
     model.HasLastMeetStats = model.LastMeetStats != null;
     model.SeasonResults = GetSeasonResults(user, team);
     model.HasSeasonResults = model.SeasonResults != null;
       }
       return model;
 }
Esempio n. 5
0
 public override void Given()
 {
     var user = new User("Test", "test", "test", "test", "test");
       user.SetIdTo(id);
       authService.MockPrincipal.User = user;
       var season = new Season("Test", GameType.EightBall);
       season.SetIdTo(id);
       season.IsActive = true;
       var seasons = new List<Season>();
       seasons.Add(season);
       repository.Setup(r => r.All<Season>()).Returns(seasons.AsQueryable());
       var division = new Division("Test", DateTime.Now, season);
       var team = new Team("Test", division);
       team.SetIdTo(id);
       team.AddPlayer(user);
       repository.Init<Team>(new List<Team> { team }.AsQueryable());
 }
Esempio n. 6
0
        public override void EstablishContext()
        {
            base.EstablishContext();
              users = new List<User>();
              divisions = new List<Division>();
              teams = new List<Team>();
              matches = new List<ClubPool.Web.Models.Match>();
              meets = new List<Meet>();
              matchResults = new List<MatchResult>();
              season = DomainModelHelper.CreateTestSeason(users, divisions, teams, meets, matches, matchResults);
              adminUser = users[0];
              officerUser = users[1];
              repository.Init<Division>(divisions.AsQueryable());
              repository.Init<User>(users.AsQueryable(), true);
              repository.Init<Team>(teams.AsQueryable(), true);
              repository.Init<MatchResult>(matchResults.AsQueryable());

              foreach (var user in users) {
            user.UpdateSkillLevel(season.GameType, repository.Object);
              }
              team = teams[0];
        }
Esempio n. 7
0
 private IEnumerable<SeasonResultViewModel> GetSeasonResults(User user, Team team)
 {
     List<SeasonResultViewModel> results = null;
       var matches = from m in team.Division.Meets
             where m.Teams.Contains(team) && m.IsComplete
             orderby m.Week descending
             from match in m.Matches
             where match.Players.Where(p => p.Player == user).Any()
             select match;
       if (matches.Any()) {
     results = new List<SeasonResultViewModel>();
     foreach (var match in matches) {
       var result = new SeasonResultViewModel() {
     Player = match.Players.Where(p => p.Player != user).First().Player.FullName,
     Team = match.Meet.Teams.Where(t => t != team).First().Name,
     Win = match.Winner == user
       };
       results.Add(result);
     }
       }
       return results;
 }
Esempio n. 8
0
 private LastMeetViewModel GetLastMeetStats(User user, Team team)
 {
     LastMeetViewModel viewModel = null;
       var meet = (from m in team.Division.Meets
           where m.Teams.Contains(team) && m.IsComplete
           orderby m.Week descending
           select m).FirstOrDefault();
       if (null != meet) {
     viewModel = CreateLastMeetViewModel(meet, team);
       }
       return viewModel;
 }
Esempio n. 9
0
 private StatsViewModel GetCurrentSeasonStatsViewModel(User user, Team team)
 {
     var vm = new StatsViewModel();
       var skillLevel = user.SkillLevels.Where(sl => sl.GameType == team.Division.Season.GameType).FirstOrDefault();
       if (null != skillLevel) {
     vm.SkillLevel = skillLevel.Value;
       }
       vm.TeamId = team.Id;
       vm.TeamName = team.Name;
       var teammate = team.Players.Where(p => p != user).Single();
       vm.TeammateName = teammate.FullName;
       vm.TeammateId = teammate.Id;
       var winsAndLosses = team.GetWinsAndLossesForPlayer(user);
       vm.PersonalRecord = GetRecordText(winsAndLosses[0], winsAndLosses[1]);
       winsAndLosses = team.GetWinsAndLosses();
       vm.TeamRecord = GetRecordText(winsAndLosses[0], winsAndLosses[1]);
       return vm;
 }
Esempio n. 10
0
 private LastMeetViewModel CreateLastMeetViewModel(Meet meet, Team team)
 {
     var model = new LastMeetViewModel();
       model.OpponentTeam = meet.Teams.Where(t => t != team).Single().Name;
       var matches = new List<LastMatchViewModel>();
       foreach (var match in meet.Matches) {
     var matchvm = CreateLastMatchViewModel(match);
     matches.Add(matchvm);
       }
       model.Matches = matches;
       return model;
 }
Esempio n. 11
0
        public override void EstablishContext()
        {
            player = new User("test", "test", "test", "test", "test");
              opponent = new User("opponent", "opponent", "opponent", "opponent", "opponent");
              var season = new Season("test", GameType.EightBall);
              var division = new Division("test", DateTime.Parse("1/1/2011"), season);
              playerTeam = new Team("team1", division);
              opponentTeam = new Team("team2", division);
              playerTeam.AddPlayer(player);
              opponentTeam.AddPlayer(opponent);
              meet = new Meet(playerTeam, opponentTeam, 1);

              repository = new Mock<IRepository>();
              results = new List<MatchResult>();
              repository.Setup(r => r.All<MatchResult>()).Returns(() => results.AsQueryable());
        }
Esempio n. 12
0
 public ScheduleViewModel(IEnumerable<Meet> meets, DateTime startingDate, Team teamToHighlight = null)
 {
     Weeks = meets.GroupBy(meet => meet.Week)
     .OrderBy(g => g.Key)
     .Select(g => new ScheduleWeekViewModel() {
       Week = g.Key + 1,
       Date = startingDate.AddDays(g.Key * 7),
       Meets = g.Select(meet => new MeetViewModel(meet) {
     Highlight = (null == teamToHighlight) ? false : meet.Teams.Contains(teamToHighlight),
       })
     });
       NumberOfMeetsPerWeek = Weeks.First().Meets.Count();
 }
Esempio n. 13
0
        public override void EstablishContext()
        {
            var repository = new Mock<IRepository>();
              authenticationService = AuthHelper.CreateMockAuthenticationService();
              controller = new MeetsController(repository.Object, authenticationService);

              loggedInUser = new User("test", "test", "test", "test", "test");
              loggedInUser.SetIdTo(99);
              authenticationService.MockPrincipal.MockIdentity.IsAuthenticated = true;
              authenticationService.MockPrincipal.MockIdentity.Name = loggedInUser.Username;

              // set up a meet
              var season = new Season("s1", GameType.EightBall);
              var division = new Division("d1", DateTime.Now, season);
              var team1 = new Team("team1", division);
              team1.AddPlayer(new User("t1p1", "pass", "a", "b", "e"));
              team1.AddPlayer(new User("t1p2", "pass", "c", "d", "e"));
              var team2 = new Team("team2", division);
              team2.AddPlayer(new User("t2p1", "pass", "e", "f", "e"));
              team2.AddPlayer(new User("t2p2", "pass", "e", "f", "e"));
              meet = new Meet(team1, team2, 0);
              meet.SetIdTo(1);
              repository.Setup(r => r.Get<Meet>(meet.Id)).Returns(meet);

              var users = team1.Players.Concat(team2.Players).Concat(new List<User> { loggedInUser });
              repository.Init<User>(users.AsQueryable());
        }
Esempio n. 14
0
 private TeamViewModel CreateTeamViewModel(Team team)
 {
     var model = new TeamViewModel();
       model.Id = team.Id;
       model.Name = team.Name;
       model.Players = team.Players.Select(p => new PlayerViewModel() { Id = p.Id, Name = p.FullName }).ToList();
       var completedMatchesQuery = from meet in team.Division.Meets
                           from match in meet.Matches
                           where meet.Teams.Contains(team) && match.IsComplete
                           select match;
       model.CanDelete = !completedMatchesQuery.Any();
       return model;
 }
Esempio n. 15
0
        public override void EstablishContext()
        {
            var repository = new Mock<IRepository>();
              authService = AuthHelper.CreateMockAuthenticationService();
              controller = new UpdateMatchController(repository.Object, authService);

              loggedInUser = new User("admin", "pass", "first", "last", "email");
              loggedInUser.SetIdTo(3);
              loggedInUser.AddRole(new Role(Roles.Administrators));
              authService.MockPrincipal.MockIdentity.IsAuthenticated = true;
              authService.MockPrincipal.MockIdentity.Name = loggedInUser.Username;

              var season = new Season("test", GameType.EightBall);
              var division = new Division("test", DateTime.Parse("1/1/2011"), season);
              season.AddDivision(division);
              var team1 = new Team("team1", division);
              division.AddTeam(team1);
              player1 = new User("player1", "test", "player1", "test", "test");
              player1.SetIdTo(1);
              team1.AddPlayer(player1);
              var team2 = new Team("team2", division);
              division.AddTeam(team2);
              player2 = new User("player2", "test", "player2", "test", "test");
              player2.SetIdTo(2);
              team2.AddPlayer(player2);
              var meet = new Meet(team1, team2, 1);
              division.Meets.Add(meet);
              match = new Web.Models.Match(meet, new MatchPlayer(player1, team1), new MatchPlayer(player2, team2));
              match.SetIdTo(1);

              repository.Setup(r => r.Get<Web.Models.Match>(match.Id)).Returns(match);
              repository.Setup(r => r.Get<User>(player1.Id)).Returns(player1);
              repository.Setup(r => r.Get<User>(player2.Id)).Returns(player2);

              var player1Results = new List<MatchResult>();
              var player2Results = new List<MatchResult>();
              for (int i = 0; i < 4; i++) {
            var tempMatch = new Web.Models.Match(meet, new MatchPlayer(player1, team1), new MatchPlayer(player2, team2));
            meet.AddMatch(tempMatch);
            tempMatch.DatePlayed = DateTime.Parse("8/1/2010").AddDays(i);
            tempMatch.IsComplete = true;
            var matchResult = new MatchResult(player1, 30, 0, 3);
            player1Results.Add(matchResult);
            tempMatch.AddResult(matchResult);
            matchResult = new MatchResult(player2, 30, 0, 3);
            player2Results.Add(matchResult);
            tempMatch.AddResult(matchResult);
              }
              repository.InitAll(new List<User> { player1, player2, loggedInUser }.AsQueryable(),
            loggedInUser.Roles.AsQueryable(),
            new List<Season> { season }.AsQueryable());
              player1.UpdateSkillLevel(GameType.EightBall, repository.Object);
              player1SkillLevel = player1.SkillLevels.Where(sl => sl.GameType == GameType.EightBall).First().Value;
              player2.UpdateSkillLevel(GameType.EightBall, repository.Object);
              player2SkillLevel = player2.SkillLevels.Where(sl => sl.GameType == GameType.EightBall).First().Value;

              viewModel = new UpdateMatchViewModel() {
            Id = match.Id,
            IsForfeit = false,
            Player1Id = player1.Id,
            Player1Innings = 2,
            Player1DefensiveShots = 1,
            Player1Wins = 4,
            Player2Id = player2.Id,
            Player2Innings = 2,
            Player2DefensiveShots = 1,
            Player2Wins = 4,
            Winner = player1.Id,
            Date = "1/1/2011",
            Time = "06:00 PM"
              };
        }