Пример #1
0
 public TeamOfWeekViewModel(
     int season,
     TeamOfWeek[] teamOfWeek)
 {
     Leaders = new TeamOfWeekLeadersViewModel(teamOfWeek);
     Season = season;
     Weeks = new List<Week>();
     foreach (var turn in teamOfWeek.GroupBy(x => x.Turn))
     {
         var q = from t in turn
                 from playerScore in t.PlayerScores
                 group playerScore by new
                 {
                     playerScore.Key,
                     playerScore.Value.PlayerId,
                     playerScore.Value.Name
                 } into g
                 let maxValue = g.OrderByDescending(x => x.Value.Pins).FirstOrDefault()
                 orderby maxValue.Value.Pins descending
                 select new PlayerScore(g.Key.PlayerId, g.Key.Name, maxValue.Value.Team, maxValue.Value.TeamLevel)
                 {
                     Pins = maxValue.Value.Pins,
                     Score = maxValue.Value.Score,
                     Series = maxValue.Value.Series,
                     Medals = g.SelectMany(x => x.Value.Medals).ToList()
                 };
         var week = new Week(turn.Key, q.ToList());
         Weeks.Add(week);
     }
 }
        public TeamOfWeekLeadersViewModelTest()
        {
            // Arrange
            var player1 = new Player("Daniel", "*****@*****.**", Player.Status.Active) { Id = "9876" };
            var player2 = new Player("Tomas", "*****@*****.**", Player.Status.Active) { Id = "8765" };
            var teamOfWeek1 = new TeamOfWeek(1234, 2012, 10, "Team A", "A");
            teamOfWeek1.AddResultForPlayer(player1, 1, 210);
            teamOfWeek1.AddResultForPlayer(player2, 1, 190);
            var teamOfWeek2 = new TeamOfWeek(5432, 2012, 10, "Team B", "B");
            teamOfWeek2.AddResultForPlayer(player1, 0, 220);
            teamOfWeek2.AddResultForPlayer(player2, 1, 180);

            // Act
            viewModel = new TeamOfWeekViewModel(
                2012,
                new[]
                {
                    teamOfWeek1,
                    teamOfWeek2
                });
        }