コード例 #1
0
        public void CloneTest()
        {
            CtcpPingHandlerConfig config1 = new CtcpPingHandlerConfig();
            CtcpPingHandlerConfig clone   = config1.Clone();

            Assert.AreNotSame(config1, clone);
        }
コード例 #2
0
        public void DefaultValueTest()
        {
            CtcpPingHandlerConfig uut = new CtcpPingHandlerConfig();

            Assert.AreEqual(0, uut.CoolDown);
            Assert.AreEqual(RegexOptions.None, uut.RegexOptions);
            Assert.AreEqual(ResponseOptions.PmsOnly, uut.ResponseOption);
            Assert.IsFalse(uut.RespondToSelf);
        }
コード例 #3
0
        private void AddCtcpPingHandler()
        {
            CtcpPingHandlerConfig config = new CtcpPingHandlerConfig
            {
                LineRegex      = ".+",
                LineAction     = this.HandlerCtcpPingHandler,
                ResponseOption = ResponseOptions.PmsOnly
            };

            CtcpPingHandler handler = new CtcpPingHandler(config);

            this.handlers.Add(handler);
        }
コード例 #4
0
        public void ConstructionTest()
        {
            CtcpPingHandlerConfig config = new CtcpPingHandlerConfig
            {
                LineRegex  = @"!bot\s+help",
                LineAction = this.MessageFunction
            };

            CtcpPingHandler uut = new CtcpPingHandler(
                config
                );

            // Keep Handling should be true by default.
            Assert.IsTrue(uut.KeepHandling);
        }
コード例 #5
0
        public void TestMisMatchedMessage()
        {
            CtcpPingHandlerConfig config = new CtcpPingHandlerConfig
            {
                LineRegex  = @"\d+",
                LineAction = this.MessageFunction
            };

            CtcpPingHandler uut = new CtcpPingHandler(
                config
                );

            // Does not match pattern.  No response expected.
            const string expectedMessage = "hello world!";
            string       ircString       = TestHelpers.ConstructCtcpPingString(remoteUser, this.ircConfig.Nick, expectedMessage);

            uut.HandleEvent(this.ConstructArgs(ircString));

            Assert.IsNull(this.responseReceived);
        }
コード例 #6
0
        // ---------------- Test Helpers ----------------

        private void DoGoodMessageTest(string user, string channel)
        {
            CtcpPingHandlerConfig config = new CtcpPingHandlerConfig
            {
                LineRegex  = @"!bot\s+help",
                LineAction = this.MessageFunction
            };

            CtcpPingHandler uut = new CtcpPingHandler(
                config
                );

            const string expectedMessage = "!bot help";

            string ircString = TestHelpers.ConstructCtcpPingString(user, channel, expectedMessage);

            uut.HandleEvent(this.ConstructArgs(ircString));

            Assert.AreEqual(user, this.responseReceived.Channel);   // Need to send a message to the user that PM'ed us.
            Assert.AreEqual(user, this.responseReceived.User);
            Assert.AreEqual(expectedMessage, this.responseReceived.Message);
        }
コード例 #7
0
        public void IgnoreMessageTest()
        {
            const string expectedMessage = "!bot help";

            CtcpPingHandlerConfig config = new CtcpPingHandlerConfig
            {
                LineRegex     = @".+",
                LineAction    = this.MessageFunction,
                RespondToSelf = false
            };

            CtcpPingHandler uut = new CtcpPingHandler(
                config
                );

            // Instead of action string, create a message string.
            string ircString = TestHelpers.ConstructMessageString(remoteUser, this.ircConfig.Nick, expectedMessage);

            uut.HandleEvent(this.ConstructArgs(ircString));

            Assert.IsNull(this.responseReceived);
        }
コード例 #8
0
        public void ValidateTest()
        {
            CtcpPingHandlerConfig config = new CtcpPingHandlerConfig();

            // No action should not validate.
            config.LineAction = null;
            config.LineRegex  = @".+";
            Assert.Throws <ListedValidationException>(() => config.Validate());

            // Empty regex should not validate.
            config.LineAction = delegate(CtcpPingHandlerArgs args)
            {
            };
            config.LineRegex = string.Empty;
            Assert.Throws <ListedValidationException>(() => config.Validate());

            // Null regex should not validate.
            config.LineAction = delegate(CtcpPingHandlerArgs args)
            {
            };
            config.LineRegex = null;
            Assert.Throws <ListedValidationException>(() => config.Validate());

            // Cooldown can not be less than 0.
            config.LineAction = delegate(CtcpPingHandlerArgs args)
            {
            };
            config.LineRegex = @".+";
            config.CoolDown  = -1;
            Assert.Throws <ListedValidationException>(() => config.Validate());

            // This should validate.
            config.LineAction = delegate(CtcpPingHandlerArgs args)
            {
            };
            config.LineRegex = @".+";
            config.CoolDown  = 1;
            Assert.DoesNotThrow(() => config.Validate());
        }