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)); }
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); }
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); }
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); }
public void GetNeighboursTest() { var country = new CountryDummyCreator().Create(); var startRegion = regionCreator.Create(country); var region1 = regionCreator.Create(country); var region2 = regionCreator.Create(country); var passageCreator = new PassageDummyCreator(); passageCreator.Create(startRegion, region1); passageCreator.Create(region1, startRegion); List <int> neighboursIDs = new List <int> { region1.ID, region2.ID }; var neighbours = startRegion.GetNeighbours(); foreach (var neighbour in neighbours) { Assert.IsTrue(neighboursIDs.Contains(neighbour.Region.ID)); } }
public void IsPresidentOfFalseTest() { var country = new CountryDummyCreator().Create(); var citizen = new CitizenDummyCreator().SetCountry(country).Create(); Assert.IsFalse(countryPresidentSerivce.IsPresidentOf(citizen, country)); }
public void CanManageSpawnNotCitizenTest() { var country = new CountryDummyCreator().CreateNewRegion().CreateNewRegion().Create(); var newspaper = new NewspaperDummyCreator().Create(); Assert.AreEqual("You must be a citizen to do that!", countryPresidentSerivce.CanManageSpawn(country, newspaper.Entity, country.Regions.ElementAt(0), true)?.Errors[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); }
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); }
public void CanBuildDefenseSystem_NotSameCountry_test() { var country = new CountryDummyCreator().Create(); var secondCountry = new CountryDummyCreator().Create(); Assert.AreEqual("Region does not belongs to your country!", defenseSystemService.CanBuildDefenseSystem(secondCountry.Regions.First(), country, 5).Errors[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 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); }
public void CanBuildDefenseSystem_noMoneyTest_test() { walletService.Setup(x => x.HaveMoney(It.IsAny <int>(), It.IsAny <Money[]>())).Returns(false); var country = new CountryDummyCreator().Create(); country.Regions.First().DefenseSystemQuality = 2; Assert.IsTrue(defenseSystemService.CanBuildDefenseSystem(country.Regions.First(), country, 3).Errors[0].StartsWith("Your country does not have")); }
public void CanBuildDefenseSystem_wrongEqualQuality_test() { var country = new CountryDummyCreator().Create(); country.Regions.First().DefenseSystemQuality = 2; Assert.AreEqual("You cannot construct defense system of this quality here!", defenseSystemService.CanBuildDefenseSystem(country.Regions.First(), country, 2).Errors[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 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 CanBuildDefenseSystem_everythingOK_test() { walletService.Setup(x => x.HaveMoney(It.IsAny <int>(), It.IsAny <Money[]>())).Returns(true); constructionRepository.Setup(x => x.AnyConstructionTypeBuildInRegion(It.IsAny <int>(), It.IsAny <ProductTypeEnum>())).Returns(false); var country = new CountryDummyCreator().Create(); country.Regions.First().DefenseSystemQuality = 2; Assert.IsTrue(defenseSystemService.CanBuildDefenseSystem(country.Regions.First(), country, 3).isSuccess); }
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); }
public void CanBuildDefenseSystem_alreadyBuilding_test() { walletService.Setup(x => x.HaveMoney(It.IsAny <int>(), It.IsAny <Money[]>())).Returns(true); constructionRepository.Setup(x => x.AnyConstructionTypeBuildInRegion(It.IsAny <int>(), It.IsAny <ProductTypeEnum>())).Returns(true); var country = new CountryDummyCreator().Create(); country.Regions.First().DefenseSystemQuality = 2; Assert.AreEqual("Defense system is already under construction in this region!", defenseSystemService.CanBuildDefenseSystem(country.Regions.First(), country, 3).Errors[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 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 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); }
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 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); } } }
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); }
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); }
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()); }
public void CanCreateNewspaperAsCountry() { Entity entity = new CountryDummyCreator().Create().Entity; Assert.IsFalse(newspaperService.CanCreateNewspaper(entity).IsError); }