public async Task ChangeUserPhoto_Success() { //Arrange------------------------------------------------------------------------------------------------------------------------------ _mockRepo.Setup(x => x.PhotoRepository.GetAsync(It.IsAny <Expression <Func <Photo, bool> > >())) .ReturnsAsync(UnitTestsDataInput.Users.First().Photos.First()); _mockRepo.Setup(x => x.PhotoRepository.Update(It.IsAny <Photo>())); _mockRepo.Setup(x => x.SaveAsync()).ReturnsAsync(true); //_mockUploadService.Setup(x => x.UploadFile(It.IsAny<IFormFile>(), // It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) // .ReturnsAsync(UnitTestsDataInput.fileUploadedDto_Success); _mockUploadService.Setup(x => x.RemoveFileFromCloudinary(It.IsAny <string>())) .Returns(UnitTestsDataInput.fileUploadedDto_Success); _mockUploadService.Setup(x => x.RemoveFileFromLocal(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(UnitTestsDataInput.fileUploadedDto_Success); _mockWebHostEnvironment.Setup(x => x.WebRootPath).Returns(It.IsAny <string>()); _mockMapper.Setup(x => x.Map(It.IsAny <PhotoForProfileDto>(), It.IsAny <Photo>())) .Returns(UnitTestsDataInput.Users.First().Photos.First()); _mockMapper.Setup(x => x.Map <PhotoForReturnProfileDto>(It.IsAny <Photo>())) .Returns(UnitTestsDataInput.PhotoForReturnProfileDto); var httpContext = new DefaultHttpContext(); httpContext.Request.Scheme = "222"; _controller.ControllerContext = new ControllerContext() { HttpContext = httpContext }; //Act---------------------------------------------------------------------------------------------------------------------------------- var result = await _controller.ChangeUserPhoto(It.IsAny <string>(), UnitTestsDataInput.photoForProfileDto); var okResult = result as CreatedAtRouteResult; //Assert------------------------------------------------------------------------------------------------------------------------------- Assert.NotNull(okResult); Assert.IsType <PhotoForReturnProfileDto>(okResult.Value); Assert.Equal(201, okResult.StatusCode); }