public new FileSystemDirectory ToImmutable() { var children = this.children.IsDefined ? (this.children.Value != null ? this.children.Value.ToImmutable() : null) : this.immutable.Children; return(this.immutable = this.immutable.With( ImmutableObjectGraph.Optional.For(this.PathSegment), ImmutableObjectGraph.Optional.For(children))); }
[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 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); }
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 void RootedStruct_ImplicitConversionToGreenNode() { RootedFileSystemDirectory rootedDrive = RootedFileSystemDirectory.Create("c:"); FileSystemDirectory unrootedDrive = rootedDrive; Assert.Same(rootedDrive.FileSystemDirectory, unrootedDrive); FileSystemEntry unrootedEntry = rootedDrive; Assert.Same(rootedDrive.FileSystemDirectory, unrootedEntry); }
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 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 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.False(updatedSubdir.Contains(fileUnderSubdir)); }
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 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 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 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 WithRootInUnrelatedTreeThrows() { var leaf = FileSystemDirectory.Create("z"); Assert.Throws <ArgumentException>(() => leaf.WithRoot(this.root)); }
internal Builder(FileSystemDirectory immutable) : base(immutable) { this.immutable = immutable; }
public void EmptyPathSegment() { Assert.Throws <ArgumentNullException>(() => FileSystemDirectory.Create(null)); }