public void LoadJsonFileNotExist() { //ARRANGE string testJsonPath = $"{_testDir}/_testfiles/BotStringsFiles/BadFile.json"; //ACT** Delegated action TestDelegate delegatedAct = new TestDelegate(() => { new BotStrings(testJsonPath); }); //ASSERT BotGeneraicException except = Assert.Throws <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo("Json file not found")); }
public void ThrowBotGenericException() { //ARRANGE string exceptMsg = "Exception message"; BotGeneraicException sutBotExcept = new BotGeneraicException(exceptMsg); //ACT** Delegated action TestDelegate delegatedAct = new TestDelegate(() => { throw sutBotExcept; }); //ASSERT BotGeneraicException except = Assert.Throws <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo(exceptMsg)); }
public void GetStringNotExist() { //ARRANGE string testJsonPath = $"{_testDir}/_testfiles/BotStringsFiles/test.json"; BotStrings sutBotStrings = new BotStrings(testJsonPath); //ACT** Delegated action TestDelegate delegatedAct = new TestDelegate(() => { sutBotStrings.getString("test4"); }); //ASSERT BotGeneraicException except = Assert.Throws <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo("test4 botstring not found")); }
public void LoadJsonFileDirectoryNoFiles() { //ARRANCE //mock configuration Mock <IConfiguration> mockConfig = new Mock <IConfiguration>(); mockConfig.SetupGet(x => x[It.IsAny <string>()]).Returns($"{_testDir}/_testfiles/BotStringsContainerNoJsonFiles"); //ACT TestDelegate delegatedAct = new TestDelegate(() => { new BotStringsContainer(mockConfig.Object); }); //ASSERT BotGeneraicException except = Assert.Throws <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo("No json files in directory")); }
public void GetContainerNotExist() { //ARRANGE //mock configuration Mock <IConfiguration> mockConfig = new Mock <IConfiguration>(); mockConfig.SetupGet(x => x[It.IsAny <string>()]).Returns($"{_testDir}/_testfiles/BotStringsContainerFiles"); //setup container BotStringsContainer sutBotStringsCntr = new BotStringsContainer(mockConfig.Object); //ACT** Delegated action TestDelegate delegatedAct = new TestDelegate(() => { sutBotStringsCntr.getContainer("file3"); }); //ASSERT BotGeneraicException except = Assert.Throws <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo("file3 container not found")); }
public void CommandModuleAttributesNotExist() { //ARRANGE //mock botstrings container Mock <IBotStringsContainer> mockBotStringsCntr = new Mock <IBotStringsContainer>(); //mock command context Mock <ICommandContext> mockCmdCntx = new Mock <ICommandContext>(); //no setups on mocks needed because it should fail earlier BotService sutBotService = new BotService(mockBotStringsCntr.Object); //ACT** Delegated action Type typeObj = typeof(HelpModule); AsyncTestDelegate delegatedAct = new AsyncTestDelegate(async() => { await Task.Run(() => sutBotService.help(mockCmdCntx.Object, typeObj)); }); //ASSERT BotGeneraicException except = Assert.ThrowsAsync <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo($"No commands in type {typeObj.Name}")); }
public void CommandsInNamespaceNotExist() { //ARRANGE //get project assembly Assembly projectAssembly = typeof(ShooterMcGavinBot.Main.Program).Assembly; //mock botstrings container Mock <IBotStringsContainer> mockBotStringsCntr = new Mock <IBotStringsContainer>(); //mock command context Mock <ICommandContext> mockCmdCntx = new Mock <ICommandContext>(); //no setups on mocks needed because it should fail earlier HelpService sutHelpService = new HelpService(projectAssembly, mockBotStringsCntr.Object); //ACT** Delegated action AsyncTestDelegate delegatedAct = new AsyncTestDelegate(async() => { await Task.Run(() => sutHelpService.help(mockCmdCntx.Object, typeof(ShooterMcGavinBot.Main.Program))); }); //ASSERT BotGeneraicException except = Assert.ThrowsAsync <BotGeneraicException>(delegatedAct); Assert.That(except.Message, Is.EqualTo("No command modules in assembly or namespace")); }