public async Task GetMessageForUser_ValidUserIdPassed_ReturnsOkResult() { var messages = new List <Message> { new Message { SenderId = 1, RecipientId = 1, Content = "test" } }; var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var repositoryMock = new Mock <IRepositoryWrapper>(); var messageParams = new MessageParams(); var mapperMock = new Mock <IMapper>(); mapperMock.Setup(m => m.Map <IEnumerable <MessageToReturnDto> >(It.IsAny <PagedList <Message> >())).Returns(new List <MessageToReturnDto>()); repositoryMock.Setup(r => r.MessageRepository.GetMessagesForUserAsync(messageParams)).ReturnsAsync(new PagedList <Message>(messages, 1, 1, 1)); var controllerMock = new MessagesController(repositoryMock.Object, mapperMock.Object); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = user } }; var result = await controllerMock.GetMessagesForUser(1, messageParams); Assert.IsType <OkObjectResult>(result); }