예제 #1
0
        public void CanCandidateWrongCountryTest()
        {
            var countryCreator = new CountryDummyCreator();

            var country      = countryCreator.Create();
            var otherCountry = countryCreator.Create();

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

            Assert.IsFalse(countrySerivce.CanCandidateAsPresident(citizen, country).isSuccess);
        }
예제 #2
0
        public void CanVoteInPresidentElectionsWrongCitizenshipTest()
        {
            var countryCreator = new CountryDummyCreator();

            var country      = countryCreator.Create();
            var otherCountry = countryCreator.Create();

            var citizen = new CitizenDummyCreator()
                          .SetCountry(otherCountry)
                          .SetRegion(country.Regions.First())
                          .Create();

            Assert.IsFalse(countrySerivce.CanVoteInPresidentElections(citizen, country.PresidentVotings.Last()).isSuccess);
        }
예제 #3
0
        public void PresidentVotingSameNumberOfVotes()
        {
            var countryCreator    = new CountryDummyCreator();
            var candidatesCreator = new PresidentCandidateDummyCreator();

            candidatesCreator.setVotesNumber(10);

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

            var country = countryCreator.Create();

            var citizenCreator = new CitizenDummyCreator();

            var voting = country.PresidentVotings.Last();

            for (int i = 0; i < 5; ++i)
            {
                var candidate = candidatesCreator.Create(voting);
                voting.PresidentCandidates.Add(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 == null);
            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);
        }
예제 #4
0
        public ProductServiceTests()
        {
            productService = new ProductService(productTaxRepository.Object, countryRepository.Object);

            var countryCreator = new CountryDummyCreator();

            countries.Add(countryCreator.Create());
            countries.Add(countryCreator.Create());
            countries.Add(countryCreator.Create());
            countries.Add(countryCreator.Create());

            countryRepository.Setup(x => x.Where(It.IsAny <Expression <Func <Country, bool> > >()))
            .Returns <Expression <Func <Country, bool> > >(
                p => countries.Where(p.Compile()).AsQueryable());

            productTaxRepository.Setup(x => x.Where(It.IsAny <Expression <Func <ProductTax, bool> > >()))
            .Returns <Expression <Func <ProductTax, bool> > >(
                p => productTaxes.Where(p.Compile()).AsQueryable());
        }
예제 #5
0
        public void CanVoteInPresidentElectionsNotStartedTest()
        {
            var countryCreator = new CountryDummyCreator();

            var country = countryCreator.Create();

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

            Assert.IsFalse(countrySerivce.CanVoteInPresidentElections(citizen, country.PresidentVotings.Last()).isSuccess);
        }
예제 #6
0
        public void CanCandidateOngoingTest()
        {
            var countryCreator = new CountryDummyCreator();

            var country = countryCreator.Create();


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

            country.PresidentVotings.Last().VotingStatusID = (int)VotingStatusEnum.Ongoing;
            country.PresidentVotings.Last().StartDay       = GameHelper.CurrentDay;

            Assert.IsFalse(countrySerivce.CanCandidateAsPresident(citizen, country).isSuccess);
        }
예제 #7
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);
                }
            }
        }
예제 #8
0
        public void PresidentVotingTestNoCandidates()
        {
            var countryCreator = new CountryDummyCreator();

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

            var country = countryCreator.Create();

            var voting = country.PresidentVotings.Last();

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

            Assert.IsTrue(country.PresidentID == null);
            Assert.IsTrue(voting.VotingStatusID == (int)VotingStatusEnum.NotStarted);
            Assert.IsTrue(voting.StartDay > GameHelper.CurrentDay);
        }
예제 #9
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);
        }