public void ValidConfigTest()
        {
            KarmaBotConfig xmlConfig = XmlLoader.LoadKarmaBotConfig(
                Path.Combine(testConfigDir, "ValidConfig.xml")
                );

            // Values from the XML file.
            Assert.AreEqual(@"^(\^\^(?<name>\S+)", xmlConfig.IncreaseCommandRegex);
            Assert.AreEqual(@"^VV(?<name>\S+)", xmlConfig.DecreaseCommandRegex);
            Assert.AreEqual(@"^!points\s+(?<name>\S+)", xmlConfig.QueryCommand);
        }
        public void EmptyConfigTest()
        {
            KarmaBotConfig defaultConfig = new KarmaBotConfig();

            KarmaBotConfig xmlConfig = XmlLoader.LoadKarmaBotConfig(
                Path.Combine(testConfigDir, "EmptyConfig.xml")
                );

            Assert.AreEqual(defaultConfig.IncreaseCommandRegex, xmlConfig.IncreaseCommandRegex);
            Assert.AreEqual(defaultConfig.DecreaseCommandRegex, xmlConfig.DecreaseCommandRegex);
            Assert.AreEqual(defaultConfig.QueryCommand, xmlConfig.QueryCommand);
        }
示例#3
0
        public void BadQueryCommandTest()
        {
            KarmaBotConfig uut = new KarmaBotConfig();

            uut.QueryCommand = null; // Null is bad.
            Assert.Throws <InvalidOperationException>(() => uut.Validate());

            uut.QueryCommand = string.Empty; // Empty is bad.
            Assert.Throws <InvalidOperationException>(() => uut.Validate());

            // No <name> group.
            uut.QueryCommand = "++derp";
            Assert.Throws <InvalidOperationException>(() => uut.Validate());
        }
示例#4
0
        public void BadDecreaseCommandTest()
        {
            KarmaBotConfig uut = new KarmaBotConfig();

            uut.DecreaseCommandRegex = null; // Null is bad.
            Assert.Throws <ValidationException>(() => uut.Validate());

            uut.DecreaseCommandRegex = string.Empty; // Empty is bad.
            Assert.Throws <ValidationException>(() => uut.Validate());

            // No <name> group.
            uut.DecreaseCommandRegex = "++derp";
            Assert.Throws <ValidationException>(() => uut.Validate());
        }
示例#5
0
        public void DefaultDecreaseRegexTest()
        {
            KarmaBotConfig uut = new KarmaBotConfig();

            Regex decreaseRegex = new Regex(uut.DecreaseCommandRegex);

            // --name is good.
            {
                Match goodMatch1 = decreaseRegex.Match("--derp");
                Assert.IsTrue(goodMatch1.Success);
                Assert.AreEqual("derp", goodMatch1.Groups["name"].Value);
            }

            // name-- is good.
            {
                Match goodMatch2 = decreaseRegex.Match("derp--");
                Assert.IsTrue(goodMatch2.Success);
                Assert.AreEqual("derp", goodMatch2.Groups["name"].Value);
            }

            // --name something is good.
            {
                Match goodMatch3 = decreaseRegex.Match("--derp for being terrible!");
                Assert.IsTrue(goodMatch3.Success);
                Assert.AreEqual("derp", goodMatch3.Groups["name"].Value);
            }

            // name-- something is good.
            {
                Match goodMatch4 = decreaseRegex.Match("derp-- for being a jerk!");
                Assert.IsTrue(goodMatch4.Success);
                Assert.AreEqual("derp", goodMatch4.Groups["name"].Value);
            }

            // Something in front of --name is bad
            {
                Match badMatch1 = decreaseRegex.Match(" --derp");
                Assert.IsFalse(badMatch1.Success);
            }

            // something in front of name-- is bad.
            {
                Match badMatch2 = decreaseRegex.Match("sdfdsaf derp--");
                Assert.IsFalse(badMatch2.Success);
            }
        }
示例#6
0
        public void DefaultIncreaseRegexTest()
        {
            KarmaBotConfig uut = new KarmaBotConfig();

            Regex increaseRegex = new Regex(uut.IncreaseCommandRegex);

            // ++name is good.
            {
                Match goodMatch1 = increaseRegex.Match("++derp");
                Assert.IsTrue(goodMatch1.Success);
                Assert.AreEqual("derp", goodMatch1.Groups["name"].Value);
            }

            // name++ is good.
            {
                Match goodMatch2 = increaseRegex.Match("derp++");
                Assert.IsTrue(goodMatch2.Success);
                Assert.AreEqual("derp", goodMatch2.Groups["name"].Value);
            }

            // ++name something is good.
            {
                Match goodMatch3 = increaseRegex.Match("++derp for being awesome!");
                Assert.IsTrue(goodMatch3.Success);
                Assert.AreEqual("derp", goodMatch3.Groups["name"].Value);
            }

            // name++ something is good.
            {
                Match goodMatch4 = increaseRegex.Match("derp++ for being cool!");
                Assert.IsTrue(goodMatch4.Success);
                Assert.AreEqual("derp", goodMatch4.Groups["name"].Value);
            }

            // Something in front of ++name is bad
            {
                Match badMatch1 = increaseRegex.Match(" ++derp");
                Assert.IsFalse(badMatch1.Success);
            }

            // something in front of name++ is bad.
            {
                Match badMatch2 = increaseRegex.Match("sdfdsaf derp++");
                Assert.IsFalse(badMatch2.Success);
            }
        }
示例#7
0
        public void DefaultQueryRegexTest()
        {
            KarmaBotConfig uut = new KarmaBotConfig();

            Regex queryRegex = new Regex(uut.QueryCommand);

            {
                Match goodMatch = queryRegex.Match("!karma derp");
                Assert.IsTrue(goodMatch.Success);
                Assert.AreEqual("derp", goodMatch.Groups["name"].Value);
            }

            // Characters in front are bad.
            {
                Match badMatch = queryRegex.Match("   !karma derp");
                Assert.IsFalse(badMatch.Success);
            }

            {
                Match badMatch = queryRegex.Match("asdfsad !karma derp");
                Assert.IsFalse(badMatch.Success);
            }
        }
示例#8
0
        public void DefaultConstructorValidateTest()
        {
            KarmaBotConfig uut = new KarmaBotConfig();

            Assert.DoesNotThrow(() => uut.Validate());
        }