public void GoodFileTest() { string goodFile = Path.Combine(TestContext.CurrentContext.TestDirectory, "GoodFile.xml"); try { // Need to do this since we need a run-time value for the exe path. File.WriteAllText(goodFile, xmlString); CowSayBotConfig config = XmlLoader.LoadCowSayBotConfig(goodFile); Assert.AreEqual(@"!{%saycmd%} (?<msg>.+)", config.ListenRegex); Assert.AreEqual(cowsayLocation, config.ExeCommand); Assert.AreEqual(5, config.CoolDownTimeSeconds); Assert.AreEqual(5, config.CowFileInfoList.CommandList.Count); Assert.AreEqual("DEFAULT", config.CowFileInfoList.CommandList["cowsay"]); Assert.AreEqual("vader", config.CowFileInfoList.CommandList["vadersay"]); Assert.AreEqual("tux", config.CowFileInfoList.CommandList["tuxsay"]); Assert.AreEqual("moose", config.CowFileInfoList.CommandList["moosesay"]); Assert.AreEqual("moofasa", config.CowFileInfoList.CommandList["lionsay"]); } finally { if (File.Exists(goodFile)) { File.Delete(goodFile); } } }
public void ValidateBadCowFileInfoListTest() { CowSayBotConfig uut = new CowSayBotConfig(); uut.ListenRegex = @"^!{%saycmd%} (?<msg>.+)"; uut.ExeCommand = FakeExe; uut.CowFileInfoList.CommandList.Clear(); Assert.Throws <InvalidOperationException>(() => uut.Validate()); }
public void ValidateSuccessTest() { CowSayBotConfig uut = new CowSayBotConfig(); uut.ListenRegex = @"^!{%saycmd%} (?<msg>.+)"; uut.ExeCommand = FakeExe; uut.CowFileInfoList.CommandList["command"] = "name"; Assert.DoesNotThrow(() => uut.Validate()); }
public void ValidateBadListenRegexTest() { CowSayBotConfig uut = new CowSayBotConfig(); uut.ListenRegex = null; uut.ExeCommand = FakeExe; uut.CowFileInfoList.CommandList["command"] = "name"; Assert.Throws <InvalidOperationException>(() => uut.Validate()); uut.ListenRegex = string.Empty; Assert.Throws <InvalidOperationException>(() => uut.Validate()); uut.ListenRegex = " "; Assert.Throws <InvalidOperationException>(() => uut.Validate()); }
public void CloneTest() { CowSayBotConfig uut1 = new CowSayBotConfig(); uut1.ListenRegex = @"^!{%saycmd%} (?<msg>.+)"; uut1.ExeCommand = FakeExe; uut1.CowFileInfoList.CommandList["command"] = "name"; CowSayBotConfig uut2 = uut1.Clone(); Assert.AreNotSame(uut1.CowFileInfoList, uut2.CowFileInfoList); Assert.AreEqual(uut1.CowFileInfoList.CommandList.Count, uut2.CowFileInfoList.CommandList.Count); Assert.AreEqual(uut1.ListenRegex, uut2.ListenRegex); Assert.AreEqual(uut1.ExeCommand, uut2.ExeCommand); }
public void GoodFileTest() { string goodFile = Path.Combine(TestFilesPath, "GoodFile.xml"); CowSayBotConfig config = XmlLoader.LoadCowSayBotConfig(goodFile); Assert.AreEqual(@"!{%saycmd%} (?<msg>.+)", config.ListenRegex); Assert.AreEqual("../../Plugins/CowSayBot/TestFiles/cowsay", config.ExeCommand); Assert.AreEqual(5, config.CoolDownTimeSeconds); Assert.AreEqual(5, config.CowFileInfoList.CommandList.Count); Assert.AreEqual("DEFAULT", config.CowFileInfoList.CommandList["cowsay"]); Assert.AreEqual("vader", config.CowFileInfoList.CommandList["vadersay"]); Assert.AreEqual("tux", config.CowFileInfoList.CommandList["tuxsay"]); Assert.AreEqual("moose", config.CowFileInfoList.CommandList["moosesay"]); Assert.AreEqual("moofasa", config.CowFileInfoList.CommandList["lionsay"]); }
public void ValidateBadExeCommandTest() { CowSayBotConfig uut = new CowSayBotConfig(); uut.ListenRegex = @"^!{%saycmd%} (?<msg>.+)"; uut.ExeCommand = null; uut.CowFileInfoList.CommandList["command"] = "name"; Assert.Throws <InvalidOperationException>(() => uut.Validate()); uut.ExeCommand = string.Empty; Assert.Throws <InvalidOperationException>(() => uut.Validate()); uut.ExeCommand = " "; Assert.Throws <InvalidOperationException>(() => uut.Validate()); uut.ExeCommand = "doesNotExist"; Assert.Throws <InvalidOperationException>(() => uut.Validate()); }