public void GetCurrentLoggedUser_ShouldReturnCurrentLoggedUser() { var mockService = new Mock <IPhotoService>(); 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())); var controller = new PhotoController(mockService.Object, _mapper, fakeUserManager.Object); var context = new ControllerContext { HttpContext = new DefaultHttpContext { User = user } }; controller.ControllerContext = context; var result = controller.GetCurrentLoggedUser(); Assert.IsInstanceOf <User>(result.Result); }