public async Task <string> HandleUpload(IFormFile file) { var data = await _streamHandler.CopyStreamToByteBuffer(file.OpenReadStream()); var encryptedData = await _streamHandler.EncryptData(data); var uniqueFileName = Guid.NewGuid().ToString(); await _streamHandler.WriteBufferToFile(encryptedData, _hostingEnvironment.WebRootPath + "uploads/" + uniqueFileName); return(uniqueFileName); }
public void for_FileUploadHandler_when_fileupload_it_should_encrypt_the_file_write_it_to_storage_and_return_a_uniqe_filename() { var fileId = _fileUploadHandler.HandleUpload(A.Fake <IFormFile>()); A.CallTo(() => _streamHandler.CopyStreamToByteBuffer(A <Stream> .Ignored)).MustHaveHappened(); A.CallTo(() => _streamHandler.EncryptData(A <byte[]> .Ignored)).MustHaveHappened(); A.CallTo(() => _streamHandler.WriteBufferToFile(A <byte[]> .Ignored, A <string> .Ignored)).MustHaveHappened(); Assert.NotNull(fileId); }
public async void It_should_copy_stream_to_memorystream() { _result = await _streamHandler.CopyStreamToByteBuffer(_stream); Assert.Equal(_result.Length, 666); }