Exemple #1
0
        private (List <Entity> entities, List <ReservedEntityName> reserved) prepareNameTakenTest()
        {
            var           creator  = new CitizenDummyCreator();
            List <Entity> entities = new List <Entity>()
            {
                creator.SetName("Test").Create().Entity,
                creator.SetName("Te st").Create().Entity,
            };


            entityRepository.Setup(x => x.Any(It.IsAny <Expression <Func <Entity, bool> > >()))
            .Returns <Expression <Func <Entity, bool> > >(expr => entities.Any(expr.Compile()));


            List <ReservedEntityName> reserved = new List <ReservedEntityName>()
            {
                new ReservedEntityName()
                {
                    ID = 1, Name = "Sum"
                },
                new ReservedEntityName()
                {
                    ID = 2, Name = "Su m"
                },
            };

            reservedEntityNameRepository.Setup(x => x.Any(It.IsAny <Expression <Func <ReservedEntityName, bool> > >()))
            .Returns <Expression <Func <ReservedEntityName, bool> > >(expr => reserved.Any(expr.Compile()));


            return(entities, reserved);
        }
Exemple #2
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);
        }
Exemple #3
0
        public void CanBuy_ProductsNotForCitizen_CannotBuy()
        {
            ProductTypeEnum[] forCitizen = { ProductTypeEnum.Bread, ProductTypeEnum.Weapon, ProductTypeEnum.MovingTicket, ProductTypeEnum.Tea, ProductTypeEnum.House };

            var citizen       = new CitizenDummyCreator().Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            foreach (var productType in Enums.ToArray <ProductTypeEnum>())
            {
                if (forCitizen.Contains(productType))
                {
                    continue;
                }

                var mockTrader = new Mock <ITrader>();
                mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Shop);

                var offer = offerCreator
                            .SetProduct(productType)
                            .Create();

                var result = citizenTrader.CanBuy(offer, mockTrader.Object);

                Assert.IsTrue(result.Is(TraderErrors.YouCannotBuyThat));
            }
        }
        public void HealCitizen_simple_test()
        {
            var hospital     = new HospitalDummyCreator().Create();
            var citizen      = new CitizenDummyCreator().Create();
            var healingPrice = new HealingPrice()
            {
                Cost = 12.34m, CurrencyID = 1
            };

            hospitalRepository.Setup(x => x.GetHealingPrice(It.IsAny <int>(), It.IsAny <int>())).Returns(healingPrice);
            transactionsService.Setup(x => x.PayForHealing(It.IsAny <Hospital>(), It.IsAny <Citizen>(), It.IsAny <HealingPrice>()));
            equipmentService.Setup(x => x.RemoveProductsFromEquipment(It.IsAny <ProductTypeEnum>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Equipment>()));

            hospitalService.HealCitizen(citizen, hospital);


            transactionsService.Verify(x => x.PayForHealing(
                                           It.Is <Hospital>(h => h == hospital),
                                           It.Is <Citizen>(c => c == citizen),
                                           It.Is <HealingPrice>(h => h == healingPrice)), Times.Once);

            equipmentService.Verify(e => e.RemoveProductsFromEquipment(
                                        It.Is <ProductTypeEnum>(t => t == ProductTypeEnum.MedicalSupplies),
                                        It.Is <int>(amount => amount == 1),
                                        It.Is <int>(quality => quality == hospital.Company.Quality),
                                        It.Is <Equipment>(eq => eq == hospital.Company.Entity.Equipment)), Times.Once);
        }
Exemple #5
0
        public void CanVoteOnPresidentCandidatePreviousVoting()
        {
            var country = new CountryDummyCreator()
                          .SetPresidentVotingStatus(GameHelper.CurrentDay - 7, VotingStatusEnum.Finished)
                          .Create();

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

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

            var oldVoting = country.PresidentVotings.Last();

            var newVoting = new PresidentVotingDummyCreator()
                            .SetState(GameHelper.CurrentDay, VotingStatusEnum.Ongoing)
                            .Create(country);


            var oldCandidate = new PresidentCandidateDummyCreator()
                               .Create(oldVoting);

            Assert.IsFalse(countrySerivce.CanVoteOnPresidentCandidate(citizen, oldCandidate).isSuccess);
        }
Exemple #6
0
        public void VoteOnPresidentCandidateTest()
        {
            bool          saveChangesCalled = false;
            PresidentVote addedVote         = null;

            presidentVotingRepository.Setup(x => x.AddVote(It.IsAny <PresidentVote>()))
            .Callback <PresidentVote>(v => addedVote = v);

            presidentVotingRepository.Setup(x => x.SaveChanges())
            .Callback(() => saveChangesCalled = true);

            var country = new CountryDummyCreator()
                          .SetPresidentVotingStatus(GameHelper.CurrentDay, VotingStatusEnum.Ongoing)
                          .Create();

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

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

            var voting = country.PresidentVotings.Last();

            var candidate = new PresidentCandidateDummyCreator()
                            .Create(voting);

            countrySerivce.VoteOnPresidentCandidate(citizen, candidate);

            Assert.IsTrue(saveChangesCalled);
            Assert.AreEqual(citizen.ID, addedVote.CitizenID);
            Assert.AreEqual(candidate.ID, addedVote.CandidateID);
            Assert.AreEqual(voting.ID, addedVote.PresidentVotingID);
        }
Exemple #7
0
        public void CanBuy_OfferNotInRegion_CannotBuy()
        {
            equipmentService.Setup(x => x.GetAllowedProductsForEntity(It.IsAny <EntityTypeEnum>())).Returns(new List <ProductTypeEnum>()
            {
                ProductTypeEnum.Bread
            });
            var country = new CountryDummyCreator()
                          .CreateNewRegion()
                          .CreateNewRegion()
                          .Create();

            var citizen = new CitizenDummyCreator()
                          .SetCountry(country)
                          .Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            var mockTrader = new Mock <ITrader>();

            mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Shop);

            var offer = offerCreator
                        .SetProduct(ProductTypeEnum.Bread)
                        .SetRegion(country.Regions.ElementAt(1))
                        .Create();

            var result = citizenTrader.CanBuy(offer, mockTrader.Object);

            Assert.IsTrue(result.Is(TraderErrors.NotSelledInYourRegion));
        }
Exemple #8
0
        public void CanVoteInPresidentElectionsVotedBeforeTest()
        {
            var country = new CountryDummyCreator()
                          .SetPresidentVotingStatus(GameHelper.CurrentDay, VotingStatusEnum.Ongoing)
                          .Create();

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

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

            var voting = country.PresidentVotings.Last();

            var candidate = new PresidentCandidateDummyCreator()
                            .Create(voting);

            var vote = new PresidentVoteDummyGenerator()
                       .SetVotingCitizen(citizen)
                       .Create(candidate);

            Assert.IsFalse(countrySerivce.CanVoteInPresidentElections(citizen, country.PresidentVotings.Last()).isSuccess);
        }
Exemple #9
0
        public void IsPresidentOfFalseTest()
        {
            var country = new CountryDummyCreator().Create();
            var citizen = new CitizenDummyCreator().SetCountry(country).Create();

            Assert.IsFalse(countryPresidentSerivce.IsPresidentOf(citizen, country));
        }
Exemple #10
0
        public void CanBuy_EverythingOk_Buy()
        {
            equipmentService.Setup(x => x.GetAllowedProductsForEntity(It.IsAny <EntityTypeEnum>())).Returns(new List <ProductTypeEnum>()
            {
                ProductTypeEnum.Bread
            });
            var country = new CountryDummyCreator()
                          .CreateNewRegion()
                          .CreateNewRegion()
                          .Create();

            var citizen = new CitizenDummyCreator()
                          .SetCountry(country)
                          .Create();
            var citizenTrader = new CitizenTrader(citizen.Entity, equipmentService.Object);


            var mockTrader = new Mock <ITrader>();

            mockTrader.SetupGet(x => x.TraderType).Returns(TraderTypeEnum.Shop);
            mockTrader.SetupGet(x => x.RegionID).Returns(citizen.RegionID);

            var offer = offerCreator
                        .SetProduct(ProductTypeEnum.Bread)
                        .Create();

            var result = citizenTrader.CanBuy(offer, mockTrader.Object);

            Assert.IsTrue(result.isSuccess);
        }
Exemple #11
0
        public void CanStartTradeCitizenTest()
        {
            var country     = new CountryDummyCreator().Create();
            var source      = new CitizenDummyCreator().SetCountry(country).Create().Entity;
            var destination = new CitizenDummyCreator().SetCountry(country).Create().Entity;

            Assert.IsTrue(tradeService.Object.CanStartTrade(source, destination).isSuccess);
        }
        public void CanBuy_NullHouse_Error()
        {
            var citizen = new CitizenDummyCreator().Create();

            var result = sellHouseService.CanBuy(null, citizen.Entity);

            Assert.IsTrue(result.Is(HouseErrors.HouseNotExist));
        }
Exemple #13
0
        public void CanManageSpawnTest()
        {
            var country = new CountryDummyCreator().CreateNewRegion().CreateNewRegion().Create();
            var citizen = new CitizenDummyCreator().SetCountry(country).Create();

            country.SetPresident(citizen);

            Assert.IsTrue(countryPresidentSerivce.CanManageSpawn(country, citizen.Entity, country.Regions.ElementAt(0), false).isSuccess);
        }
Exemple #14
0
        public void CanCandidateGoodCountryTest()
        {
            var countryCreator = new CountryDummyCreator();

            var country = countryCreator.Create();

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

            Assert.IsTrue(countrySerivce.CanCandidateAsPresident(citizen, country).isSuccess);
        }
        public HotelDayChangeProcessorTests()
        {
            mockProcessor          = new Mock <HotelDayChangeProcessor>(equipmentService.Object, equipmentRepository.Object);
            mockProcessor.CallBase = true;

            SingletonInit.Init();

            hotelDummyCreator   = new HotelDummyCreator();
            citizenDummyCreator = new CitizenDummyCreator();
        }
        public void CanStartWorkingTest()
        {
            jobOfferRepository.Setup(x => x.GetById(It.IsAny <int>())).
            Returns(new JobOffer());

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

            var result = companyService.CanStartWorkAt(123, citizen);

            Assert.IsFalse(result.IsError);
        }
Exemple #17
0
        public void CanManageSpawnLastRegionTrueTest()
        {
            var country = new CountryDummyCreator().CreateNewRegion().Create();

            country.Regions.ElementAt(0).CanSpawn = false;
            var citizen = new CitizenDummyCreator().SetCountry(country).Create();

            country.SetPresident(citizen);

            Assert.AreEqual("This is your last region where citizens can spawn. You cannot disable spawn here!", countryPresidentSerivce.CanManageSpawn(country, citizen.Entity, country.Regions.ElementAt(1), false)?.Errors[0]);
        }
        public void CanRemoveRequestTest()
        {
            var request           = new FriendRequestDummyCreator().Create();
            var someRandomCitizen = new CitizenDummyCreator().Create();


            Assert.IsFalse(friendService.CanRemoveRequest(request.SecondCitizen, request).isSuccess);
            Assert.IsTrue(friendService.CanRemoveRequest(request.ProposerCitizen, request).isSuccess);


            Assert.IsFalse(friendService.CanRemoveRequest(someRandomCitizen, request).isSuccess);
        }
Exemple #19
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);
        }
Exemple #20
0
        public void CanVoteInPresidentElectionsNotOngoingTest()
        {
            var country = new CountryDummyCreator()
                          .SetPresidentVotingStatus(GameHelper.CurrentDay - 1, VotingStatusEnum.NotStarted)
                          .Create();

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

            Assert.IsFalse(countrySerivce.CanVoteInPresidentElections(citizen, country.PresidentVotings.Last()).isSuccess);
        }
        public void CanStartWorkAtNoJobOfferErrorTest()
        {
            jobOfferRepository.Setup(x => x.GetById(It.IsAny <int>())).
            Returns <Entities.JobOffer>(null);

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

            var result = companyService.CanStartWorkAt(123, citizen);

            Assert.IsTrue(result.IsError);
            Assert.IsTrue(result.Errors[0].Contains("exist"));
        }
        public void CanBuy_EverythingOk_Success()
        {
            var house   = new HouseDummyCreator().SetSellOffer().Create();
            var citizen = new CitizenDummyCreator().Create();

            houseRepository.Setup(x => x.HasHouseInRegion(It.IsAny <int>(), It.IsAny <int>())).Returns(false);
            mockSellHouseService.Setup(x => x.HaveEnoughCashToBuy(It.IsAny <House>(), It.IsAny <Entity>())).Returns(true);

            var result = sellHouseService.CanBuy(house, citizen.Entity);

            Assert.IsTrue(result.isSuccess);
        }
        public void CanBuy_AlreadyHasHouse_Error()
        {
            var house   = new HouseDummyCreator().SetSellOffer().Create();
            var citizen = new CitizenDummyCreator().Create();

            houseRepository.Setup(x => x.HasHouseInRegion(It.IsAny <int>(), It.IsAny <int>())).Returns(true);
            mockSellHouseService.Setup(x => x.HaveEnoughCashToBuy(It.IsAny <House>(), It.IsAny <Entity>())).Returns(true);

            var result = sellHouseService.CanBuy(house, citizen.Entity);

            Assert.IsTrue(result.Is(HouseErrors.AlreadyHaveHouse));
        }
        public void CanStartWorkWorkingSomewhereElseTest()
        {
            jobOfferRepository.Setup(x => x.GetById(It.IsAny <int>())).
            Returns(new JobOffer());

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

            citizen.CompanyEmployee = new Entities.CompanyEmployee();

            var result = companyService.CanStartWorkAt(123, citizen);

            Assert.IsTrue(result.IsError);
            Assert.IsTrue(result.Errors[0].Contains("company"));
        }
Exemple #25
0
        public void CanCandidateWrongCitizenshipTest()
        {
            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.CanCandidateAsPresident(citizen, country).isSuccess);
        }
Exemple #26
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);
        }
        public void HealCitizen_overflow_test()
        {
            mockHospitalService.Setup(x => x.GetHealAmount(It.IsAny <int>())).Returns(10);
            var citizen = new CitizenDummyCreator().Create();

            citizen.HitPoints = 99;

            hospitalService.HealCitizenProcess(citizen, 1234);

            mockHospitalService.Verify(x => x.GetHealAmount(It.Is <int>(q => q == 1234)), Times.Once);

            Assert.AreEqual(100, citizen.HitPoints);
            Assert.IsTrue(citizen.UsedHospital);
        }
Exemple #28
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);
                }
            }
        }
Exemple #29
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);
        }
        public void HealCitizen_freeHealing_test()
        {
            var hospital     = new HospitalDummyCreator().Create();
            var citizen      = new CitizenDummyCreator().Create();
            var healingPrice = new HealingPrice()
            {
                Cost = null, CurrencyID = 1
            };

            hospitalRepository.Setup(x => x.GetHealingPrice(It.IsAny <int>(), It.IsAny <int>())).Returns(healingPrice);

            hospitalService.HealCitizen(citizen, hospital);

            transactionsService.Verify(x => x.PayForHealing(
                                           It.IsAny <Hospital>(),
                                           It.IsAny <Citizen>(),
                                           It.IsAny <HealingPrice>()), Times.Never);
        }