예제 #1
0
        public void ResolvePath_WhereBasePathIsRoot_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

            compositionFixture.ExportGateway(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");
        }
        public void RemoveItem_WherePathIsFile_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

            gatewayMock.Setup(g => g.RemoveItem(rootName, new FileId(@"\File.ext"), false)).Verifiable();
            compositionFixture.ExportGateway(gatewayMock.Object);

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

            gatewayMock.VerifyAll();
        }
        public void ClearContent_WhereNodeIsFile_ClearsContent()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var content            = TestContent.MultiLineTestContent.Select(c => Convert.ToByte(c)).ToArray();

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

            gatewayMock.Setup(g => g.ClearContent(rootName, new FileId(@"\File.ext"))).Verifiable();
            compositionFixture.ExportGateway(gatewayMock.Object);

            var pipelineFixture = new PipelineFixture();

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

            gatewayMock.VerifyAll();
        }
        public void RenameItem_WherePathIsFile_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

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

            gatewayMock.Setup(g => g.RenameItem(rootName, new FileId(@"\File.ext"), "FileRenamed.ext"))
            .Returns(new FileInfoContract(original.Id.Value.Replace("File", "FileRenamed"), original.Name.Replace("File", "FileRenamed"), original.Created, original.Updated, original.Size, null))
            .Verifiable();
            compositionFixture.ExportGateway(gatewayMock.Object);

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

            gatewayMock.VerifyAll();
        }
예제 #5
0
        public void GetChildItem_WherePathIsRoot_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;

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

            compositionFixture.ExportGateway(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());
        }
        public void GetContent_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.InitializeGetChildItems(rootName, @"\", rootDirectoryItems);

            gatewayMock.SetupSequence(g => g.GetContent(rootName, new FileId(@"\File.ext")))
            .Returns(content)
            .Throws(new InvalidOperationException(@"Redundant access to \File.ext"));
            compositionFixture.ExportGateway(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");
        }
        public void SetContent_WhereNodeIsFileAndEncodingIsByte_AcceptsContent()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var content            = TestContent.MultiLineTestContent.Select(c => Convert.ToByte(c)).ToArray();

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

            gatewayMock.Setup(g => g.ClearContent(rootName, new FileId(@"\File.ext"))).Verifiable();
            gatewayMock.Setup(g => g.SetContent(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))).Verifiable();
            compositionFixture.ExportGateway(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();
        }
예제 #8
0
        public void NewItem_WherePathIsRootAndItemTypeIsDirectory_CallsGatewayCorrectly()
        {
            var rootName           = FileSystemFixture.GetRootName();
            var rootDirectoryItems = fileSystemFixture.RootDirectoryItems;
            var newItem            = new DirectoryInfoContract(@"\SubDir", "SubDir", DateTime.Now, DateTime.Now);

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

            gatewayMock.Setup(g => g.NewDirectoryItem(rootName, new DirectoryId(@"\"), "NewSubDir"))
            .Returns(newItem)
            .Verifiable();
            compositionFixture.ExportGateway(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();
        }