Esempio n. 1
0
        public async void Returns_ThreadOutWithMessages_when_ThreadExistsAndContainsMessages()
        {
            ThreadOut threadOut = new ThreadOut
            {
                ID       = Guid.NewGuid(),
                Messages = new List <MessageOut>()
                {
                    new MessageOut
                    {
                        ID       = Guid.NewGuid(),
                        SentDate = DateTime.Now
                    },
                    new MessageOut
                    {
                        ID       = Guid.NewGuid(),
                        SentDate = DateTime.Now
                    }
                }
            };

            StatusCode <ThreadOut> status         = new StatusCode <ThreadOut>(StatusCodes.Status200OK, threadOut);
            Mock <IMessageService> messageService = new Mock <IMessageService>();

            messageService.Setup(_ => _.GetMessagesByThreadAndFilterAndUser(It.IsAny <Guid>(), It.IsAny <MessageFilter>(), It.IsAny <string>()))
            .Returns(Task.FromResult(status));

            MessagesController messagesController = new MessagesController(messageService.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME));

            messagesController.Authenticate(ADMIN_USERNAME);

            MessageFilter messageFilter = new MessageFilter
            {
                NumberOfLastMessage = 5
            };

            IActionResult result = await messagesController.GetMessagesFromThread(Guid.NewGuid(), messageFilter);

            Assert.NotNull(result);
            OkObjectResult okObjectResult = result as OkObjectResult;

            Assert.NotNull(okObjectResult);
            Assert.NotNull(okObjectResult.Value);
            Assert.IsType <ThreadOut>(okObjectResult.Value);
            Assert.Equal(2, (okObjectResult.Value as ThreadOut).Messages.Count);
        }
Esempio n. 2
0
        public async void Returns_OkObjectResult200_when_ThreadExistsAndContainsMessages()
        {
            StatusCode <ThreadOut> status         = new StatusCode <ThreadOut>(StatusCodes.Status200OK);
            Mock <IMessageService> messageService = new Mock <IMessageService>();

            messageService.Setup(_ => _.GetMessagesByThreadAndFilterAndUser(It.IsAny <Guid>(), It.IsAny <MessageFilter>(), It.IsAny <string>()))
            .Returns(Task.FromResult(status));

            MessagesController messagesController = new MessagesController(messageService.Object, UserManagerHelper.GetUserManager(ADMIN_USERNAME));

            messagesController.Authenticate(ADMIN_USERNAME);

            MessageFilter messageFilter = new MessageFilter
            {
                NumberOfLastMessage = 5
            };

            IActionResult result = await messagesController.GetMessagesFromThread(Guid.NewGuid(), messageFilter);

            Assert.NotNull(result);
            Assert.IsType <OkObjectResult>(result);
        }