コード例 #1
0
        public async Task <string> UploadProfileImage(DataForProfilePicUpdateDto data)
        {
            string fileNameForStorage = "accounts/profile/" + data.Name + Path.GetExtension(data.Image.FileName);
            await _cloudStorage.UploadFileAsync(data.Image, fileNameForStorage);

            string imageUrl = Environment.GetEnvironmentVariable("CLOUD_STORAGE_URL") + fileNameForStorage;

            return(imageUrl);
        }
コード例 #2
0
        public async Task <string> UploadProfileImage(DataForProfilePicUpdateDto data)
        {
            var fileNameForStorage = "accounts/profile/" + data.Name + Path.GetExtension(data.Image.FileName);
            await _cloudStorage.UploadFileAsync(data.Image, fileNameForStorage);

            var imageUrl = $"{_env.CloudStorageUrl}{fileNameForStorage}";

            return(imageUrl);
        }
コード例 #3
0
        public async Task UpdateProfileImage_GivenImage_ReturnsUpdatedUserProfileAsync()
        {
            //Given
            ImageFromUserDto           imageFromUser        = Mock.Of <ImageFromUserDto>();
            DataForProfilePicUpdateDto dataForProfileUpdate = Mock.Of <DataForProfilePicUpdateDto>();
            string newProfilePicUrl = "new url";

            //When
            _mapper.Setup(x => x.Map <DataForProfilePicUpdateDto>(imageFromUser)).Returns(dataForProfileUpdate);
            _profileService.Setup(x => x.UploadProfileImage(dataForProfileUpdate)).ReturnsAsync(newProfilePicUrl);
            _repo.Setup(x => x.UpdateProfileImage(_user.Id, newProfilePicUrl)).ReturnsAsync(_user);
            //Then
            var response = await _controller.UpdateProfileImage(imageFromUser);

            Assert.IsType <ActionResult <User> >(response);
        }
コード例 #4
0
        public async System.Threading.Tasks.Task UploadFile_GivenDataForProfilePicUpdate_ReturnsNewUrlAsync()
        {
            //Given
            DataForProfilePicUpdateDto data = Mock.Of <DataForProfilePicUpdateDto>();

            data.Name = "imageName";
            var mockImage = new Mock <IFormFile>();

            mockImage.Setup(x => x.FileName).Returns("mockfile.png");
            data.Image = mockImage.Object;
            var returnUrl = "accounts/profile/imageName.png";

            //When
            _configuration.Setup(x => x.GetSection("CloudStorageUrl").Value).Returns("url");
            //Then
            var response = await _profileService.UploadProfileImage(data);

            Assert.Equal(returnUrl, response);
        }