public void CopyItem_WherePathIsDirectoryAndDestinationDirectoryIsDifferent_CopiesDirectory()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var subDirectoryItems  = fileSystemFixture.SubDirectoryItems;

            var original = (DirectoryInfoContract)rootDirectoryItems.Single(i => i.Name == "SubDir");
            var copy     = default(DirectoryInfoContract);

            var gatewayMock = mockingFixture.InitializeGetChildItems(rootName, @"\SubDir", rootDirectoryItems, subDirectoryItems);

            gatewayMock.Setup(g => g.CopyItem(rootName, new DirectoryId(@"\SubDir"), @"SubDirCopy", new DirectoryId(@"\SubDir"), false))
            .Returns(copy = new DirectoryInfoContract(original.Id.Value.Replace("SubDir", "SubDirCopy"), original.Name.Replace("SubDir", "SubDirCopy"), original.Created, original.Updated))
            .Verifiable();
            compositionFixture.ExportGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Copy-Item -Path X:\SubDir -Destination X:\SubDir\SubDirCopy",
                @"Get-ChildItem -Path X:\SubDir"
                );

            Assert.AreEqual(subDirectoryItems.Count() + 1, result.Count, "Unexpected number of results");
            CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), copy, "Copied item is missing");

            gatewayMock.VerifyAll();
        }
Esempio n. 2
0
        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 CloudDirectoryNode GetDirectory(DirectoryInfoContract contract)
            {
                var result = new CloudDirectoryNode(contract);

                result.SetParent(root);
                return(result);
            }
Esempio n. 4
0
        public void MoveItem_WherePathIsDirectoryInSubDirectory_MovesDirectory()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var subDirectoryItems  = fileSystemFixture.SubDirectoryItems;

            var original = (DirectoryInfoContract)subDirectoryItems.Single(i => i.Name == "SubSubDir");
            var moved    = default(DirectoryInfoContract);

            var gatewayMock = mockingFixture.InitializeGetChildItems(rootName, @"\SubDir", rootDirectoryItems, subDirectoryItems);

            gatewayMock.Setup(g => g.MoveItem(rootName, new DirectoryId(@"\SubDir\SubSubDir"), "SubSubDirMove", new DirectoryId(@"\SubDir")))
            .Returns(moved = new DirectoryInfoContract(original.Id.Value.Replace("SubSubDir", "SubSubDirMove"), original.Name.Replace("SubSubDir", "SubSubDirMove"), original.Created, original.Updated))
            .Verifiable();
            compositionFixture.ExportGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Move-Item -Path X:\SubDir\SubSubDir -Destination X:\SubDir\SubSubDirMove",
                @"Get-ChildItem -Path X:\SubDir"
                );

            Assert.AreEqual(subDirectoryItems.Count(), result.Count, "Unexpected number of results");
            CollectionAssert.DoesNotContain(result.Select(p => p.BaseObject).ToArray(), original, "Original item remains");
            CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), moved, "Moved item is missing");

            gatewayMock.VerifyAll();
        }
Esempio n. 5
0
        public void NewItemAsync_WherePathIsSubDirAndItemTypeIsDirectory_CreatesNewDirectory()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var subDirectoryItems  = fileSystemFixture.SubDirectoryItems;
            var newItem            = new DirectoryInfoContract(@"\SubDir\NewSubSubDir", "NewSubSubDir", DateTime.Now, DateTime.Now);

            var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\SubDir", rootDirectoryItems, subDirectoryItems);

            gatewayMock.Setup(g => g.NewDirectoryItemAsync(rootName, new DirectoryId(@"\SubDir"), "NewSubSubDir"))
            .ReturnsAsync(newItem)
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"New-Item -Type Directory -Path X:\SubDir -Name NewSubSubDir",
                @"Get-ChildItem -Path X:\SubDir"
                );

            Assert.AreEqual(subDirectoryItems.Length + 1, result.Count, "Unexpected number of results");
            CollectionAssert.Contains(result.Select(p => p.BaseObject).ToArray(), newItem, "Missing result");

            gatewayMock.VerifyAll();
        }
Esempio n. 6
0
            public CloudFileNode GetFile(FileInfoContract contract, DirectoryInfoContract parent = null)
            {
                var result = new CloudFileNode(contract);

                result.SetParent(parent != null ? new CloudDirectoryNode(parent) : _root);
                return(result);
            }
Esempio n. 7
0
 void SetupMoveItem(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target)
 {
     _gateway
     .Setup(g => g.MoveItem(_rootName, directoryOrFile.Id, name, target.Id))
     .Returns((RootName _rootName, FileSystemId source, string movePath, DirectoryId destination) => {
         var directorySource = source as DirectoryId;
         if (directorySource != null)
         {
             return new DirectoryInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated)
             {
                 Parent = target
             }
         }
         ;
         var fileSource = source as FileId;
         if (fileSource != null)
         {
             return new FileInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated, ((FileInfoContract)directoryOrFile).Size, ((FileInfoContract)directoryOrFile).Hash)
             {
                 Directory = target
             }
         }
         ;
         throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'".ToString(CultureInfo.CurrentCulture));
     });
 }
        public void RenameItemAsync_WherePathIsDirectoryInSubDirectory_RenamesDirectory()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var subDirectoryItems  = fileSystemFixture.SubDirectoryItems;

            var original = (DirectoryInfoContract)subDirectoryItems.Single(i => i.Name == "SubSubDir");
            var renamed  = default(DirectoryInfoContract);

            var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\SubDir", rootDirectoryItems, subDirectoryItems);

            gatewayMock.Setup(g => g.RenameItemAsync(rootName, new DirectoryId(@"\SubDir\SubSubDir"), "SubSubDirRenamed", It.IsAny <Func <FileSystemInfoLocator> >()))
            .ReturnsAsync(renamed = new DirectoryInfoContract(original.Id.Value.Replace("SubSubDir", "SubSubDirRenamed"), original.Name.Replace("SubSubDir", "SubSubDirRenamed"), original.Created, original.Updated))
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Rename-Item -Path X:\SubDir\SubSubDir -NewName SubSubDirRenamed",
                @"Get-ChildItem -Path X:\SubDir"
                );

            Assert.AreEqual(subDirectoryItems.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();
        }
Esempio n. 9
0
            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 TestDirectory(ICloudGateway gateway, RootName root, string apiKey, string path)
            {
                this.gateway = gateway;
                this.root    = root;

                var rootDirectory = gateway.GetRoot(root, apiKey);

                directory = gateway.NewDirectoryItem(root, rootDirectory.Id, path);
            }
Esempio n. 11
0
 public IEnumerable <FileSystemInfoContract> GetChildItem(DirectoryInfoContract parent)
 {
     return(ExecuteInSemaphore(() => {
         return gateway.GetChildItem(rootName, parent.Id).Select(item => {
             FixupSize(item, id => gateway.GetContent(rootName, id));
             return item;
         });
     }, nameof(GetChildItem)));
 }
Esempio n. 12
0
 public IEnumerable <FileSystemInfoContract> GetChildItem(DirectoryInfoContract parent)
 {
     try {
         return(gateway.GetChildItemAsync(rootName, parent.Id).Result);
     } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1)
     {
         throw ex.InnerExceptions[0];
     }
 }
Esempio n. 13
0
 public DirectoryInfoContract NewDirectoryItem(DirectoryInfoContract parent, string name)
 {
     try {
         return(gateway.NewDirectoryItemAsync(rootName, parent.Id, name).Result);
     } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1)
     {
         throw ex.InnerExceptions[0];
     }
 }
            public TestDirectory(IAsyncCloudGateway gateway, RootName root, string apiKey, string path)
            {
                this.gateway = gateway;
                this.root    = root;

                var rootDirectory = gateway.GetRootAsync(root, apiKey).Result;

                directory = gateway.NewDirectoryItemAsync(root, rootDirectory.Id, path).Result;
            }
Esempio n. 15
0
        public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content, ProgressProxy progress)
        {
            if (!string.IsNullOrEmpty(encryptionKey))
            {
                content = content.Encrypt(encryptionKey);
            }

            InvalidateDrive();

            return(gateway.NewFileItem(rootName, parent.Id, name, content, progress));
        }
Esempio n. 16
0
            public DirectoryInfoContract SetupNewDirectory(string parentName, string directoryName)
            {
                var parentId  = new DirectoryId(parentName);
                var directory = new DirectoryInfoContract($"{parentId.Value}{directoryName}\\".ToString(CultureInfo.CurrentCulture), directoryName, "2016-01-01 12:00:00".ToDateTime(), "2016-01-01 12:00:00".ToDateTime());

                _drive
                .Setup(drive => drive.NewDirectoryItem(It.Is <DirectoryInfoContract>(parent => parent.Id == parentId), directoryName))
                .Returns(directory)
                .Verifiable();
                return(directory);
            }
Esempio n. 17
0
 public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content)
 {
     return(ExecuteInSemaphore(() => {
         if (content.Length == 0)
         {
             return new ProxyFileInfoContract(name);
         }
         var result = _gateway.NewFileItemAsync(_rootName, parent.Id, name, content, null).Result;
         result.Size = (FileSize)content.Length;
         return result;
     }, nameof(NewFileItem), true));
 }
Esempio n. 18
0
            public void SetupNewFileItem(DirectoryInfoContract parent, string fileName, 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.NewFileItem(_rootName, parent.Id, fileName, It.Is <Stream>(s => checkContent(s)), It.IsAny <IProgress <ProgressValue> >()))
                .Returns(new FileInfoContract(parent.Id + Path.DirectorySeparatorChar.ToString() + fileName, fileName, DateTimeOffset.Now, DateTimeOffset.Now, (FileSize)content.Length, Encoding.Default.GetString(content).ToHash()));
            }
Esempio n. 19
0
        public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content)
        {
            return(ExecuteInSemaphore(() => {
                if (content.Length == 0)
                {
                    return new ProxyFileInfoContract(name);
                }

                var gatewayContent = content.EncryptOrPass(_encryptionKey);

                var result = _gateway.NewFileItem(_rootName, parent.Id, name, gatewayContent, null);
                result.Size = (FileSize)content.Length;
                return result;
            }, nameof(NewFileItem), true));
        }
Esempio n. 20
0
            private TestDirectoryFixture(IAsyncCloudGateway gateway, RootName root, string apiKey, IDictionary <string, string> parameters, string path)
            {
                this.gateway = gateway;
                this.root    = root;

                var rootDirectory = gateway.GetRootAsync(root, apiKey, parameters).Result;

                var residualDirectory = gateway.GetChildItemAsync(root, rootDirectory.Id).Result.SingleOrDefault(f => f.Name == path) as DirectoryInfoContract;

                if (residualDirectory != null)
                {
                    gateway.RemoveItemAsync(root, residualDirectory.Id, true).Wait();
                }

                directory = gateway.NewDirectoryItemAsync(root, rootDirectory.Id, path).Result;
            }
Esempio n. 21
0
        public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content, ProgressProxy progress)
        {
            try {
                if (content != null && !string.IsNullOrEmpty(encryptionKey))
                {
                    content = content.Encrypt(encryptionKey);
                }

                ProgressProxy.ProgressFunc <FileInfoContract> func = p => gateway.NewFileItemAsync(rootName, parent.Id, name, content, p);
                return(ProgressProxy.TraceProgressOn(func, progress));
            } catch (AggregateException ex) when(ex.InnerExceptions.Count == 1)
            {
                throw ex.InnerExceptions[0];
            } finally {
                InvalidateDrive();
            }
        }
Esempio n. 22
0
            private TestDirectoryFixture(ICloudGateway gateway, RootName root, string apiKey, IDictionary <string, string> parameters, string path)
            {
                _gateway = gateway;
                _root    = root;

                gateway.GetDrive(root, apiKey, parameters);
                var rootDirectory = gateway.GetRoot(root, apiKey, parameters);

                var residualDirectory = gateway.GetChildItem(root, rootDirectory.Id).SingleOrDefault(f => f.Name == path) as DirectoryInfoContract;

                if (residualDirectory != null)
                {
                    gateway.RemoveItem(root, residualDirectory.Id, true);
                }

                _directory = gateway.NewDirectoryItem(root, rootDirectory.Id, path);
            }
Esempio n. 23
0
            public void SetupNewFileItem(DirectoryInfoContract parent, string fileName, 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.NewFileItem(rootName, parent.Id, fileName, It.Is <Stream>(s => checkContent(s)), It.IsAny <IProgress <ProgressValue> >()))
                .Returns(new FileInfoContract(parent.Id + Path.DirectorySeparatorChar.ToString() + fileName, fileName, DateTimeOffset.Now, DateTimeOffset.Now, content.Length, Encoding.Default.GetString(content).ToHash()));
            }
Esempio n. 24
0
        public void NewItemAsync_WherePathIsRootAndItemTypeIsDirectory_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var newItem            = new DirectoryInfoContract(@"\SubDir", "SubDir", DateTime.Now, DateTime.Now);

            var gatewayMock = mockingFixture.InitializeGetChildItemsAsync(rootName, @"\", rootDirectoryItems);

            gatewayMock.Setup(g => g.NewDirectoryItemAsync(rootName, new DirectoryId(@"\"), "NewSubDir"))
            .ReturnsAsync(newItem)
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"New-Item -Type Directory -Path X:\ -Name NewSubDir"
                );

            Assert.AreEqual(1, result.Count, "Unexpected number of results");
            Assert.AreEqual(newItem, result[0].BaseObject, "Mismatching result");

            gatewayMock.VerifyAll();
        }
Esempio n. 25
0
 public DirectoryInfoContract NewDirectoryItem(DirectoryInfoContract parent, string name)
 {
     return ExecuteInSemaphore(() => {
         return gateway.NewDirectoryItemAsync(rootName, parent.Id, name).Result;
     }, nameof(NewDirectoryItem), true);
 }
Esempio n. 26
0
 public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination)
 {
     return ExecuteInSemaphore(() => {
         Func<FileSystemInfoLocator> locator = () => new FileSystemInfoLocator(source);
         return gateway.MoveItemAsync(rootName, source.Id, movePath, destination.Id, locator).Result;
     }, nameof(MoveItem), true);
 }
Esempio n. 27
0
 private void SetupMoveItem(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target, Action callback = null)
 {
     _drive
     .Setup(drive => drive.MoveItem(It.Is <FileSystemInfoContract>(item => item.Id == directoryOrFile.Id), name, target))
     .Returns((FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) => {
         var directorySource = source as DirectoryInfoContract;
         if (directorySource != null)
         {
             return new DirectoryInfoContract(source.Id.Value, movePath, source.Created, source.Updated)
             {
                 Parent = target
             }
         }
         ;
         var fileSource = source as FileInfoContract;
         if (fileSource != null)
         {
             return new FileInfoContract(source.Id.Value, movePath, source.Created, source.Updated, fileSource.Size, fileSource.Hash)
             {
                 Directory = target
             }
         }
         ;
         throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'".ToString(CultureInfo.CurrentCulture));
     })
     .Callback(() => { callback?.Invoke(); })
     .Verifiable();
 }
Esempio n. 28
0
 public void SetupMoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target, Action callback = null)
 => SetupMoveItem(directoryOrFile, directoryOrFile.Name, target, callback);
 private void SetupMoveItemAsync(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target)
 {
     gateway
     .Setup(g => g.MoveItemAsync(rootName, directoryOrFile.Id, name, target.Id, It.IsAny <Func <FileSystemInfoLocator> >()))
     .Returns((RootName _rootName, FileSystemId source, string movePath, DirectoryId destination, Func <FileSystemInfoLocator> progress) => {
         var directorySource = source as DirectoryId;
         if (directorySource != null)
         {
             return(Task.FromResult((FileSystemInfoContract) new DirectoryInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated)
             {
                 Parent = target
             }));
         }
         var fileSource = source as FileId;
         if (fileSource != null)
         {
             return(Task.FromResult((FileSystemInfoContract) new FileInfoContract(source.Value, movePath, directoryOrFile.Created, directoryOrFile.Updated, ((FileInfoContract)directoryOrFile).Size, ((FileInfoContract)directoryOrFile).Hash)
             {
                 Directory = target
             }));
         }
         throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'".ToString(CultureInfo.CurrentCulture));
     });
 }
Esempio n. 30
0
 public void SetupGetChildItems(DirectoryInfoContract parent, IEnumerable <FileSystemInfoContract> childItems)
 {
     _drive
     .Setup(d => d.GetChildItem(parent))
     .Returns(childItems);
 }
 public CloudDirectoryNode(DirectoryInfoContract contract) : base(contract)
 {
 }
Esempio n. 32
0
        public FileInfoContract NewFileItem(DirectoryInfoContract parent, string name, Stream content)
        {
            return ExecuteInSemaphore(() => {
                if (content != null && !string.IsNullOrEmpty(encryptionKey))
                    content = content.Encrypt(encryptionKey);

                return gateway.NewFileItemAsync(rootName, parent.Id, name, content, null).Result;
            }, nameof(NewFileItem), true);
        }
Esempio n. 33
0
 public void SetupMoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target)
 {
     SetupMoveItem(directoryOrFile, directoryOrFile.Name, target);
 }
Esempio n. 34
0
 public IEnumerable<FileSystemInfoContract> GetChildItem(DirectoryInfoContract parent)
 {
     return ExecuteInSemaphore(() => {
         return gateway.GetChildItemAsync(rootName, parent.Id).Result;
     }, nameof(GetChildItem));
 }
 internal DirectoryInfoContract SetupNewDirectory(string parentName, string directoryName)
 {
     var parentId = new DirectoryId(parentName);
     var directory = new DirectoryInfoContract($"{parentId.Value}{directoryName}\\", directoryName, ToDateTime("2016-01-01 12:00:00"), ToDateTime("2016-01-01 12:00:00"));
     Drive
         .Setup(drive => drive.NewDirectoryItem(It.Is<DirectoryInfoContract>(parent => parent.Id == parentId), directoryName))
         .Returns(directory);
     return directory;
 }
Esempio n. 36
0
 public void SetupNewDirectoryItem(DirectoryInfoContract parent, string directoryName)
 {
     gateway
     .Setup(g => g.NewDirectoryItem(rootName, parent.Id, directoryName))
     .Returns(new DirectoryInfoContract(parent.Id + Path.DirectorySeparatorChar.ToString() + directoryName, directoryName, DateTimeOffset.Now, DateTimeOffset.Now));
 }
 internal void SetupMoveDirectoryOrFile(FileSystemInfoContract directoryOrFile, DirectoryInfoContract target)
 {
     SetupMoveItem(directoryOrFile, directoryOrFile.Name, target);
 }
 private void SetupMoveItem(FileSystemInfoContract directoryOrFile, string name, DirectoryInfoContract target)
 {
     Drive
         .Setup(drive => drive.MoveItem(It.Is<FileSystemInfoContract>(item => item.Id == directoryOrFile.Id), name, target))
         .Returns((FileSystemInfoContract source, string movePath, DirectoryInfoContract destination) => {
             var directorySource = source as DirectoryInfoContract;
             if (directorySource != null)
                 return new DirectoryInfoContract(source.Id.Value, movePath, source.Created, source.Updated) { Parent = target };
             var fileSource = source as FileInfoContract;
             if (fileSource != null)
                 return new FileInfoContract(source.Id.Value, movePath, source.Created, source.Updated, fileSource.Size, fileSource.Hash) { Directory = target };
             throw new InvalidOperationException($"Unsupported type '{source.GetType().Name}'");
         });
 }
Esempio n. 39
0
 public FileSystemInfoContract MoveItem(FileSystemInfoContract source, string movePath, DirectoryInfoContract destination)
 {
     return ExecuteInSemaphore(() => {
         return gateway.MoveItem(rootName, source.Id, movePath, destination.Id);
     }, nameof(MoveItem), true);
 }