public void Test_ShouldReturnBuilding_WhenGivenDef(Type defType, Type expectedType) { // Arrange BuildingFactory buildingFactory = new BuildingFactory(faction, game); IStructureDef def = (IStructureDef)Activator.CreateInstance(defType); // Act IStructure <IStructureDef> building = buildingFactory.CreateNewBuilding(def); // Assert Assert.AreEqual(expectedType, building.GetType()); }
/// <summary> /// Replaces one ConstructingBuilding with an IStructure. /// </summary> /// <param name="sender">ConstructingBuilding to be replaced</param> /// <param name="eventArgs">EventArgs containing new structure's definition</param> public void ReplaceBuilding(object sender, EventArgsWithPayload <IStructureDef> eventArgs) { if (!(sender is ConstructingBuildingController structure)) { return; } // Remove old structure DespawnStructure(structure); // Add new structure BuildingFactory factory = new BuildingFactory(structure.Faction, Game); IStructure <IStructureDef> building = factory.CreateNewBuilding(structure.Def.CompletedBuildingDef); SpawnStructure(structure.StartCoords, building); }