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

            Assert.True(file.IsDefault);
            file = FileSystemDirectory.Create("c:").AsRoot;
            Assert.False(file.IsDefault);
        }
 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 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);
        }
 public void EmptyPathSegment()
 {
     Assert.Throws <ArgumentNullException>(() => FileSystemDirectory.Create(null));
 }
        public void WithRootInUnrelatedTreeThrows()
        {
            var leaf = FileSystemDirectory.Create("z");

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