public void ChangesSinceLoneFile()
        {
            // try a case-only change to the path segment.
            var file1   = FileSystemFile.Create("a.txt");
            var file2   = file1.WithPathSegment("A.txt");
            var changes = file2.ChangesSince(file1);

            Assert.Equal(1, changes.Count);
            Assert.Equal(ChangeKind.Replaced, changes[0].Kind);
            Assert.Equal(FileSystemEntryChangedProperties.PathSegment, changes[0].Changes);

            var file3 = file2.AddAttributes("someattribute");

            changes = file3.ChangesSince(file1);
            Assert.Equal(1, changes.Count);
            Assert.Equal(ChangeKind.Replaced, changes[0].Kind);
            Assert.Equal(FileSystemEntryChangedProperties.PathSegment | FileSystemEntryChangedProperties.Attributes, changes[0].Changes);

            var file3_reverted = file2.RemoveAttributes("someattribute");

            changes = file3_reverted.ChangesSince(file1);
            Assert.Equal(1, changes.Count);
            Assert.Equal(ChangeKind.Replaced, changes[0].Kind);
            Assert.Equal(FileSystemEntryChangedProperties.PathSegment, changes[0].Changes);

            changes = file3_reverted.ChangesSince(file3);
            Assert.Equal(1, changes.Count);
            Assert.Equal(ChangeKind.Replaced, changes[0].Kind);
            Assert.Equal(FileSystemEntryChangedProperties.Attributes, changes[0].Changes);
        }
        private FileSystemDirectory GetRootWithLookupTable()
        {
            // Fill in a bunch of children to force the creation of a lookup table.
            var root = this.root.AddChildren(Enumerable.Range(100, 30).Select(n => FileSystemFile.Create("filler" + n)));

            return(root);
        }
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")));
 }
        [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.º 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);
        }
        public FileSystemEntry this[string pathSegment] {
            get {
                int index = this.children.IndexOf(FileSystemFile.Create(pathSegment));
                if (index < 0)
                {
                    throw new IndexOutOfRangeException();
                }

                return(this.children[index]);
            }
        }
        public        RootedFileSystemEntry this[string pathSegment] {
            get {
                int index = this.greenNode.Children.IndexOf(FileSystemFile.Create(pathSegment));
                if (index < 0)
                {
                    throw new IndexOutOfRangeException();
                }

                return(this.greenNode.Children[index].WithRoot(this.root));
            }
        }
        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.True(updatedSubdir.Contains(newLeaf));
        }
        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.True(updatedSubdir.Contains(newLeaf));
        }
        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 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));
        }
        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.Equal(1, changesList.Count);
            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.º 13
0
        public virtual FileSystemFile ToFileSystemFile(
            ImmutableObjectGraph.Optional <System.Collections.Immutable.ImmutableHashSet <System.String> > attributes = default(ImmutableObjectGraph.Optional <System.Collections.Immutable.ImmutableHashSet <System.String> >))
        {
            FileSystemFile that = this as FileSystemFile;

            if (that != null && this.GetType().IsEquivalentTo(typeof(FileSystemFile)))
            {
                if ((!attributes.IsDefined || attributes.Value == that.Attributes))
                {
                    return(that);
                }
            }

            return(FileSystemFile.Create(
                       pathSegment: this.PathSegment,
                       attributes: attributes));
        }
Ejemplo n.º 14
0
 public void ReplaceDescendentNotFound()
 {
     Assert.Throws <ArgumentException>(() => this.root.ReplaceDescendent(FileSystemFile.Create("nonexistent"), FileSystemFile.Create("replacement")));
 }
Ejemplo n.º 15
0
 public void NonRecursiveFiles()
 {
     Assert.False(FileSystemFile.Create("a") is System.Collections.IEnumerable);
 }