[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));
        }
Beispiel #2
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")));
 }
        public void RootedStruct_IsDefault()
        {
            var file = new RootedFileSystemDirectory();

            Assert.True(file.IsDefault);
            file = FileSystemDirectory.Create("c:").AsRoot;
            Assert.False(file.IsDefault);
        }
Beispiel #4
0
        public void RecursiveDirectories()
        {
            var emptyRoot = FileSystemDirectory.Create("c:");

            Assert.True(emptyRoot is IEnumerable <FileSystemEntry>);
            Assert.Equal(0, emptyRoot.Count());             // using Linq exercises the enumerable

            Assert.Equal(3, this.root.Count());             // use Linq to exercise enumerator
            Assert.Equal(1, this.root.OfType <FileSystemDirectory>().Single().Count());
        }
        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);
        }
Beispiel #8
0
        public virtual FileSystemDirectory ToFileSystemDirectory(
            ImmutableObjectGraph.Optional <System.Collections.Immutable.ImmutableSortedSet <FileSystemEntry> > children = default(ImmutableObjectGraph.Optional <System.Collections.Immutable.ImmutableSortedSet <FileSystemEntry> >))
        {
            FileSystemDirectory that = this as FileSystemDirectory;

            if (that != null && this.GetType().IsEquivalentTo(typeof(FileSystemDirectory)))
            {
                if ((!children.IsDefined || children.Value == that.Children))
                {
                    return(that);
                }
            }

            return(FileSystemDirectory.Create(
                       pathSegment: this.PathSegment,
                       children: children));
        }
 public void EmptyPathSegment()
 {
     Assert.Throws <ArgumentNullException>(() => FileSystemDirectory.Create(null));
 }
        public void WithRootInUnrelatedTreeThrows()
        {
            var leaf = FileSystemDirectory.Create("z");

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