private List <CandidateModel> ConvertCandidates(ElectionResultsData electionResultsData) { electionResultsData.Candidates = StatisticsAggregator.CalculatePercentagesForCandidates( electionResultsData.Candidates, electionResultsData.Candidates.Sum(c => c.Votes)); var candidates = electionResultsData.Candidates.Select(c => new CandidateModel { Id = c.Id, ImageUrl = c.ImageUrl, Name = c.Name, Percentage = c.Percentage, Votes = c.Votes }).ToList(); return(candidates); }
public void set_percentages_for_each_candidate(int c1Votes, decimal c1Percentage, int c2Votes, decimal c2Percentage, int c3Votes, decimal c3Percentage) { var candidatesResultsParser = new TestableCandidatesResultsParser(null) { ParsedCandidates = CreateListOfCandidatesWithVotes(c1Votes, c2Votes, c3Votes) }; var electionResultsData = new ElectionResultsData { Candidates = CreateListOfCandidatesWithVotes(c1Votes, c2Votes, c3Votes) }; var sumOfVotes = candidatesResultsParser.ParsedCandidates.Sum(c => c.Votes); StatisticsAggregator.CalculatePercentagesForCandidates(electionResultsData, sumOfVotes); electionResultsData.Candidates[0].Percentage.Should().Be(c1Percentage); electionResultsData.Candidates[1].Percentage.Should().Be(c2Percentage); electionResultsData.Candidates[2].Percentage.Should().Be(c3Percentage); }