Ejemplo n.º 1
0
        public void RootedStruct_IsDefault()
        {
            var file = new RootedFileSystemDirectory();

            Assert.True(file.IsDefault);
            file = FileSystemDirectory.Create("c:").AsRoot;
            Assert.False(file.IsDefault);
        }
Ejemplo n.º 2
0
        [Fact(Skip = "Only works in debug")] // TODO: We need validation to be able to run in release too!
        public void ChildAddedTwiceThrowsWithMutation()
        {
            var root         = FileSystemDirectory.Create("c:");
            var child        = FileSystemFile.Create("a.txt");
            var mutatedChild = child.WithPathSegment("b.txt");   // same identity since we mutated an existing one.

            Assert.Throws <RecursiveChildNotUniqueException>(() => root.AddChildren(child).AddChildren(mutatedChild));
        }
Ejemplo n.º 3
0
 public FileSystemTests()
 {
     this.root = FileSystemDirectory.Create("c:").AddChildren(
         FileSystemFile.Create("a.cs"),
         FileSystemFile.Create("b.cs"),
         FileSystemDirectory.Create("c").AddChildren(
             FileSystemFile.Create("d.cs")));
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        public void TypeConversion()
        {
            FileSystemFile      file   = FileSystemFile.Create("a");
            FileSystemDirectory folder = file.ToFileSystemDirectory();

            Assert.Equal(file.PathSegment, folder.PathSegment);
            FileSystemFile fileAgain = folder.ToFileSystemFile();

            Assert.Equal(file.PathSegment, fileAgain.PathSegment);
        }
Ejemplo n.º 6
0
        public void RecursiveDirectories()
        {
            var emptyRoot = FileSystemDirectory.Create("c:");

            Assert.True(emptyRoot is IEnumerable <FileSystemEntry>);
            Assert.Empty(emptyRoot);            // using Linq exercises the enumerable

            Assert.Equal(3, this.root.Count()); // use Linq to exercise enumerator
            Assert.Single(this.root.OfType <FileSystemDirectory>().Single());
        }
Ejemplo n.º 7
0
        public void RemoveDescendent()
        {
            FileSystemDirectory subdir          = this.root.OfType <FileSystemDirectory>().First(d => d.Children.OfType <FileSystemFile>().Any());
            FileSystemFile      fileUnderSubdir = subdir.Children.OfType <FileSystemFile>().First();
            FileSystemDirectory updatedRoot     = this.root.RemoveDescendent(fileUnderSubdir);

            Assert.Equal(this.root.Identity, updatedRoot.Identity);
            FileSystemDirectory updatedSubdir = (FileSystemDirectory)updatedRoot.Single(c => c.Identity == subdir.Identity);

            Assert.DoesNotContain(fileUnderSubdir, updatedSubdir);
        }
Ejemplo n.º 8
0
        public void AddDescendent()
        {
            FileSystemDirectory subdir      = this.root.OfType <FileSystemDirectory>().First();
            FileSystemFile      newLeaf     = FileSystemFile.Create("added.txt");
            FileSystemDirectory updatedRoot = this.root.AddDescendent(newLeaf, subdir);

            Assert.Equal(this.root.Identity, updatedRoot.Identity);
            FileSystemDirectory updatedSubdir = updatedRoot.OfType <FileSystemDirectory>().First();

            Assert.Contains(newLeaf, updatedSubdir);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public void AddDescendentWithLookupTableFixup()
        {
            var root = this.GetRootWithLookupTable();
            FileSystemDirectory subdir      = root.OfType <FileSystemDirectory>().First();
            FileSystemFile      newLeaf     = FileSystemFile.Create("added.txt");
            FileSystemDirectory updatedRoot = root.AddDescendent(newLeaf, subdir);

            Assert.Equal(root.Identity, updatedRoot.Identity);
            FileSystemDirectory updatedSubdir = updatedRoot.OfType <FileSystemDirectory>().First();

            Assert.Contains(newLeaf, updatedSubdir);
        }
        public void RemoveDescendentWithLookupTableFixup()
        {
            var root = this.GetRootWithLookupTable();
            FileSystemDirectory subdir          = root.OfType <FileSystemDirectory>().First(d => d.Children.OfType <FileSystemFile>().Any());
            FileSystemFile      fileUnderSubdir = subdir.Children.OfType <FileSystemFile>().First();
            FileSystemDirectory updatedRoot     = root.RemoveDescendent(fileUnderSubdir);

            Assert.Equal(root.Identity, updatedRoot.Identity);
            FileSystemDirectory updatedSubdir = (FileSystemDirectory)updatedRoot.Single(c => c.Identity == subdir.Identity);

            Assert.False(updatedSubdir.Contains(fileUnderSubdir));
        }
Ejemplo n.º 12
0
        public void HasDescendent()
        {
            FileSystemFile file;
            var            root =
                FileSystemDirectory.Create(@"c:")
                .AddChild(
                    FileSystemDirectory.Create("dir")
                    .AddChild(file = FileSystemFile.Create("file")));
            var otherFile = FileSystemFile.Create("file2");

            Assert.True(root.HasDescendent(file));
            Assert.False(root.HasDescendent(otherFile));
            Assert.False(root.HasDescendent(root));
        }
Ejemplo n.º 13
0
        public void ChangesSinceWithPropertyChangeInChild()
        {
            var root1 = FileSystemDirectory.Create("c:").AddChildren(
                FileSystemFile.Create("file1.txt").AddAttributes("att1")).AsRoot;
            var root2 = root1["file1.txt"].AsFileSystemFile.AddAttributes("att2").Root;
            IReadOnlyList <FileSystemEntry.DiffGram> changes = root2.ChangesSince(root1);
            var changesList = changes.ToList();

            Assert.Single(changesList);
            Assert.Same(root1["file1.txt"].FileSystemEntry, changesList[0].Before);
            Assert.Same(root2["file1.txt"].FileSystemEntry, changesList[0].After);
            Assert.Equal(ChangeKind.Replaced, changesList[0].Kind);
            Assert.Equal(FileSystemEntryChangedProperties.Attributes, changesList[0].Changes);
        }
Ejemplo n.º 14
0
 public void EmptyPathSegment()
 {
     Assert.Throws <ArgumentNullException>(() => FileSystemDirectory.Create(null));
 }
Ejemplo n.º 15
0
        public void WithRootInUnrelatedTreeThrows()
        {
            var leaf = FileSystemDirectory.Create("z");

            Assert.Throws <ArgumentException>(() => leaf.WithRoot(this.root));
        }