public void ConvertRootedDirectoryToFile()
        {
            RootedFileSystemDirectory redDirectory = this.root.AsRoot.Children.Last().AsFileSystemDirectory;
            var redFile = redDirectory.ToFileSystemFile();

            Assert.True(redFile.Root.Children.Contains(redFile.AsFileSystemEntry));
        }
        public void ConvertRootedFileToDirectory()
        {
            RootedFileSystemFile      redFile      = this.root.AsRoot.Children.First().AsFileSystemFile;
            RootedFileSystemDirectory redDirectory = redFile.ToFileSystemDirectory();

            Assert.True(redDirectory.Root.Children.Contains(redDirectory.AsFileSystemEntry));
        }
        public void RedNodeWithBulkMethodOnRoot()
        {
            var redRoot = this.root.AsRoot;
            RootedFileSystemDirectory modifiedRoot = redRoot.With(pathSegment: "g");

            Assert.Equal("g", modifiedRoot.PathSegment);
        }
        public void RootedStruct_IsDefault()
        {
            var file = new RootedFileSystemDirectory();

            Assert.True(file.IsDefault);
            file = FileSystemDirectory.Create("c:").AsRoot;
            Assert.False(file.IsDefault);
        }
        public void RedNodeRecursiveParentCreate()
        {
            var drive = RootedFileSystemDirectory.Create("c:");

            Assert.Equal("c:", drive.PathSegment);
            Assert.True(drive.IsRoot);
            Assert.Equal(drive, drive.Root);
        }
        public void RootedStruct_ImplicitConversionToGreenNode()
        {
            RootedFileSystemDirectory rootedDrive   = RootedFileSystemDirectory.Create("c:");
            FileSystemDirectory       unrootedDrive = rootedDrive;

            Assert.Same(rootedDrive.FileSystemDirectory, unrootedDrive);
            FileSystemEntry unrootedEntry = rootedDrive;

            Assert.Same(rootedDrive.FileSystemDirectory, unrootedEntry);
        }
        private static void VerifyDescendentsShareRoot(RootedFileSystemDirectory directory)
        {
            foreach (var child in directory)
            {
                Assert.Same(directory.Root.FileSystemDirectory, child.Root.FileSystemDirectory);

                if (child.IsFileSystemDirectory)
                {
                    VerifyDescendentsShareRoot(child.AsFileSystemDirectory);
                }
            }
        }
        public void RedNodeConstructionAPI()
        {
            var redRoot = RootedFileSystemDirectory.Create("c:").AddChildren(
                FileSystemFile.Create("a.cs"),
                FileSystemFile.Create("b.cs"),
                FileSystemDirectory.Create("c")
                .AddChildren(FileSystemFile.Create("d.cs")));

            Assert.Equal("c:", redRoot.PathSegment);
            Assert.Equal(3, redRoot.Children.Count);
            Assert.Equal("d.cs", redRoot.Children.Single(c => c.IsFileSystemDirectory).AsFileSystemDirectory.Children.Single().PathSegment);
        }
        public void RedNodeStuff()
        {
            var redRoot = this.root.AsRoot;

            Assert.Equal(this.root.PathSegment, redRoot.PathSegment);
            Assert.Equal(this.root.Children.Count, redRoot.Children.Count);
            Assert.True(redRoot.Children.Any(c => c.PathSegment == "a.cs" && c.IsFileSystemFile));
            Assert.True(redRoot.Children.Any(c => c.PathSegment == "b.cs" && c.IsFileSystemFile));

            RootedFileSystemDirectory subdir = redRoot.Children.Last().AsFileSystemDirectory;

            Assert.Equal("d.cs", subdir.Children.Single().PathSegment);
        }
        public void RootedStruct_EqualityOperators()
        {
            var r1a = RootedFileSystemDirectory.Create("foo");
            var r1b = r1a;             // struct copy
            var r2  = RootedFileSystemDirectory.Create("foo");

            // Compare two structs with the same underlying green node reference.
            Assert.True(r1a == r1b);
            Assert.False(r1a != r1b);

            // Compare two structs with different underlying green node references.
            Assert.False(r1a == r2);
            Assert.True(r1a != r2);

            // Now verify the root node reference aspect to it.
            var newRoot = RootedFileSystemDirectory.Create("c:")
                          .AddChild(r1a.FileSystemDirectory).Parent;
            var r1Rerooted = r1a.FileSystemDirectory.WithRoot(newRoot);

            Assert.False(r1a == r1Rerooted);
            Assert.True(r1a != r1Rerooted);
        }