public async Task AddPhotoForUser_UnauthorizedUserIdPassed_ReturnsUnauthorizedResult() { var photo = new Photo() { Id = 1, IsMain = true, }; var photoToMain = new Photo() { Id = 2, IsMain = false, }; var user = new User() { Id = 2, Photos = new List <Photo> { photo, photoToMain } }; var photoForCreation = new PhotoForCreationDto { File = new FormFile(null, 0, 0, "", ""), Url = "test", PublicId = "test" }; var userClaims = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.NameIdentifier, "1"), })); var mapperMock = new Mock <IMapper>(); var cloudinaryConfigMock = Options.Create <CloudinarySettings>(new CloudinarySettings { ApiKey = "test", ApiSecret = "test", CloudName = "test" }); var repositoryMock = new Mock <IRepositoryWrapper>(); repositoryMock.Setup(r => r.UserRepository.GetUserAsync(It.IsAny <int>())).ReturnsAsync(() => user); repositoryMock.Setup(r => r.SaveAllAsync()).ReturnsAsync(true); mapperMock.Setup(m => m.Map <PhotoForReturnDto>(It.IsAny <Photo>())).Returns(new PhotoForReturnDto()); mapperMock.Setup(m => m.Map <Photo>(It.IsAny <PhotoForCreationDto>())).Returns(new Photo()); var controllerMock = new PhotosController(repositoryMock.Object, mapperMock.Object, cloudinaryConfigMock); controllerMock.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext() { User = userClaims } }; var result = await controllerMock.AddPhotoForUser(user.Id, photoForCreation); Assert.IsType <UnauthorizedResult>(result); }