Skip to content

Commit

Permalink
add child test
Browse files Browse the repository at this point in the history
  • Loading branch information
zeusongit committed Feb 1, 2024
1 parent 506977f commit 6d4bff3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ internal void AddChildren(PackageItemRootViewModel item)
}
/// <summary>
/// The methods is used for adding a child item to all the encountered parent folders in a nested path
/// and make sure all the intermediate file paths are created as separte PackageItemRootViewModel.
/// and make sure all the intermediate file paths are created as separate PackageItemRootViewModel.
/// For example if we have a path like "\dir1\dir2\dir3" and we want to add a child item to "dir1", the method will
/// add "dir 3" to "dir2" and then "dir2" to "dir1".
/// </summary>
Expand Down
42 changes: 42 additions & 0 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,5 +258,47 @@ public void AssertIsSubPathOfDeep_IsSuccessful()
Assert.AreEqual(testDir.Value, newPkgVm.IsSubPathOfDeep(new PackageItemRootViewModel(paths[0]), new PackageItemRootViewModel(paths[1])));
}
}
[Test]
public void AssertAddChildRecursively_IsSuccessful()
{
//arrange
List<string> testDirs = new List<string> {
{ @"C:\Package\bin\Dir1\Dir3" },
{ @"C:\Package\bin\Dir2\Dir3" },
{ @"C:\Package\bin\Dir3\Dir4" },
};
var root = new PackageItemRootViewModel(@"C:\Package");

//assert
foreach (var testDir in testDirs)
{
root.AddChildRecursively(new PackageItemRootViewModel(testDir));
}

var bin = root.ChildItems.First();
var d1 = bin.ChildItems.ElementAt(0);
var d2 = bin.ChildItems.ElementAt(1);
var d3 = bin.ChildItems.ElementAt(2);


Assert.IsTrue(root.ChildItems.Count == 1);
Assert.IsTrue(root.ChildItems.Select(x => x.DirectoryName.EndsWith("bin")).Any());

Assert.IsTrue(bin.ChildItems.Count == 3);
Assert.IsTrue(bin.ChildItems.Select(x => x.DirectoryName.EndsWith("Dir1")).Any());
Assert.IsTrue(bin.ChildItems.Select(x => x.DirectoryName.EndsWith("Dir2")).Any());
Assert.IsTrue(bin.ChildItems.Select(x => x.DirectoryName.EndsWith("Dir3")).Any());

Assert.IsTrue(d1.ChildItems.Count == 1);
Assert.IsTrue(d2.ChildItems.Count == 1);
Assert.IsTrue(d3.ChildItems.Count == 1);
Assert.IsTrue(d1.ChildItems.Select(x => x.DirectoryName.EndsWith("Dir3")).Any());
Assert.IsTrue(d2.ChildItems.Select(x => x.DirectoryName.EndsWith("Dir3")).Any());
Assert.IsTrue(d3.ChildItems.Select(x => x.DirectoryName.EndsWith("Dir4")).Any());

Assert.IsTrue(d1.ChildItems.First().ChildItems.Count == 0);
Assert.IsTrue(d2.ChildItems.First().ChildItems.Count == 0);
Assert.IsTrue(d3.ChildItems.First().ChildItems.Count == 0);
}
}
}

0 comments on commit 6d4bff3

Please sign in to comment.