public void MoveItem_WherePathIsFileAndDestinationDirectoryIsDifferent_MovesFile() { var rootName = FileSystemFixture.GetRootName(); var rootDirectoryItems = fileSystemFixture.RootDirectoryItems; var subDirectoryItems = fileSystemFixture.SubDirectoryItems; var original = (FileInfoContract)subDirectoryItems.Single(i => i.Name == "SubFile.ext"); var moved = default(FileInfoContract); var gatewayMock = mockingFixture.InitializeGetChildItems(rootName, @"\SubDir", rootDirectoryItems, subDirectoryItems); gatewayMock.Setup(g => g.MoveItem(rootName, new FileId(@"\File.ext"), @"FileMove.ext", new DirectoryId(@"\SubDir"))) .Returns(moved = new FileInfoContract(original.Id.Value.Replace("File", "FileMove"), original.Name.Replace("File", "FileMove"), original.Created, original.Updated, original.Size, original.Hash)) .Verifiable(); compositionFixture.ExportGateway(gatewayMock.Object); var result = new PipelineFixture().Invoke( FileSystemFixture.NewDriveCommand, @"Move-Item -Path X:\File.ext -Destination X:\SubDir\FileMove.ext", @"Get-ChildItem -Path X:\SubDir" ); Assert.AreEqual(subDirectoryItems.Count() + 1, result.Count, "Unexpected number of results"); CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), moved, "Moved item is missing"); gatewayMock.VerifyAll(); }
public void SetupSetFileContentWithError <TException>(FileInfoContract file, byte[] content) where TException : Exception, new() { _drive .Setup(drive => drive.SetContent(It.Is <FileInfoContract>(f => f.Id == file.Id), It.Is <Stream>(s => s.Contains(content)))) .Throws <TException>(); }
public Stream GetContent(FileInfoContract source, ProgressProxy progress) { try { var result = gateway.GetContentAsync(rootName, source.Id).Result; if (!result.CanSeek) { var bufferStream = new MemoryStream(); result.CopyTo(bufferStream, MAX_BULKDOWNLOAD_SIZE); bufferStream.Seek(0, SeekOrigin.Begin); result.Dispose(); result = bufferStream; } result = new ProgressStream(result, progress); if (!string.IsNullOrEmpty(encryptionKey)) { result = result.Decrypt(encryptionKey); } return(result); } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } }
public void CopyItem_WherePathIsFile_CopiesFile() { var rootName = FileSystemFixture.GetRootName(); var rootDirectoryItems = fileSystemFixture.RootDirectoryItems; var original = (FileInfoContract)rootDirectoryItems.Single(i => i.Name == "File.ext"); var copy = default(FileInfoContract); var gatewayMock = mockingFixture.InitializeGetChildItems(rootName, @"\", rootDirectoryItems); gatewayMock.Setup(g => g.CopyItem(rootName, new FileId(@"\File.ext"), @"FileCopy.ext", new DirectoryId(@"\"), false)) .Returns(copy = new FileInfoContract(original.Id.Value.Replace("File", "FileCopy"), original.Name.Replace("File", "FileCopy"), original.Created, original.Updated, original.Size, original.Hash)) .Verifiable(); compositionFixture.ExportGateway(gatewayMock.Object); var result = new PipelineFixture().Invoke( FileSystemFixture.NewDriveCommand, @"Copy-Item -Path X:\File.ext -Destination X:\FileCopy.ext", @"Get-ChildItem -Path X:\" ); Assert.AreEqual(rootDirectoryItems.Count() + 1, result.Count, "Unexpected number of results"); CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), original, "Original item is missing"); CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), copy, "Copied item is missing"); gatewayMock.VerifyAll(); }
public CloudFileNode GetFile(FileInfoContract contract, DirectoryInfoContract parent = null) { var result = new CloudFileNode(contract); result.SetParent(parent != null ? new CloudDirectoryNode(parent) : _root); return(result); }
public void NewItemAsync_WhereEncryptionKeyIsSpecifiedAndItemTypeIsFile_PassesEncryptedValue() { var rootName = FileSystemFixture.GetRootName(); var rootDirectoryItems = fileSystemFixture.RootDirectoryItems; var content = TestContent.SingleLineTestContent; var newItem = new FileInfoContract(@"\NewFile", "NewFile", DateTime.Now, DateTime.Now, content.Length, FileSystemFixture.GetHash(content)); var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\", rootDirectoryItems); gatewayMock.Setup(g => g.NewFileItemAsync(rootName, new DirectoryId(@"\"), "NewFile", It.Is <Stream>(s => EncryptionFixture.GetDecryptingReader(s, FileSystemFixture.EncryptionKey).ReadToEnd() == content), It.Is <IProgress <ProgressValue> >(p => true))) .ReturnsAsync(newItem) .Verifiable(); compositionFixture.ExportAsyncGateway(gatewayMock.Object); var pipelineFixture = new PipelineFixture(); pipelineFixture.SetVariable("value", content); var result = pipelineFixture.Invoke( FileSystemFixture.NewDriveCommandWithEncryptionKey, @"New-Item -Type File -Path X:\ -Name NewFile -Value $value" ); Assert.AreEqual(1, result.Count, "Unexpected number of results"); Assert.AreEqual(newItem, result[0].BaseObject, "Mismatching result"); gatewayMock.VerifyAll(); }
public void RenameItemAsync_WherePathIsFile_RenamesFile() { var rootName = FileSystemFixture.GetRootName(); var rootDirectoryItems = fileSystemFixture.RootDirectoryItems; var original = (FileInfoContract)rootDirectoryItems.Single(i => i.Name == "File.ext"); var renamed = default(FileInfoContract); var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\", rootDirectoryItems); gatewayMock.Setup(g => g.RenameItemAsync(rootName, new FileId(@"\File.ext"), "FileRenamed.ext", It.IsAny <Func <FileSystemInfoLocator> >())) .ReturnsAsync(renamed = new FileInfoContract(original.Id.Value.Replace("File", "FileRenamed"), original.Name.Replace("File", "FileRenamed"), original.Created, original.Updated, original.Size, original.Hash)) .Verifiable(); compositionFixture.ExportAsyncGateway(gatewayMock.Object); var result = new PipelineFixture().Invoke( FileSystemFixture.NewDriveCommand, @"Rename-Item -Path X:\File.ext -NewName FileRenamed.ext", @"Get-ChildItem -Path X:\" ); Assert.AreEqual(rootDirectoryItems.Count(), result.Count, "Unexpected number of results"); CollectionAssert.DoesNotContain(result.Select(p => p.BaseObject).ToArray(), original, "Unrenamed original remains"); CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), renamed, "Renamed item is missing"); gatewayMock.VerifyAll(); }
public void NewItemAsync_WherePathIsIncompleteAndItemTypeIsFile_CreatesNewFile() { var rootName = FileSystemFixture.GetRootName(); var rootDirectoryItems = fileSystemFixture.RootDirectoryItems; var newIntermediateDirectory = new DirectoryInfoContract(@"\NewSubDir", "NewSubDir", DateTime.Now, DateTime.Now); var newItem = new FileInfoContract(@"\NewSubDir\NewSubFile", "NewSubFile", DateTime.Now, DateTime.Now, 0, null); var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\", rootDirectoryItems); gatewayMock.Setup(g => g.NewDirectoryItemAsync(rootName, new DirectoryId(@"\"), "NewSubDir")) .ReturnsAsync(newIntermediateDirectory) .Verifiable(); gatewayMock.Setup(g => g.NewFileItemAsync(rootName, new DirectoryId(@"\NewSubDir"), "NewSubFile", null, It.Is <IProgress <ProgressValue> >(p => true))) .ReturnsAsync(newItem) .Verifiable(); var subDirs = new Queue <string>(new[] { @"\", @"\NewSubDir" }); var predicateIterator = new Func <string, bool>(s => s == subDirs.Dequeue()); gatewayMock.SetupSequence(g => g.GetChildItemAsync(rootName, It.Is <DirectoryId>(d => predicateIterator(d.Value)))) .ReturnsAsync(new FileSystemInfoContract[0]) .ReturnsAsync(new FileSystemInfoContract[0]) .ThrowsAsync(new InvalidOperationException(@"Redundant access to directory")); compositionFixture.ExportAsyncGateway(gatewayMock.Object); var result = new PipelineFixture().Invoke( FileSystemFixture.NewDriveCommand, @"New-Item -Type File -Path X:\NewSubDir -Name NewSubFile -Force", @"Get-ChildItem -Path X:\ -Filter 'NewSub*' -Recurse" ); Assert.AreEqual(2, result.Count, "Unexpected number of results"); CollectionAssert.AreEqual(result.Select(i => i.BaseObject).ToArray(), new FileSystemInfoContract[] { newIntermediateDirectory, newItem }, "Unexpected result"); gatewayMock.VerifyAll(); }
public void ClearContent(FileInfoContract target) { gateway.ClearContent(rootName, target.Id); target.Size = 0; InvalidateDrive(); }
public void NewItemAsync_WherePathIsSubDirAndItemTypeIsFile_CanRemoveNewFile() { var rootName = FileSystemFixture.GetRootName(); var rootDirectoryItems = fileSystemFixture.RootDirectoryItems; var subDirectoryItems = fileSystemFixture.SubDirectoryItems; var newItem = new FileInfoContract(@"\SubDir\NewSubFile", "NewSubFile", DateTime.Now, DateTime.Now, 0, null); var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\SubDir", rootDirectoryItems, subDirectoryItems); gatewayMock.Setup(g => g.NewFileItemAsync(rootName, new DirectoryId(@"\SubDir"), "NewSubFile", null, It.Is <IProgress <ProgressValue> >(p => true))) .ReturnsAsync(newItem) .Verifiable(); gatewayMock.Setup(g => g.RemoveItemAsync(rootName, new FileId(@"\SubDir\NewSubFile"), false)) .ReturnsAsync(true) .Verifiable(); compositionFixture.ExportAsyncGateway(gatewayMock.Object); var result = new PipelineFixture().Invoke( FileSystemFixture.NewDriveCommand, @"New-Item -Type File -Path X:\SubDir -Name NewSubFile", @"Remove-Item -Path X:\SubDir\NewSubFile", @"Get-ChildItem -Path X:\SubDir" ); Assert.AreEqual(subDirectoryItems.Length, result.Count, "Unexpected number of results"); CollectionAssert.DoesNotContain(result.Select(p => p.BaseObject).ToArray(), newItem, "Excessive result"); gatewayMock.VerifyAll(); }
public void SetupSetFileContent(FileInfoContract file, byte[] content, ICollection <Tuple <int, int, byte[], byte[]> > differences) { _drive .Setup(drive => drive.SetContent(It.Is <FileInfoContract>(f => f.Id == file.Id), It.IsAny <Stream>())) .Callback((FileInfoContract _file, Stream _stream) => _stream.FindDifferences(content, differences)) .Verifiable(); }
public void SetupGetFileContent(FileInfoContract file, byte[] content) { _drive .Setup(drive => drive.GetContent(It.Is <FileInfoContract>(f => f.Id == file.Id))) .Returns(new MemoryStream(content)) .Verifiable(); }
public void FileInfo_CopyToDirectory_Succeeds() { var fileContent = Encoding.Default.GetBytes("Why did the chicken cross the road?"); var sutContract = _fixture.RootDirectoryItems.OfType <FileInfoContract>().First(); var targetContract = _fixture.RootDirectoryItems.OfType <DirectoryInfoContract>().Last(); var copyContract = new FileInfoContract(targetContract.Id + Path.DirectorySeparatorChar.ToString() + sutContract.Name, sutContract.Name, sutContract.Created, sutContract.Updated, sutContract.Size, sutContract.Hash) { Directory = targetContract }; _fixture.SetupGetRootDirectoryItems(); _fixture.SetupGetSubDirectory2Items(_fixture.SubDirectory2Items); _fixture.SetupGetFileContent(sutContract, fileContent); _fixture.SetupNewFile(targetContract.Id.Value, copyContract.Name); _fixture.SetupSetFileContent(copyContract, fileContent); var root = _fixture.GetDriveInfo().RootDirectory; var sut = root.GetFiles(sutContract.Name).Single(); var target = root.GetDirectories(targetContract.Name).Single(); sut.CopyTo(target.FullName + Path.DirectorySeparatorChar + copyContract.Name); var residualFiles = root.GetFiles(sutContract.Name); Assert.AreEqual(1, residualFiles.Count(), "Original file removed"); Assert.AreEqual(root.FullName, sut.Directory.FullName, "Original file relocated"); var copiedFiles = target.GetFiles(copyContract.Name); Assert.AreEqual(1, copiedFiles.Count(), "File not copied"); Assert.AreEqual(target.FullName, copiedFiles[0].Directory.FullName, "Unexpected copy location"); _fixture.Verify(); }
public void SetupMove(FileInfoContract source, string movePath, DirectoryInfoContract destination) { var newName = !string.IsNullOrEmpty(movePath) ? movePath : source.Name; _drive .Setup(d => d.MoveItem(source, movePath, destination)) .Returns(new FileInfoContract(destination.Id.Value + Path.DirectorySeparatorChar + newName, newName, source.Created, source.Updated, source.Size, source.Hash)); }
public FileInfoContract SetupNewFile(DirectoryId parentId, string fileName) { var file = new FileInfoContract($"{parentId.Value.TrimEnd('\\')}\\{fileName}".ToString(CultureInfo.CurrentCulture), fileName, "2016-02-01 12:00:00".ToDateTime(), "2016-02-01 12:00:00".ToDateTime(), FileSize.Empty, null); _drive .Setup(drive => drive.NewFileItem(It.Is <DirectoryInfoContract>(parent => parent.Id == parentId), fileName, It.Is <Stream>(s => s.Length == 0))) .Returns(file) .Verifiable(); return(file); }
public void SetContent(FileInfoContract target, Stream content) { ExecuteInSemaphore(() => { target.Size = content.Length; var gatewayContent = content.EncryptOrPass(encryptionKey); #if DEBUG gatewayContent = new TraceStream(nameof(target), target.Name, gatewayContent); #endif gateway.SetContent(rootName, target.Id, gatewayContent, null); }, nameof(SetContent), true); }
public void SetContent(FileInfoContract target, Stream content) { ExecuteInSemaphore(() => { target.Size = (FileSize)content.Length; //#if DEBUG // content = new TraceStream(nameof(SetContent), target.Name, content); //#endif FileSystemInfoLocator locator() => new FileSystemInfoLocator(target); _gateway.SetContentAsync(_rootName, target.Id, content, null, locator).Wait(); }, nameof(SetContent), true); }
public void SetContent(FileInfoContract target, Stream content, ProgressProxy progress) { if (!string.IsNullOrEmpty(encryptionKey)) { content = content.Encrypt(encryptionKey); } gateway.SetContent(rootName, target.Id, content, progress); target.Size = content.Length; InvalidateDrive(); }
public Stream GetContent(FileInfoContract source) { return(ExecuteInSemaphore(() => { var gatewayContent = gateway.GetContent(rootName, source.Id).ToSeekableStream(); var content = gatewayContent.DecryptOrPass(encryptionKey); #if DEBUG content = new TraceStream(nameof(source), source.Name, content); #endif return content; }, nameof(GetContent))); }
protected void ResolveContract(FileInfoContract contract) { if (IsResolved) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "{0} '{1}' is not a resolvable FileSystemInfo type", Contract.GetType().Name, Contract.Name)); } if (Contract.Name != contract.Name) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "Cannot resolve ProxyFileInfo '{0}' with FileInfo '{1}'", Contract.Name, contract.Name)); } Contract = contract; }
protected void ResolveContract(FileInfoContract contract) { if (IsResolved) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidNonProxyResolution, Contract.GetType().Name, Contract.Name)); } if (Contract.Name != contract.Name) { throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidProxyResolution, Contract.Name, contract.Name)); } Contract = contract; }
public Stream GetContent(FileInfoContract source) { return(ExecuteInSemaphore(() => { var gatewayContent = gateway.GetContentAsync(rootName, source.Id).Result.ToSeekableStream(); var content = gatewayContent.DecryptOrPass(encryptionKey); #if DEBUG CompositionInitializer.SatisfyImports(content = new TraceStream(nameof(GetContent), source.Name, content)); #endif return content; }, nameof(GetContent))); }
public void SetContent(FileInfoContract target, Stream content) { ExecuteInSemaphore(() => { target.Size = content.Length; var gatewayContent = content.EncryptOrPass(encryptionKey); #if DEBUG CompositionInitializer.SatisfyImports(gatewayContent = new TraceStream(nameof(SetContent), target.Name, gatewayContent)); #endif Func <FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(target); gateway.SetContentAsync(rootName, target.Id, gatewayContent, null, locator).Wait(); }, nameof(SetContent), true); }
public void ClearContent(FileInfoContract target) { try { Func <FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(target); gateway.ClearContentAsync(rootName, target.Id, locator).Wait(); target.Size = 0; } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1) { throw ex.InnerExceptions[0]; } finally { InvalidateDrive(); } }
public Stream GetContent(FileInfoContract source) { return(ExecuteInSemaphore(() => { var content = _gateway.GetContentAsync(_rootName, source.Id).Result.ToSeekableStream(); source.Size = (FileSize)content.Length; //#if DEBUG // content = new TraceStream(nameof(GetContent), source.Name, content); //#endif return content; }, nameof(GetContent))); }
public void SetupSetContent(FileInfoContract target, byte[] content, string encryptionKey) { Func <Stream, bool> checkContent = stream => { //if (!string.IsNullOrEmpty(encryptionKey)) //{ // var buffer = Encryption.StreamCrypto.Decrypt(encryptionKey, stream); // return buffer.Contains(content); //} return(stream.Contains(content)); }; _gateway .Setup(g => g.SetContent(_rootName, target.Id, It.Is <Stream>(s => checkContent(s)), It.IsAny <IProgress <ProgressValue> >())); }
public void SetupGetContent(FileInfoContract source, byte[] content, string encryptionKey = null, bool canSeek = true) { // The first constructor does not expose the underlying stream. GetBuffer throws UnauthorizedAccessException. var stream = new MemoryStream(content, 0, content.Length, false, publiclyVisible: true); // publiclyVisible: true to enable GetBuffer(), which returns the unsigned byte array from which the stream was created; otherwise, false. //if (!string.IsNullOrEmpty(encryptionKey)) // stream = Encryption.StreamCrypto.Encrypt(encryptionKey, stream); if (!canSeek) { stream = new LinearReadMemoryStream(stream); } _gateway .Setup(g => g.GetContent(_rootName, source.Id)) .Returns(stream); }
public void SetContent(FileInfoContract target, Stream content) { ExecuteInSemaphore(() => { var gatewayContent = content.EncryptOrPass(_encryptionKey); target.Size = (FileSize)content.Length; //#if DEBUG // CompositionInitializer.SatisfyImports(gatewayContent = new TraceStream(nameof(target), target.Name, gatewayContent)); //#endif _gateway.SetContent(_rootName, target.Id, gatewayContent, null); if (content != gatewayContent) { gatewayContent.Close(); } }, nameof(SetContent), true); }
public void SetupSetContent(FileInfoContract target, byte[] content, string encryptionKey) { Func <Stream, bool> checkContent = stream => { if (!string.IsNullOrEmpty(encryptionKey)) { var buffer = new MemoryStream(); SharpAESCrypt.SharpAESCrypt.Decrypt(encryptionKey, stream, buffer); buffer.Seek(0, SeekOrigin.Begin); return(buffer.Contains(content)); } return(stream.Contains(content)); }; gateway .Setup(g => g.SetContent(rootName, target.Id, It.Is <Stream>(s => checkContent(s)), It.IsAny <IProgress <ProgressValue> >())); }
public Stream GetContent(FileInfoContract source) { return(ExecuteInSemaphore(() => { var gatewayContent = _gateway.GetContent(_rootName, source.Id).ToSeekableStream(); var content = gatewayContent.DecryptOrPass(_encryptionKey); if (content != gatewayContent) { gatewayContent.Close(); } source.Size = (FileSize)content.Length; //#if DEBUG // CompositionInitializer.SatisfyImports(content = new TraceStream(nameof(source), source.Name, content)); //#endif return content; }, nameof(GetContent))); }
public Stream GetContent(FileInfoContract source) { return ExecuteInSemaphore(() => { var result = gateway.GetContentAsync(rootName, source.Id).Result; if (!result.CanSeek) { var bufferStream = new MemoryStream(); result.CopyTo(bufferStream, MAX_BULKDOWNLOAD_SIZE); bufferStream.Seek(0, SeekOrigin.Begin); result.Dispose(); result = bufferStream; } if (!string.IsNullOrEmpty(encryptionKey)) result = result.Decrypt(encryptionKey); #if DEBUG result = new TraceStream(nameof(GetContent), source.Name, result); #endif return result; }, nameof(GetContent)); }
internal void SetupSetFileContent(FileInfoContract file, string content) { Drive .Setup(drive => drive.SetContent(It.Is<FileInfoContract>(f => f.Id == file.Id), It.Is<Stream>(s => Contains(s, content)))); }
public void SetContent(FileInfoContract target, Stream content) { ExecuteInSemaphore(() => { if (!string.IsNullOrEmpty(encryptionKey)) content = content.Encrypt(encryptionKey); #if DEBUG content = new TraceStream(nameof(SetContent), target.Name, content); #endif Func<FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(target); var result = gateway.SetContentAsync(rootName, target.Id, content, null, locator).Result; target.Size = content.Length; }, nameof(SetContent), true); }
public CloudFileNode(FileInfoContract contract) : base(contract) { }
public void FileInfo_CopyToDirectory_Succeeds() { var fileContent = "Why did the chicken cross the road?"; var sutContract = fixture.RootDirectoryItems.OfType<FileInfoContract>().First(); var targetContract = fixture.RootDirectoryItems.OfType<DirectoryInfoContract>().Last(); var copyContract = new FileInfoContract(targetContract.Id + Path.DirectorySeparatorChar.ToString() + sutContract.Name, sutContract.Name, sutContract.Created, sutContract.Updated, sutContract.Size, sutContract.Hash) { Directory = targetContract }; fixture.SetupGetRootDirectoryItems(); fixture.SetupGetSubDirectory2Items(fixture.SubDirectory2Items); fixture.SetupGetFileContent(sutContract, fileContent); fixture.SetupNewFile(targetContract.Id.Value, copyContract.Name); fixture.SetupSetFileContent(copyContract, fileContent); fixture.SetupGetDisplayRoot(); var root = fixture.GetDriveInfo().RootDirectory; var sut = root.GetFiles(sutContract.Name).Single(); var target = root.GetDirectories(targetContract.Name).Single(); sut.CopyTo(target.FullName + Path.DirectorySeparatorChar + copyContract.Name); var residualFiles = root.GetFiles(sutContract.Name); Assert.AreEqual(1, residualFiles.Count(), "Original file removed"); Assert.AreEqual(root.FullName, sut.Directory.FullName, "Original file relocated"); var copiedFiles = target.GetFiles(copyContract.Name); Assert.AreEqual(1, copiedFiles.Count(), "File not copied"); Assert.AreEqual(target.FullName, copiedFiles[0].Directory.FullName, "Unexpected copy location"); fixture.Drive.VerifyAll(); }
internal FileInfoContract SetupNewFile(DirectoryId parentId, string fileName) { var file = new FileInfoContract($"{parentId.Value.TrimEnd('\\')}\\{fileName}", fileName, ToDateTime("2016-02-01 12:00:00"), ToDateTime("2016-02-01 12:00:00"), 0, null); Drive .Setup(drive => drive.NewFileItem(It.Is<DirectoryInfoContract>(parent => parent.Id == parentId), fileName, It.Is<Stream>(s => s.Length == 0))) .Returns(file); return file; }
internal void SetupGetFileContent(FileInfoContract file, string content) { Drive .Setup(drive => drive.GetContent(It.Is<FileInfoContract>(f => f.Id == file.Id))) .Returns(!string.IsNullOrEmpty(content) ? new MemoryStream(Encoding.Default.GetBytes(content)) : new MemoryStream()); }
public void SetContent(FileInfoContract target, Stream content) { ExecuteInSemaphore(() => { if (!string.IsNullOrEmpty(encryptionKey)) content = content.Encrypt(encryptionKey); #if DEBUG content = new TraceStream(nameof(target), target.Name, content); #endif gateway.SetContent(rootName, target.Id, content, null); target.Size = content.Length; }, nameof(SetContent), true); }