Example #1
0
        public void ShouldSumVotesForAllConstituencies()
        {
            //Given
            IDataRepository repository    = _ioc.Resolve <IDataRepository>();
            int             candidateId   = 1;
            string          candidateName = "Adam Kowalski";

            repository.Add(new CandidatesModel()
            {
                Id = candidateId, Name = candidateName
            });
            repository.Add(new ConstituencyModel()
            {
                Id = 1, Name = "Okreg 1"
            });
            repository.Add(new ConstituencyModel()
            {
                Id = 2, Name = "Okreg 2"
            });

            var firstConstituencyVotes   = 10;
            var secondConstituencyVotes  = 7;
            var excpectedVotes           = firstConstituencyVotes + secondConstituencyVotes;
            var firstConstituencyResults = new List <CandidateResults>();

            firstConstituencyResults.Add(new CandidateResults()
            {
                CandidateId   = 1,
                NumberOfVotes = firstConstituencyVotes
            });
            var secondConstituencyResults = new List <CandidateResults>();

            secondConstituencyResults.Add(new CandidateResults()
            {
                CandidateId   = 1,
                NumberOfVotes = secondConstituencyVotes
            });

            VotesReport firstConstituencyVotingReport = new VotesReport()
            {
                ConstituencyId = 1,
                Votes          =
                    firstConstituencyResults.Select(
                        c => new CandidateVotes()
                {
                    CandidateId = c.CandidateId, Amount = c.NumberOfVotes
                })
            };

            VotesReport secondConstituencyVotingReport = new VotesReport()
            {
                ConstituencyId = 2,
                Votes          =
                    secondConstituencyResults.Select(
                        c => new CandidateVotes()
                {
                    CandidateId = c.CandidateId, Amount = c.NumberOfVotes
                })
            };

            //when
            _votingService.SendVotes(firstConstituencyVotingReport);
            _votingService.SendVotes(secondConstituencyVotingReport);
            var votingSummary =
                _votingService.GetVotingSummary(null).AggregatedVoteses.ToArray().First(c => c.CandidateId == 1).Amount;

            //Then
            Assert.AreEqual(excpectedVotes, votingSummary);
        }