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 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 ShouldNotMoveAndThrowExceptionAndLogErrorWhenSubModuleFails() { MemoryLogger logger; MoverModule module; IBuildingModule buildingModule; IWorkerModule workerModule; ITaskModule taskModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, X = 1, Y = 1 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(true); logger = new MemoryLogger(); module = new MoverModule(logger, taskModule, workerModule, buildingModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.BeginMoveTo(1, 2, 2)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); workerModule = new MockedWorkerModule(true, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new MoverModule(logger, taskModule, workerModule, buildingModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.BeginMoveTo(1, 2, 2)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }
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 ShouldMove() { MoverModule module; IBuildingModule buildingModule; IWorkerModule workerModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Task[] result; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, X = 1, Y = 1 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); module = new MoverModule(NullLogger.Instance, taskModule, workerModule, buildingModule); schedulerModule = new MockedSchedulerModule(false, module); result = module.BeginMoveTo(1, 2, 2); Assert.IsNotNull(result); Assert.AreEqual(TaskTypeIDs.MoveTo, result.First().TaskTypeID); Assert.AreEqual(1, result.First().WorkerID); Assert.AreEqual(1, schedulerModule.Count); }
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 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 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 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 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 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 ShouldEndTasks() { IdlerModule module; IWorkerModule workerModule; ITaskModule taskModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); module = new IdlerModule(NullLogger.Instance, taskModule, workerModule); module.EndIdle(1); // nothing to check }
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 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 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 ShouldNotEndTaskWhenWorkerDoesntExists() { MemoryLogger logger; IdlerModule module; IWorkerModule workerModule; ITaskModule taskModule; logger = new MemoryLogger(); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); module = new IdlerModule(logger, taskModule, workerModule); Assert.ThrowsException <PIONotFoundException>(() => module.BeginIdle(2, 10)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
public void ShouldReturnTrueWhenWorkerIsInBuilding() { LocationCheckerModule module; IWorkerModule workerModule; IBuildingModule buildingModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 5, X = 10, Y = 10 }); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); module = new LocationCheckerModule(NullLogger.Instance, workerModule, buildingModule); Assert.IsTrue(module.WorkerIsInBuilding(1, 3)); }
public void ShouldNotTakeWhenWorkerIsAlreadyCarryingItem() { MemoryLogger logger; TakerModule module; IWorkerModule workerModule; ITaskModule taskModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1, ResourceTypeID = ResourceTypeIDs.Wood }); taskModule = new MockedTaskModule(false); logger = new MemoryLogger(); module = new TakerModule(logger, taskModule, workerModule, null, null); Assert.ThrowsException <PIOInvalidOperationException>(() => module.BeginTake(1, ResourceTypeIDs.Coal)); 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 ShouldReturnFalseWhenWorkerIsNotInBuilding() { LocationCheckerModule module; IWorkerModule workerModule; IBuildingModule buildingModule; // different planet workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 6, X = 10, Y = 10 }); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); module = new LocationCheckerModule(NullLogger.Instance, workerModule, buildingModule); Assert.IsFalse(module.WorkerIsInBuilding(1, 3)); // different X workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 5, X = 9, Y = 10 }); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); module = new LocationCheckerModule(NullLogger.Instance, workerModule, buildingModule); Assert.IsFalse(module.WorkerIsInBuilding(1, 3)); // different Y workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 5, X = 10, Y = 9 }); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); module = new LocationCheckerModule(NullLogger.Instance, workerModule, buildingModule); Assert.IsFalse(module.WorkerIsInBuilding(1, 3)); }
public void ShouldNotEndTaskWhenSubModuleFails() { MemoryLogger logger; IdlerModule module; IWorkerModule workerModule; ITaskModule taskModule; logger = new MemoryLogger(); workerModule = new MockedWorkerModule(true, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); module = new IdlerModule(logger, taskModule, workerModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.BeginIdle(1, 10)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }
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 WorkerIsInBuildingShouldThrowExceptionAndLogErrorWhenWorkerDoesntExists() { MemoryLogger logger; LocationCheckerModule module; IWorkerModule workerModule; IBuildingModule buildingModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 10, PlanetID = 5, X = 10, Y = 10 }); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); logger = new MemoryLogger(); module = new LocationCheckerModule(logger, workerModule, buildingModule); Assert.ThrowsException <PIONotFoundException>(() => module.WorkerIsInBuilding(1, 2)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
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 ShouldNotMoveWhenWorkerIsAlreadyWorking() { MemoryLogger logger; MoverModule module; IWorkerModule workerModule; ITaskModule taskModule; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false, new Task() { WorkerID = 1 }); logger = new MemoryLogger(); module = new MoverModule(logger, taskModule, workerModule, null); Assert.ThrowsException <PIOInvalidOperationException>(() => module.BeginMoveTo(1, 1, 1)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName))); }
public void ShouldEndTasks() { MoverModule module; IBuildingModule buildingModule; IWorkerModule workerModule; ITaskModule taskModule; buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, X = 1, Y = 1 }); workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); module = new MoverModule(NullLogger.Instance, taskModule, workerModule, buildingModule); module.EndMoveTo(1, 2, 2); Assert.AreEqual(2, workerModule.GetWorker(1).X); Assert.AreEqual(2, workerModule.GetWorker(1).Y); }
public void ShouldIdle() { IdlerModule module; IWorkerModule workerModule; ITaskModule taskModule; MockedSchedulerModule schedulerModule; Task result; workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 1 }); taskModule = new MockedTaskModule(false); module = new IdlerModule(NullLogger.Instance, taskModule, workerModule); schedulerModule = new MockedSchedulerModule(false, module); result = module.BeginIdle(1, 10); Assert.IsNotNull(result); Assert.AreEqual(TaskTypeIDs.Idle, result.TaskTypeID); Assert.AreEqual(1, result.WorkerID); Assert.AreEqual(1, schedulerModule.Count); }
public void WorkerIsInBuildingShouldThrowExceptionAndLogErrorWhenSubModuleFails() { MemoryLogger logger; LocationCheckerModule module; IWorkerModule workerModule; IBuildingModule buildingModule; // workerModule = new MockedWorkerModule(true, new Worker() { WorkerID = 1, PlanetID = 5, X = 10, Y = 10 }); buildingModule = new MockedBuildingModule(false, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); logger = new MemoryLogger(); module = new LocationCheckerModule(logger, workerModule, buildingModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.WorkerIsInBuilding(1, 3)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); // workerModule = new MockedWorkerModule(false, new Worker() { WorkerID = 1, PlanetID = 5, X = 10, Y = 10 }); buildingModule = new MockedBuildingModule(true, new Building() { BuildingID = 3, PlanetID = 5, X = 10, Y = 10 }); logger = new MemoryLogger(); module = new LocationCheckerModule(logger, workerModule, buildingModule); Assert.ThrowsException <PIOInternalErrorException>(() => module.WorkerIsInBuilding(1, 3)); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }