Ejemplo n.º 1
0
        public void GenerateSettlement_InvalidCode_Throws()
        {
            var mockRng               = RandomizationHelper.CreateMockRandomNumberGenerator();
            var mockRepo              = new Mock <ISettlementRepository>();
            var generator             = new SettlementGenerator(mockRepo.Object, mockRng.Object);
            var mockBuildingGenerator = new Mock <IBuildingNameGenerator>();

            Assert.ThrowsAsync <ArgumentException>(() => generator.GenerateSettlement(_fixture.Create <string>(), mockBuildingGenerator.Object));
        }
Ejemplo n.º 2
0
        public async Task GenerateSettlement_ValidCode_GeneratesSettlement()
        {
            var mockRng = RandomizationHelper.CreateMockRandomNumberGenerator();

            var mockRepo   = new Mock <ISettlementRepository>();
            var settlement = _fixture.Create <SettlementTypeDetails>();

            mockRepo.Setup(x => x.GetSettlement(settlement.Code)).ReturnsAsync(settlement);

            var buildingTypes = _fixture.CreateMany <BuildingTypeModel>(settlement.Buildings.Count()).ToArray();

            for (int i = 0; i < settlement.Buildings.Count(); i++)
            {
                settlement.Buildings[i].BuildingTypeId = i + 10;
                buildingTypes[i].Id = i + 10;
            }

            var mockBuildingGenerator = new Mock <IBuildingNameGenerator>();

            mockBuildingGenerator.Setup(x => x.ListBuildingTypes()).ReturnsAsync(buildingTypes);

            mockBuildingGenerator.Setup(x => x.GenerateBuildingName(It.IsAny <string>()))
            .Returns <string>((code) => Task.Run(() =>
                                                 _fixture.Build <BuildingNameResultModel>()
                                                 .With(x => x.BuildingTypeCode, code)
                                                 .Create()));

            var generator = new SettlementGenerator(mockRepo.Object, mockRng.Object);
            var result    = await generator.GenerateSettlement(settlement.Code, mockBuildingGenerator.Object);

            // Assert general result
            Assert.NotNull(result);
            Assert.AreEqual(settlement.Code, result.Code);
            Assert.AreEqual(settlement.Id, result.Id);
            Assert.AreEqual(settlement.Name, result.Name);
            mockRng.Verify(x => x.GetRandomInteger(settlement.MinSize, settlement.MaxSize), Times.AtLeastOnce);
            Assert.GreaterOrEqual(result.Population, Math.Min(settlement.MinSize, settlement.MaxSize));
            Assert.LessOrEqual(result.Population, Math.Max(settlement.MinSize, settlement.MaxSize));
            Assert.AreEqual(settlement.Buildings.Count(), result.Buildings.Count());

            // Assert buildings created
            foreach (var settlmentBuilding in settlement.Buildings)
            {
                var resultBuilding = result.Buildings.First(x => x.Key.Id == settlmentBuilding.BuildingTypeId);
                Assert.AreEqual(settlmentBuilding.MinBuildings, resultBuilding.Value.Count());

                var expectedBuildingType = buildingTypes.First(x => x.Id == settlmentBuilding.BuildingTypeId);
                Assert.AreEqual(expectedBuildingType.Code, resultBuilding.Key.Code);

                mockRng.Verify(x => x.GetRandomInteger(settlmentBuilding.MinBuildings, settlmentBuilding.MaxBuildings), Times.AtLeastOnce);
                Assert.GreaterOrEqual(resultBuilding.Value.Count, Math.Min(settlmentBuilding.MinBuildings, settlmentBuilding.MaxBuildings));
                Assert.LessOrEqual(resultBuilding.Value.Count, Math.Max(settlmentBuilding.MinBuildings, settlmentBuilding.MaxBuildings));
            }
        }
Ejemplo n.º 3
0
 void PlopSettlements()
 {
     for (int y = 1; y < mapHeight - 1; y++)
     {
         int perRow = Random.Range(1, 3);
         for (int i = 0; i < perRow; i++)
         {
             int             x        = Random.Range(0, mapWidth);
             SettlementPiece sp       = PlacePiece(settlementPiece, x, y).GetComponent <SettlementPiece>();
             Color           newColor = new Color(Random.Range(.5f, 1f), Random.Range(.5f, 1f), Random.Range(.5f, 1f));
             sp.SetValues(x, y, sg.GenerateSettlement(), newColor);
         }
     }
 }
Ejemplo n.º 4
0
    void GenerateNewSelections()
    {
        int j = Random.Range(0, 3);

        for (int i = 0; i < 3; i++)
        {
            Settlement newSett = sg.GenerateSettlement();

            if (j == i)
            {
                newSett.distance = 3;
            }
            else
            {
                newSett.distance = Random.Range(3, 9);
            }

            settlements.Add(newSett);
            SaveSettlement(newSett, i);
        }
    }