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);
                }
            }
        }
示例#2
0
        public void ValidateBadCowFileInfoListTest()
        {
            CowSayBotConfig uut = new CowSayBotConfig();

            uut.ListenRegex = @"^!{%saycmd%} (?<msg>.+)";
            uut.ExeCommand  = FakeExe;
            uut.CowFileInfoList.CommandList.Clear();

            Assert.Throws <InvalidOperationException>(() => uut.Validate());
        }
示例#3
0
        public void ValidateSuccessTest()
        {
            CowSayBotConfig uut = new CowSayBotConfig();

            uut.ListenRegex = @"^!{%saycmd%} (?<msg>.+)";
            uut.ExeCommand  = FakeExe;
            uut.CowFileInfoList.CommandList["command"] = "name";

            Assert.DoesNotThrow(() => uut.Validate());
        }
示例#4
0
        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());
        }
示例#5
0
        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);
        }
示例#6
0
        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"]);
        }
示例#7
0
        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());
        }