Esempio n. 1
0
        public void ShouldNotCreateBotIfAlreadyExistsAndLogErrors()
        {
            MemoryLogger        logger;
            BotSchedulerModule  scheduler;
            IBotModule          botModule;
            IOrderManagerModule orderManagerModule;

            PIO.ClientLib.PIOServiceReference.IPIOService client;

            botModule = Substitute.For <IBotModule>();
            botModule.CreateBot(Arg.Any <int>()).Returns((x) => new Bot()
            {
                BotID = 1, WorkerID = 1
            });
            botModule.GetBotForWorker(Arg.Any <int>()).Returns((x) => new Bot()
            {
                BotID = 1, WorkerID = 1
            });
            orderManagerModule = Substitute.For <IOrderManagerModule>();
            client             = Substitute.For <PIO.ClientLib.PIOServiceReference.IPIOService>();

            logger    = new MemoryLogger();
            scheduler = new BotSchedulerModule(logger, client, botModule, orderManagerModule, 1);
            Assert.ThrowsException <PIOInvalidOperationException>(() => scheduler.CreateBot(1));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == scheduler.ModuleName)));
        }
Esempio n. 2
0
        public void ShouldNotCreateBotAndLogErrors()
        {
            MemoryLogger        logger;
            BotSchedulerModule  scheduler;
            IBotModule          botModule;
            IOrderManagerModule orderManagerModule;

            PIO.ClientLib.PIOServiceReference.IPIOService client;

            botModule = Substitute.For <IBotModule>();
            botModule.CreateBot(Arg.Any <int>()).Returns((x) => throw new Exception());
            orderManagerModule = Substitute.For <IOrderManagerModule>();
            client             = Substitute.For <PIO.ClientLib.PIOServiceReference.IPIOService>();

            logger    = new MemoryLogger();
            scheduler = new BotSchedulerModule(logger, client, botModule, orderManagerModule, 1);
            Assert.ThrowsException <PIOInternalErrorException>(() => scheduler.CreateBot(1));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == scheduler.ModuleName)));
        }
Esempio n. 3
0
        public void ShouldCreateBot()
        {
            Bot result;
            BotSchedulerModule  scheduler;
            IBotModule          botModule;
            IOrderManagerModule orderManagerModule;

            PIO.ClientLib.PIOServiceReference.IPIOService client;

            botModule = Substitute.For <IBotModule>();
            botModule.CreateBot(Arg.Any <int>()).Returns((x) => new Bot()
            {
                BotID = 1, WorkerID = 1
            });
            orderManagerModule = Substitute.For <IOrderManagerModule>();
            client             = Substitute.For <PIO.ClientLib.PIOServiceReference.IPIOService>();

            scheduler = new BotSchedulerModule(NullLogger.Instance, client, botModule, orderManagerModule, 1);
            result    = scheduler.CreateBot(1);
            Assert.IsNotNull(result);
            Assert.AreEqual(1, scheduler.Count);
        }