public void AddReply_ShouldCallAddReplyAndReturnOkResult() { int photoId = 1; Photos[photoId].Comments = new List <Comment> { new Comment { Id = 1 } }; var mockService = new Mock <IPhotoService>(); mockService.Setup(service => service.GetPhotoById(photoId)).Returns(Photos[photoId]); var fakeUserManager = new FakeUserManagerBuilder() .Build(); var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, "test1"), new Claim(ClaimTypes.NameIdentifier, "1"), new Claim("custom-claim", "example claim value"), }, "mock")); fakeUserManager.Setup(u => u.FindByNameAsync("test1")).Returns(Task.FromResult(new User { Id = "1", UserName = "******" })); var controller = new PhotoController(mockService.Object, _mapper, fakeUserManager.Object); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } }; controller.ControllerContext = context; var result = controller.AddReply(photoId, 1, new Reply { Id = 1 }); mockService.Verify(service => service.AddReply(It.IsAny <Comment>(), It.IsAny <Reply>(), It.IsAny <Photo>()), Times.Once()); Assert.IsInstanceOf <OkResult>(result); }