コード例 #1
0
        public void ResolvePath_WhereBasePathIsRoot_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(new string[] {
                FileSystemFixture.NewDriveCommand,
                @"Resolve-Path X:\*"
            });

            Assert.AreEqual(rootDirectoryItems.Length, result.Count, "Unexpected number of results");
            CollectionAssert.AllItemsAreInstancesOfType(result.Select(i => i.BaseObject).ToList(), typeof(PathInfo), "Result is not of type PathInfo");
        }
コード例 #2
0
        public void RenameItemAsync_WherePathIsFile_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

            var original = (FileInfoContract)rootDirectoryItems.Single(i => i.Name == "File.ext");

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

            gatewayMock.Setup(g => g.RenameItemAsync(rootName, new FileId(@"\File.ext"), "FileRenamed.ext", It.IsAny <Func <FileSystemInfoLocator> >()))
            .ReturnsAsync(new FileInfoContract(original.Id.Value.Replace("File", "FileRenamed"), original.Name.Replace("File", "FileRenamed"), original.Created, original.Updated, original.Size, null))
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Rename-Item -Path X:\File.ext -NewName FileRenamed.ext"
                );

            gatewayMock.VerifyAll();
        }
コード例 #3
0
        public void SetContentAsync_WhereNodeIsFileAndEncodingIsByte_AcceptsContent()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var content            = TestContent.MultiLineTestContent.Select(c => Convert.ToByte(c)).ToArray();

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

            gatewayMock.Setup(g => g.ClearContentAsync(rootName, new FileId(@"\File.ext"), It.IsAny <Func <FileSystemInfoLocator> >()))
            .ReturnsAsync(true)
            .Verifiable();
            gatewayMock.Setup(g => g.SetContentAsync(rootName, new FileId(@"\File.ext"), It.Is <Stream>(s => new BinaryReader(s, System.Text.Encoding.Default, true).ReadBytes((int)s.Length).SequenceEqual(content)), It.Is <IProgress <ProgressValue> >(p => true), It.IsAny <Func <FileSystemInfoLocator> >()))
            .ReturnsAsync(true)
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var pipelineFixture = new PipelineFixture();

            pipelineFixture.SetVariable("value", content);
            pipelineFixture.Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Set-Content -Path X:\File.ext $value -Encoding Byte"
                );

            gatewayMock.VerifyAll();
        }
コード例 #4
0
        public void RemoveItemAsync_WherePathIsFile_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

            gatewayMock.Setup(g => g.RemoveItemAsync(rootName, new FileId(@"\File.ext"), false))
            .ReturnsAsync(true)
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Remove-Item -Path X:\File.ext"
                );

            gatewayMock.VerifyAll();
        }
コード例 #5
0
        public void ClearContentAsync_WhereNodeIsFile_ClearsContent()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var content            = TestContent.MultiLineTestContent.Select(c => Convert.ToByte(c)).ToArray();

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

            gatewayMock.Setup(g => g.ClearContentAsync(rootName, new FileId(@"\File.ext"), It.IsAny <Func <FileSystemInfoLocator> >()))
            .ReturnsAsync(true)
            .Verifiable();
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var pipelineFixture = new PipelineFixture();

            pipelineFixture.SetVariable("value", content);
            pipelineFixture.Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Clear-Content -Path X:\File.ext"
                );

            gatewayMock.VerifyAll();
        }
コード例 #6
0
        public void GetChildItemAsync_WherePathIsRoot_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

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

            Assert.AreEqual(rootDirectoryItems.Length, result.Count, "Unexpected number of results");
            CollectionAssert.AreEquivalent(rootDirectoryItems, result.Select(p => p.BaseObject).Cast <FileSystemInfoContract>().ToList());
        }
コード例 #7
0
        public void GetContentAsync_WhereNodeIsFileAndEncodingIsByte_ReturnsContent()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var content            = new MemoryStream(TestContent.MultiLineTestContent.Select(c => Convert.ToByte(c)).ToArray());

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

            gatewayMock.SetupSequence(g => g.GetContentAsync(rootName, new FileId(@"\File.ext")))
            .ReturnsAsync(content)
            .ThrowsAsync(new InvalidOperationException(@"Redundant access to \File.ext"));
            compositionFixture.ExportAsyncGateway(gatewayMock.Object);

            var result = new PipelineFixture().Invoke(
                FileSystemFixture.NewDriveCommand,
                @"Get-Content -Path X:\File.ext -Encoding Byte"
                );

            CollectionAssert.AreEqual(content.ToArray(), result.Select(p => p.BaseObject).ToArray(), "Mismatching content");
        }
コード例 #8
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();
        }