public async Task SendMessage(ChatMessageViewModel messageModel)
        {
            var isCommand = _commandService.IsCommand(messageModel.Body);
            messageModel.CreatedOn = DateTime.Now;
            messageModel.Body = messageModel.Body.Trim();
            await SendMessageToAll(messageModel, isCommand);

            try
            {
                if (isCommand)
                {
                    _commandService.Handle(messageModel.Body, command =>
                    {
                        _stockSender.Send(command.Value);
                    });
                }
                else
                {
                    await _messagesRepository.Insert(new ChatMessage
                    {
                        CreatedOn = messageModel.CreatedOn,
                        UserId = messageModel.UserId,
                        Body = messageModel.Body
                    });
                }
            }
            catch (CommandException e)
            {
                await SendMessageFromBot(e.Message);
            }

        }
Esempio n. 2
0
        public void ValidCommand()
        {
            var result = commandService.IsCommand("/stock=aapl.us");

            Assert.True(result);
        }