public void WhenValidCsvFileOutputProvidedShouldReturnSingleLeagueResultObject()
        {
            //Arrange
            IList <LeagueResult> leagueResultList = new List <LeagueResult>
            {
                new LeagueResult {
                    TeamName = "1. Arsenal", GoalsFor = 79, GoalsAgainst = 36
                },
                new LeagueResult {
                    TeamName = "2. Liverpool", GoalsFor = 67, GoalsAgainst = 30
                },
                new LeagueResult {
                    TeamName = "3. Manchester_U", GoalsFor = 87, GoalsAgainst = 45
                },
                new LeagueResult {
                    TeamName = "4. Newcastle", GoalsFor = 74, GoalsAgainst = 52
                },
                new LeagueResult {
                    TeamName = "5. Leeds", GoalsFor = 79, GoalsAgainst = 37
                },
                new LeagueResult {
                    TeamName = "6. Chelsea", GoalsFor = 66, GoalsAgainst = 38
                },
                new LeagueResult {
                    TeamName = "7. West_Ham", GoalsFor = 48, GoalsAgainst = 57
                }
            };
            var winningTeamExpected = new LeagueResult {
                TeamName = "7. West_Ham", GoalsFor = 48, GoalsAgainst = 57
            };

            var leagueResultParserMock = new Mock <ILeagueResultParser>();

            leagueResultParserMock.Setup(x => x.ReadIntoLeagueResults(It.IsAny <List <string> >(), It.IsAny <List <string> >())).Returns(leagueResultList);

            //Act
            var leagueResultProcessor = new LeagueResultProcessor(leagueResultParserMock.Object);
            var winningTeam           = leagueResultProcessor.FindWinningTeam(new FileOutput());

            //Assert
            Assert.IsNotNull(winningTeam);
            Assert.AreEqual(winningTeamExpected.TeamName, winningTeam.TeamName);
            Assert.AreEqual(winningTeam.GoalsFor, winningTeamExpected.GoalsFor);
            Assert.AreEqual(winningTeam.GoalsAgainst, winningTeamExpected.GoalsAgainst);
        }
Example #2
0
        //-------------------------------------------------------------------
        //Eredmények összesítése
        private void RankTeams()
        {
            int    allhomepoints;
            int    allawaypoints;
            int    allhomegoals;
            int    allawaygoals;
            int    allhomegoalsget;
            int    allawaygoalsget;
            int    allhomewins;
            int    allhomedraws;
            int    allhomelosses;
            int    allawaywins;
            int    allawaydraws;
            int    allawaylosses;
            string teamname;

            for (int n = 0; n < numberofteams; n++)
            {
                allhomepoints = (int)(from y in gameResults
                                      where y.HomeTeamID == n + 1
                                      select y.HomeTeamPoints).Sum();
                allawaypoints = (int)(from y in gameResults
                                      where y.AwayTeamID == n + 1
                                      select y.AwayTeamPoints).Sum();
                allhomegoals = (int)(from y in gameResults
                                     where y.HomeTeamID == n + 1
                                     select y.HomeTeamGoals).Sum();
                allawaygoals = (int)(from y in gameResults
                                     where y.AwayTeamID == n + 1
                                     select y.AwayTeamGoals).Sum();
                allhomegoalsget = (int)(from y in gameResults
                                        where y.HomeTeamID == n + 1
                                        select y.AwayTeamGoals).Sum();
                allawaygoalsget = (int)(from y in gameResults
                                        where y.AwayTeamID == n + 1
                                        select y.HomeTeamGoals).Sum();
                allhomewins = (from y in gameResults
                               where y.HomeTeamID == n + 1 &&
                               y.HomeTeamPoints == 3
                               select y).Count();
                allhomedraws = (from y in gameResults
                                where y.HomeTeamID == n + 1 &&
                                y.HomeTeamPoints == 1
                                select y).Count();
                allhomelosses = (from y in gameResults
                                 where y.HomeTeamID == n + 1 &&
                                 y.HomeTeamPoints == 0
                                 select y).Count();
                allawaywins = (from y in gameResults
                               where y.AwayTeamID == n + 1 &&
                               y.AwayTeamPoints == 3
                               select y).Count();
                allawaydraws = (from y in gameResults
                                where y.AwayTeamID == n + 1 &&
                                y.AwayTeamPoints == 1
                                select y).Count();
                allawaylosses = (from y in gameResults
                                 where y.AwayTeamID == n + 1 &&
                                 y.AwayTeamPoints == 0
                                 select y).Count();
                teamname = (from y in TEAMs
                            where y.ID == n + 1
                            select y.NAME).First();
                LeagueResult leagueResult = new LeagueResult();
                leagueResult.teamname            = teamname;
                leagueResult.totalpoints         = allhomepoints + allawaypoints;
                leagueResult.totalgoalsscored    = allhomegoals + allawaygoals;
                leagueResult.totalgoalsget       = allhomegoalsget + allawaygoalsget;
                leagueResult.totalgoaldifference = leagueResult.totalgoalsscored - leagueResult.totalgoalsget;
                leagueResult.totalwins           = allhomewins + allawaywins;
                leagueResult.totaldraws          = allhomedraws + allawaydraws;
                leagueResult.totallosses         = allhomelosses + allawaylosses;
                leagueResults.Add(leagueResult);
            }
        }