Exemplo n.º 1
0
        private MessageController GetControllerInstance()
        {
            var mockIHttpContextAccessor = new Mock <IHttpContextAccessor>();

            var mockUserService = new Mock <IUserService>();

            mockUserService.Setup(s => s.GetCurrentUserId(mockIHttpContextAccessor.Object)).Returns(UserId);

            MessagesService messageService = new MessagesService();

            messageService.Add(Message1);
            messageService.Add(Message2);

            return(new MessageController(
                       mockUserService.Object,
                       messageService,
                       mockIHttpContextAccessor.Object));
        }
Exemplo n.º 2
0
        void AddMessage(string text)
        {
            MessagesService messagesService = new MessagesService(mockContext.Object);

            messagesService.Add(new Message
            {
                Id         = Guid.NewGuid(),
                CreateDate = DateTimeOffset.UtcNow,
                Text       = text
            });
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Index([FromBody] Message message, string connId)
        {
            message.SentDate = DateTime.Now;
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            Message result = await _service.Add(message);

            if (result != null)
            {
                // call hub
                await this._chatHub.Clients.AllExcept(connId)
                .SendAsync("ReceiveMessage", result);

                return(Ok(message));
            }
            else
            {
                return(NotFound());
            }
        }