예제 #1
0
        public void CanHandleInChannel()
        {
            var command  = new ParametrizedCommand(InChat.Channel, "test");
            var paramses =
                new HandlerParams(null,
                                  new Update
            {
                Message = new Message
                {
                    Text = "/test@testbot",
                    Chat = new Chat {
                        Type = ChatType.Channel
                    }
                }
            }, null, "testbot");

            Assert.True(command.CanHandleInternal(paramses));

            paramses =
                new HandlerParams(null,
                                  new Update
            {
                Message = new Message
                {
                    Text = "/test@testbot",
                    Chat = new Chat {
                        Type = ChatType.Group
                    }
                }
            }, null, "testbot");
            Assert.False(command.CanHandleInternal(paramses));

            paramses =
                new HandlerParams(null,
                                  new Update
            {
                Message = new Message
                {
                    Text = "/test@testbot",
                    Chat = new Chat {
                        Type = ChatType.Supergroup
                    }
                }
            }, null, "testbot");
            Assert.False(command.CanHandleInternal(paramses));

            paramses =
                new HandlerParams(null,
                                  new Update
            {
                Message = new Message
                {
                    Text = "/test@testbot",
                    Chat = new Chat {
                        Type = ChatType.Private
                    }
                }
            }, null, "testbot");
            Assert.False(command.CanHandleInternal(paramses));
        }
예제 #2
0
        public void CanHandleByTextWithUsername()
        {
            var command  = new ParametrizedCommand("test");
            var paramses = new HandlerParams(null, new Update {
                Message = new Message {
                    Text = "/test@testbot"
                }
            },
                                             null, "testbot");

            Assert.True(command.CanHandleInternal(paramses));
        }
예제 #3
0
        public void CanFilterUserName()
        {
            var commandInChat = new ParametrizedCommand(InChat.All, "test", CommandParseMode.Both);
            var command       = new ParametrizedCommand("test", CommandParseMode.Both);

            var paramses = new HandlerParams(null, new Update {
                Message = new Message {
                    Text = "/test@testbot"
                }
            },
                                             null, "testbot");

            Assert.True(commandInChat.CanHandleInternal(paramses));
            Assert.True(command.CanHandleInternal(paramses));

            commandInChat = new ParametrizedCommand(InChat.All, "test", CommandParseMode.WithUsername);
            command       = new ParametrizedCommand("test", CommandParseMode.WithUsername);

            Assert.True(commandInChat.CanHandleInternal(paramses));
            Assert.True(command.CanHandleInternal(paramses));

            commandInChat = new ParametrizedCommand(InChat.All, "test", CommandParseMode.WithoutUsername);
            command       = new ParametrizedCommand("test", CommandParseMode.WithoutUsername);

            Assert.False(commandInChat.CanHandleInternal(paramses));
            Assert.False(command.CanHandleInternal(paramses));

            paramses = new HandlerParams(null, new Update {
                Message = new Message {
                    Text = "/test"
                }
            },
                                         null, "testbot");
            Assert.True(commandInChat.CanHandleInternal(paramses));
            Assert.True(command.CanHandleInternal(paramses));
        }