Esempio n. 1
0
        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)));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public void ShouldNotEndTaskWhenSubModuleFails()
        {
            MemoryLogger          logger;
            StorerModule          module;
            IBuildingModule       buildingModule;
            IWorkerModule         workerModule;
            IStackModule          stackModule;
            ITaskModule           taskModule;
            MockedSchedulerModule schedulerModule;


            buildingModule = new MockedBuildingModule(false, new Building()
            {
                BuildingID = 2, X = 0, Y = 0
            });

            workerModule = new MockedWorkerModule(false, new Worker()
            {
                WorkerID = 1, PlanetID = 1
            });
            stackModule     = new MockedStackModule(true);
            taskModule      = new MockedTaskModule(false);
            logger          = new MemoryLogger();
            module          = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule);
            schedulerModule = new MockedSchedulerModule(false, module);
            Assert.ThrowsException <PIOInternalErrorException>(() => module.EndStore(1, ResourceTypeIDs.Wood));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));


            workerModule = new MockedWorkerModule(true, 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 <PIOInternalErrorException>(() => module.EndStore(1, ResourceTypeIDs.Wood));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));
        }