コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        public async void It_should_copy_stream_to_memorystream()
        {
            _result = await _streamHandler.CopyStreamToByteBuffer(_stream);

            Assert.Equal(_result.Length, 666);
        }