public async Task UploadSendFileAsync(SendFileUploadDataResponse uploadData, EncString fileName, EncByteArray encryptedFileData) { try { switch (uploadData.FileUploadType) { case FileUploadType.Direct: await _bitwardenFileUploadService.Upload(fileName.EncryptedString, encryptedFileData, fd => _apiService.PostSendFileAsync(uploadData.SendResponse.Id, uploadData.SendResponse.File.Id, fd)); break; case FileUploadType.Azure: Func <Task <string> > renewalCallback = async() => { var response = await _apiService.RenewFileUploadUrlAsync(uploadData.SendResponse.Id, uploadData.SendResponse.File.Id); return(response.Url); }; await _azureFileUploadService.Upload(uploadData.Url, encryptedFileData, renewalCallback); break; default: throw new Exception("Unknown file upload type"); } } catch (Exception) { await _apiService.DeleteSendAsync(uploadData.SendResponse.Id); throw; } }
public async Task SaveWithServerAsync_NewFileSend_AzureUpload_Success(SutProvider <SendService> sutProvider, string userId, SendFileUploadDataResponse response, Send send) { send.Id = null; response.FileUploadType = FileUploadType.Azure; sutProvider.GetDependency <IUserService>().GetUserIdAsync().Returns(userId); sutProvider.GetDependency <IApiService>().PostFileTypeSendAsync(Arg.Any <SendRequest>()).Returns(response); var fileContentBytes = new EncByteArray(Encoding.UTF8.GetBytes("This is the file content")); await sutProvider.Sut.SaveWithServerAsync(send, fileContentBytes); switch (send.Type) { case SendType.File: await sutProvider.GetDependency <IFileUploadService>().Received(1).UploadSendFileAsync(response, send.File.FileName, fileContentBytes); break; case SendType.Text: default: throw new Exception("Untested send type"); } }