public void ShouldHarvest() { HarvesterModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Task result; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFarm = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Plank, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); module = new HarvesterModule(NullLogger.Instance, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); result = module.BeginHarvest(1); Assert.IsNotNull(result); Assert.AreEqual(TaskTypeIDs.Harvest, result.TaskTypeID); Assert.AreEqual(1, result.WorkerID); Assert.AreEqual(1, schedulerModule.Count); }
public void ShouldNotEndTaskWhenSubModuleFails() { MemoryLogger logger; TakerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, X = 10, Y = 10 }); workerModule = new MockedWorkerModule(true, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new TakerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInternalErrorException>(() => module.EndTake(1, ResourceTypeIDs.Wood)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }
public void ShouldThrowExceptionAndLogErrorWhenSubModuleFailsInGetMissingResourcesToBuild() { MemoryLogger logger; ResourceCheckerModule module; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(true); materialModule = new MockedMaterialModule(false); logger = new MemoryLogger(); module = new ResourceCheckerModule(logger, buildingModule, stackModule, null, materialModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.GetMissingResourcesToBuild(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); stackModule = new MockedStackModule(false); materialModule = new MockedMaterialModule(true); logger = new MemoryLogger(); module = new ResourceCheckerModule(logger, buildingModule, stackModule, null, materialModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.GetMissingResourcesToBuild(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }
public void ShouldNotEndTaskWhenWorkerDoesntExists() { MemoryLogger logger; StorerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { X = 10, Y = 10 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONotFoundException>(() => module.EndStore(2, ResourceTypeIDs.Wood)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
public void ShouldNotEndTaskWhenTargetFactoryDoesntExists() { MemoryLogger logger; StorerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { X = 10, Y = 10 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, ResourceTypeID = ResourceTypeIDs.Stone }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONotFoundException>(() => module.BeginStore(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); }
public void ShouldNotHarvesteWhenBuildingIsNotFarm() { HarvesterModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; MemoryLogger logger; logger = new MemoryLogger(); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFactory = false }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Plank, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); module = new HarvesterModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInvalidOperationException>(() => module.BeginHarvest(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); }
public void ShouldEndTaskWhenStackExists() { HarvesterModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Stack stack; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFarm = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); productModule = new MockedProductModule(false, new Product() { ProductID = 1, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); module = new HarvesterModule(NullLogger.Instance, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); module.EndHarvest(1); stack = stackModule.GetStack(2); Assert.AreEqual(12, stack.Quantity); }
public void ShouldReturnEmptyArrayWhenBuildingHasEnoughResourcesToBuild() { ResourceCheckerModule module; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; ResourceTypeIDs[] missingResources; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); materialModule = new MockedMaterialModule(false, new Material() { MaterialID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Material() { MaterialID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Material() { MaterialID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); module = new ResourceCheckerModule(NullLogger.Instance, buildingModule, stackModule, null, materialModule); missingResources = module.GetMissingResourcesToBuild(1); Assert.IsNotNull(missingResources); Assert.AreEqual(0, missingResources.Length); }
public void ShouldNotEndTaskWhenSubModuleFails() { MemoryLogger logger; ProducerModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IIngredientModule ingredientModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFactory = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(true); ingredientModule = new MockedIngredientModule(false); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInternalErrorException>(() => module.EndProduce(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); stackModule = new MockedStackModule(false); ingredientModule = new MockedIngredientModule(false); productModule = new MockedProductModule(true, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInternalErrorException>(() => module.EndProduce(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }
public void ShouldEndTaskWhenBuildingHasNoProduct() { HarvesterModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFarm = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); productModule = new MockedProductModule(false); taskModule = new MockedTaskModule(false); module = new HarvesterModule(NullLogger.Instance, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); module.EndHarvest(1); }
public void ShouldNotBuildWhenBuildingDoesntExistsAtPos() { MemoryLogger logger; BuilderModule module; IWorkerModule workerModule; ITaskModule taskModule; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; IBuildingTypeModule buildingTypeModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10 }); taskModule = new MockedTaskModule(false); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, RemainingBuildSteps = 5 }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { BuildingID = 2, Quantity = 10, ResourceTypeID = ResourceTypeIDs.Wood, StackID = 1 }, new Stack() { BuildingID = 2, Quantity = 10, ResourceTypeID = ResourceTypeIDs.Stone, StackID = 1 }); materialModule = new MockedMaterialModule(false, new Material() { Quantity = 1, ResourceTypeID = ResourceTypeIDs.Wood, BuildingTypeID = BuildingTypeIDs.Sawmill }, new Material() { Quantity = 2, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill }); logger = new MemoryLogger(); module = new BuilderModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule); Assert.ThrowsException <PIONotFoundException>(() => module.BeginBuild(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
public void ShouldBuild() { BuilderModule module; IWorkerModule workerModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IStackModule stackModule; IMaterialModule materialModule; Task result; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, BuildingTypeID = BuildingTypeIDs.Sawmill, RemainingBuildSteps = 5 }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { BuildingID = 2, Quantity = 10, ResourceTypeID = ResourceTypeIDs.Wood, StackID = 1 }, new Stack() { BuildingID = 2, Quantity = 10, ResourceTypeID = ResourceTypeIDs.Stone, StackID = 1 }); materialModule = new MockedMaterialModule(false, new Material() { Quantity = 1, ResourceTypeID = ResourceTypeIDs.Wood, BuildingTypeID = BuildingTypeIDs.Sawmill }, new Material() { Quantity = 2, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill }); module = new BuilderModule(NullLogger.Instance, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule); schedulerModule = new MockedSchedulerModule(false, module); result = module.BeginBuild(1); Assert.IsNotNull(result); Assert.AreEqual(TaskTypeIDs.Build, result.TaskTypeID); Assert.AreEqual(1, result.WorkerID); Assert.AreEqual(1, schedulerModule.Count); }
public void ShouldReturnTrueWhenBuildingHasEnoughResourcesToBuild() { ResourceCheckerModule module; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); materialModule = new MockedMaterialModule(false, new Material() { MaterialID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Material() { MaterialID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Material() { MaterialID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); module = new ResourceCheckerModule(NullLogger.Instance, buildingModule, stackModule, null, materialModule); Assert.IsTrue(module.HasEnoughResourcesToBuild(1)); }
public void ShouldReturnTrueWhenBuildingHasEnoughResourcesToProduce() { ResourceCheckerModule module; IBuildingModule buildingModule; IStackModule stackModule; IIngredientModule ingredientModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); ingredientModule = new MockedIngredientModule(false, new Ingredient() { IngredientID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Ingredient() { IngredientID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Ingredient() { IngredientID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); module = new ResourceCheckerModule(NullLogger.Instance, buildingModule, stackModule, ingredientModule, null); Assert.IsTrue(module.HasEnoughResourcesToProduce(1)); }
public void ShouldThrowExceptionAndLogErrorWhenSubModuleFails() { MemoryLogger logger; StorerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, X = 10, Y = 10 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10, ResourceTypeID = ResourceTypeIDs.Stone }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }); taskModule = new MockedTaskModule(true); logger = new MemoryLogger(); module = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInternalErrorException>(() => module.BeginStore(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); workerModule = new MockedWorkerModule(true, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10, ResourceTypeID = ResourceTypeIDs.Stone }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInternalErrorException>(() => module.BeginStore(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); }
public void ShouldStore() { StorerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Task result; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, X = 10, Y = 10 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10, ResourceTypeID = ResourceTypeIDs.Stone }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); taskModule = new MockedTaskModule(false); module = new StorerModule(NullLogger.Instance, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); result = module.BeginStore(1); Assert.IsNotNull(result); Assert.AreEqual(1, result.WorkerID); Assert.AreEqual(1, schedulerModule.Count); }
public void ShouldEndTaskWhenStackExists() { StorerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Stack stack; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, X = 10, Y = 10 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10, ResourceTypeID = ResourceTypeIDs.Stone }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 2, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); taskModule = new MockedTaskModule(false); module = new StorerModule(NullLogger.Instance, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); module.EndStore(1, ResourceTypeIDs.Stone); stack = stackModule.GetStack(2); Assert.AreEqual(11, stack.Quantity); //Assert.AreEqual(2, workerModule.GetWorker(1).FactoryID); }
public void ShouldNotCreateBuildingWhenPositionIsOccupied() { MemoryLogger logger; BuilderModule module; IWorkerModule workerModule; ITaskModule taskModule; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; IBuildingTypeModule buildingTypeModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10 }); taskModule = new MockedTaskModule(false); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, X = 10, Y = 10 }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill }); logger = new MemoryLogger(); stackModule = new MockedStackModule(false, new Stack() { Quantity = 10, ResourceTypeID = ResourceTypeIDs.Wood, StackID = 1 }, new Stack() { Quantity = 10, ResourceTypeID = ResourceTypeIDs.Stone, StackID = 1 }); materialModule = new MockedMaterialModule(false, new Material() { Quantity = 1, ResourceTypeID = ResourceTypeIDs.Wood, BuildingTypeID = BuildingTypeIDs.Sawmill }, new Material() { Quantity = 2, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill }); module = new BuilderModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule); Assert.ThrowsException <PIOInvalidOperationException>(() => module.BeginCreateBuilding(1, BuildingTypeIDs.Sawmill)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
public void ShouldEndBuildTasks() { BuilderModule module; IWorkerModule workerModule; ITaskModule taskModule; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; IBuildingTypeModule buildingTypeModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, BuildingTypeID = BuildingTypeIDs.Sawmill, RemainingBuildSteps = 5 }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, BuildSteps = 5 }); stackModule = new MockedStackModule(false, new Stack() { BuildingID = 2, Quantity = 10, ResourceTypeID = ResourceTypeIDs.Wood, StackID = 1 }, new Stack() { BuildingID = 2, Quantity = 10, ResourceTypeID = ResourceTypeIDs.Stone, StackID = 1 }); materialModule = new MockedMaterialModule(false, new Material() { Quantity = 1, ResourceTypeID = ResourceTypeIDs.Wood, BuildingTypeID = BuildingTypeIDs.Sawmill }, new Material() { Quantity = 2, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill }); module = new BuilderModule(NullLogger.Instance, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule); module.EndBuild(1); Assert.AreEqual(4, buildingModule.GetBuilding(2).RemainingBuildSteps); }
public void ShouldNotProduceWhenBuildingIsNotFinished() { MemoryLogger logger; ProducerModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IIngredientModule ingredientModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, RemainingBuildSteps = 10 }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFactory = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false); ingredientModule = new MockedIngredientModule(false); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIOInvalidOperationException>(() => module.BeginProduce(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); }
public void ShouldNotHarvesteWhenWorkerDoesntExists() { MemoryLogger logger; HarvesterModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFarm = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new HarvesterModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONotFoundException>(() => module.BeginHarvest(2)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); }
public void ShouldThrowExceptionAndLogErrorWhenBuildingDoesntExistsInBuildingHasEnoughResourcesToBuild() { MemoryLogger logger; ResourceCheckerModule module; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false); materialModule = new MockedMaterialModule(false); logger = new MemoryLogger(); module = new ResourceCheckerModule(logger, buildingModule, stackModule, null, materialModule); Assert.ThrowsException <PIONotFoundException>(() => module.HasEnoughResourcesToBuild(2)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
public void ShouldReturnResourcesTypesWhenBuildingHasNotEnoughResourcesToProduce() { ResourceCheckerModule module; IBuildingModule buildingModule; IStackModule stackModule; IIngredientModule ingredientModule; ResourceTypeIDs[] missingResources; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); #region when all stacks exist stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 1 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); ingredientModule = new MockedIngredientModule(false, new Ingredient() { IngredientID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Ingredient() { IngredientID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Ingredient() { IngredientID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); module = new ResourceCheckerModule(NullLogger.Instance, buildingModule, stackModule, ingredientModule, null); missingResources = module.GetMissingResourcesToProduce(1); Assert.IsNotNull(missingResources); Assert.AreEqual(1, missingResources.Length); Assert.AreEqual(ResourceTypeIDs.Stone, missingResources[0]); #endregion #region when a stack is missing stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 } ); ingredientModule = new MockedIngredientModule(false, new Ingredient() { IngredientID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Ingredient() { IngredientID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Ingredient() { IngredientID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); module = new ResourceCheckerModule(NullLogger.Instance, buildingModule, stackModule, ingredientModule, null); missingResources = module.GetMissingResourcesToProduce(1); Assert.IsNotNull(missingResources); Assert.AreEqual(1, missingResources.Length); Assert.AreEqual(ResourceTypeIDs.Coal, missingResources[0]); #endregion }
public void ShouldNotEndCreateBuildingTaskWhenSubModuleFails() { MemoryLogger logger; BuilderModule module; IWorkerModule workerModule; ITaskModule taskModule; IBuildingModule buildingModule; IStackModule stackModule; IMaterialModule materialModule; IBuildingTypeModule buildingTypeModule; logger = new MemoryLogger(); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); buildingModule = new MockedBuildingModule(false); buildingTypeModule = new MockedBuildingTypeModule(true, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { Quantity = 10, ResourceTypeID = ResourceTypeIDs.Wood, StackID = 1 }, new Stack() { Quantity = 10, ResourceTypeID = ResourceTypeIDs.Stone, StackID = 1 }); materialModule = new MockedMaterialModule(false, new Material() { Quantity = 1, ResourceTypeID = ResourceTypeIDs.Wood, BuildingTypeID = BuildingTypeIDs.Sawmill }, new Material() { Quantity = 2, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill }); module = new BuilderModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.EndCreateBuilding(1, BuildingTypeIDs.Sawmill)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); logger = new MemoryLogger(); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); buildingModule = new MockedBuildingModule(true); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill }); stackModule = new MockedStackModule(false, new Stack() { Quantity = 10, ResourceTypeID = ResourceTypeIDs.Wood, StackID = 1 }, new Stack() { Quantity = 10, ResourceTypeID = ResourceTypeIDs.Stone, StackID = 1 }); materialModule = new MockedMaterialModule(false, new Material() { Quantity = 1, ResourceTypeID = ResourceTypeIDs.Wood, BuildingTypeID = BuildingTypeIDs.Sawmill }, new Material() { Quantity = 2, ResourceTypeID = ResourceTypeIDs.Stone, BuildingTypeID = BuildingTypeIDs.Sawmill }); module = new BuilderModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.EndCreateBuilding(1, BuildingTypeIDs.Sawmill)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }
public void ShouldNotProduceWhenBuildingHasNotEnoughResourcesToProduce() { MemoryLogger logger; ProducerModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IIngredientModule ingredientModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFactory = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); #region when all stacks exist stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 1 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); ingredientModule = new MockedIngredientModule(false, new Ingredient() { IngredientID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Ingredient() { IngredientID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Ingredient() { IngredientID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONoResourcesException>(() => module.BeginProduce(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); #endregion #region when a stack is missing stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 } ); ingredientModule = new MockedIngredientModule(false, new Ingredient() { IngredientID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Ingredient() { IngredientID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Ingredient() { IngredientID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); productModule = new MockedProductModule(false, new Product() { ProductID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, Duration = 4, Quantity = 2 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONoResourcesException>(() => module.BeginProduce(1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); #endregion }
public void ShouldReturnNullWhenBuildingHasNoProduct() { ProducerModule module; IBuildingModule buildingModule; IBuildingTypeModule buildingTypeModule; IWorkerModule workerModule; IStackModule stackModule; IIngredientModule ingredientModule; IProductModule productModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Task result; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill }); buildingTypeModule = new MockedBuildingTypeModule(false, new BuildingType() { BuildingTypeID = BuildingTypeIDs.Sawmill, IsFactory = true }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); ingredientModule = new MockedIngredientModule(false, new Ingredient() { IngredientID = 0, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 5 }, new Ingredient() { IngredientID = 1, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 10 }, new Ingredient() { IngredientID = 3, BuildingTypeID = BuildingTypeIDs.Sawmill, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 6 } ); productModule = new MockedProductModule(false); taskModule = new MockedTaskModule(false); module = new ProducerModule(NullLogger.Instance, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule); schedulerModule = new MockedSchedulerModule(false, module); result = module.BeginProduce(1); Assert.IsNull(result); }
public void ShouldNotTakeWhenFactoryHasNotEnoughResourcesToTake() { MemoryLogger logger; TakerModule module; IBuildingModule buildingModule; IWorkerModule workerModule; IStackModule stackModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 2, X = 10, Y = 10 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, X = 10, Y = 10 }); #region when all stacks exist stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 2, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Stone, Quantity = 0 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new TakerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONoResourcesException>(() => module.BeginTake(1, ResourceTypeIDs.Stone)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); #endregion #region when a stack is missing stackModule = new MockedStackModule(false, new Stack() { StackID = 0, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Plank, Quantity = 10 }, new Stack() { StackID = 1, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Wood, Quantity = 10 }, new Stack() { StackID = 3, BuildingID = 1, ResourceTypeID = ResourceTypeIDs.Coal, Quantity = 10 } ); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new TakerModule(logger, taskModule, workerModule, buildingModule, stackModule); schedulerModule = new MockedSchedulerModule(false, module); Assert.ThrowsException <PIONoResourcesException>(() => module.BeginTake(1, ResourceTypeIDs.Stone)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); Assert.AreEqual(0, schedulerModule.Count); #endregion }