Exemple #1
0
        public async Task BCRPFindCmdOK()
        {
            var cmd       = new Cmd();
            var cmd2      = new Cmd2();
            var processor = new CommandRequestProcessorTest(new List <ICommand> {
                cmd, cmd2
            });
            var request = new BaseCommandBotRequest <JToken>(null, cmd.UniqueName,
                                                             JToken.FromObject(new DiscussCommandBotRequest()), null, null, BotCommandContext.DiscussPostForm);
            await processor.ProcessAsync(request);

            Assert.IsTrue(cmd.DiscussCmdExecuted);
            Assert.IsFalse(cmd.EventCmdExecuted);
            Assert.IsFalse(cmd.MesCmdExecuted);
            cmd.DiscussCmdExecuted = false;

            request.ctx = BotCommandContext.EventPostForm;
            await processor.ProcessAsync(request);

            Assert.IsFalse(cmd.DiscussCmdExecuted);
            Assert.IsTrue(cmd.EventCmdExecuted);
            Assert.IsFalse(cmd.MesCmdExecuted);
            cmd.EventCmdExecuted = false;

            request.ctx = BotCommandContext.MessagingPostForm;
            await processor.ProcessAsync(request);

            Assert.IsFalse(cmd.DiscussCmdExecuted);
            Assert.IsFalse(cmd.EventCmdExecuted);
            Assert.IsTrue(cmd.MesCmdExecuted);
        }
Exemple #2
0
 protected override bool TryGetProcessor(BaseCommandBotRequest <JToken> request,
                                         out Func <BaseCommandBotRequest <JToken>, Task <BaseCommandBotResponse <ICommandResponseBody> > > func)
 {
     if (!string.IsNullOrEmpty(request.commandName))
     {
         var command = _commands.FirstOrDefault(x => x.UniqueName == request.commandName);
         if (command != null)
         {
             if (_commandProcessors.TryGetValue(request.ctx, out var commandFunc))
             {
                 func = botRequest => commandFunc(command, botRequest);
                 return(true);
             }
         }
     }
     func = null;
     return(false);
 }
Exemple #3
0
 private static BaseCommandBotRequest <TRequestBody> CreateRequest <TRequestBody>(BaseCommandBotRequest <JToken> request, TRequestBody requestBody)
 {
     return(new BaseCommandBotRequest <TRequestBody>(request.userWmid, request.commandName, requestBody, request.lng, request.token, request.ctx));
 }
Exemple #4
0
 public override Task <BaseCommandBotResponse <IEventCommandResponse> > ExecAsync(BaseCommandBotRequest <EventCommandBotRequest> request)
 {
     return(Task.FromResult(new BaseCommandBotResponse <IEventCommandResponse>
     {
         respType = CommandBotResponseType.StateCommand,
         token = request.token,
         response = new BotCommandStateResponse
         {
             message = "hello",
             state = BotCommandStateType.Success
         }
     }));
 }
 public override Task <BaseCommandBotResponse <IEventCommandResponse> > ExecAsync(BaseCommandBotRequest <EventCommandBotRequest> request)
 {
     return(Task.FromResult(new BaseCommandBotResponse <IEventCommandResponse>(CommandBotResponseType.Post,
                                                                               new EventCommandPostBotResponse
     {
         postText = "hello"
     }, request.token)));
 }
Exemple #6
0
 public Task <BaseCommandBotResponse <IEventCommandResponse> > ExecAsync(BaseCommandBotRequest <EventCommandBotRequest> request)
 {
     EventCmdExecuted = true;
     return(Task.FromResult <BaseCommandBotResponse <IEventCommandResponse> >(null));
 }
Exemple #7
0
 public virtual Task <BaseCommandBotResponse <IEventCommandResponse> > ExecAsync(BaseCommandBotRequest <EventCommandBotRequest> request)
 {
     throw new System.NotImplementedException();
 }