예제 #1
0
        public void VoteOnPresidentCandidate(Citizen citizen, PresidentCandidate candidate)
        {
            var vote = new PresidentVote()
            {
                CandidateID       = candidate.ID,
                CitizenID         = citizen.ID,
                PresidentVotingID = candidate.VotingID
            };

            presidentVotingRepository.AddVote(vote);
            presidentVotingRepository.SaveChanges();
        }
예제 #2
0
        public void CandidateAsPresident(Citizen citizen, Country country)
        {
            var candidate = new PresidentCandidate()
            {
                CandidateID       = citizen.ID,
                CandidateStatusID = (int)PresidentCandidateStatusEnum.WaitingForElectionEnd,
                VotingID          = country.PresidentVotings.Last().ID
            };

            presidentVotingRepository.AddCandidate(candidate);
            presidentVotingRepository.SaveChanges();
        }
예제 #3
0
        public PresidentVote Create(PresidentCandidate candidate)
        {
            presidentVote.PresidentCandidate = candidate;
            presidentVote.PresidentVoting    = candidate.PresidentVoting;
            presidentVote.PresidentVotingID  = candidate.VotingID;
            presidentVote.CandidateID        = candidate.ID;
            candidate.PresidentVotes.Add(presidentVote);
            candidate.PresidentVoting.PresidentVotes.Add(presidentVote);

            var _return = presidentVote;

            presidentVote = createVote();
            return(_return);
        }
예제 #4
0
        public void PresidentVotingCandidateWinningTest()
        {
            var countryCreator    = new CountryDummyCreator();
            var candidatesCreator = new PresidentCandidateDummyCreator();


            countryCreator.VotingCreator.SetState(GameHelper.CurrentDay, VotingStatusEnum.Ongoing);

            var country = countryCreator.Create();

            var citizenCreator = new CitizenDummyCreator();

            var voting = country.PresidentVotings.Last();

            PresidentCandidate lastCandidate = null;



            for (int i = 0; i < 5; ++i)
            {
                candidatesCreator.setVotesNumber(10 + i);
                var candidate = candidatesCreator.Create(voting);
                voting.PresidentCandidates.Add(candidate);
                lastCandidate = candidate;
                candidates.Add(candidate);
            }

            PresidentVoting newVoting = null;

            presidentVotingRepository.Setup(x => x.Add(It.IsAny <PresidentVoting>()))
            .Callback <PresidentVoting>(v => newVoting = v);



            countrySerivce.ProcessPresidentVoting(GameHelper.CurrentDay, country, voting);

            Assert.IsTrue(country.PresidentID == lastCandidate.CandidateID);
            Assert.IsTrue(lastCandidate.CandidateStatusID == (int)PresidentCandidateStatusEnum.Approved);
            Assert.IsTrue(voting.VotingStatusID == (int)VotingStatusEnum.Finished);
            Assert.IsTrue(voting != newVoting && newVoting != null);
            Assert.IsTrue(newVoting.StartDay > GameHelper.CurrentDay);
            Assert.IsTrue(newVoting.VotingStatusID == (int)VotingStatusEnum.NotStarted);
            foreach (var candidate in candidates)
            {
                if (candidate != lastCandidate)
                {
                    Assert.IsTrue(candidate.CandidateStatusID == (int)PresidentCandidateStatusEnum.Rejected);
                }
            }
        }
예제 #5
0
        public PresidentCandidate Create(PresidentVoting voting)
        {
            presidentCandidate.PresidentVoting = voting;
            presidentCandidate.VotingID        = voting.ID;

            for (int i = 0; i < votesNumber; ++i)
            {
                voteGenerator.Create(presidentCandidate);
            }


            var _return = presidentCandidate;

            presidentCandidate = createCandidate();
            return(_return);
        }
예제 #6
0
        public MethodResult CanVoteOnPresidentCandidate(Citizen citizen, PresidentCandidate candidate)
        {
            MethodResult result;

            if (candidate.CandidateStatusID != (int)PresidentCandidateStatusEnum.WaitingForElectionEnd) //it will be checked without doing SQL
            {
                return(new MethodResult("You cannot vote on this candidate"));
            }


            if ((result = CanVoteInPresidentElections(citizen, candidate.PresidentVoting)).IsError)
            {
                return(result);
            }

            return(MethodResult.Success);
        }
예제 #7
0
        public void CandidateAsPresidentTest()
        {
            var countryCreator = new CountryDummyCreator();

            var country = countryCreator.Create();

            var citizen = new CitizenDummyCreator().Create();

            PresidentCandidate newCandidate = null;

            presidentVotingRepository.Setup(x => x.AddCandidate(It.IsAny <PresidentCandidate>()))
            .Callback <PresidentCandidate>(c => newCandidate = c);

            countrySerivce.CandidateAsPresident(citizen, country);

            Assert.IsTrue(newCandidate.CandidateID == citizen.ID);
            Assert.IsTrue(newCandidate.VotingID == country.PresidentVotings.Last().ID);
        }
예제 #8
0
 public void AddCandidate(PresidentCandidate candidate)
 {
     context.PresidentCandidates.Add(candidate);
 }
예제 #9
0
 public PresidentCandidateDummyCreator()
 {
     presidentCandidate = createCandidate();
 }