public void ShouldGetAllBots() { BotModule module; Bot[] results; IDatabase database; database = Substitute.For <IDatabase>(); database.Execute <Bot>(Arg.Any <ISelect>()).Returns(new Bot[] { new Bot() { BotID = 1 }, new Bot() { BotID = 2 }, new Bot() { BotID = 3 } }); module = new BotModule(NullLogger.Instance, database); results = module.GetBots(); Assert.IsNotNull(results); Assert.AreEqual(3, results.Length); for (int t = 0; t < 3; t++) { Assert.IsNotNull(results[t]); Assert.AreEqual(t + 1, results[t].BotID); } }
public void ShouldNotGetAllBotsAndLogError() { BotModule module; MemoryLogger logger; IDatabase database; logger = new MemoryLogger(); database = Substitute.For <IDatabase>(); database.Execute <Bot>(Arg.Any <ISelect>()).Returns((x) => { throw new Exception(); }); module = new BotModule(logger, database); Assert.ThrowsException <PIODataException>(() => module.GetBots()); Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName))); }