From 6d4bff3aae97eea185862350bf3208ff4972a36d Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Thu, 1 Feb 2024 18:49:04 -0500 Subject: [PATCH] add child test --- .../PackageItemRootViewModel.cs | 2 +- .../PublishPackageViewModelTests.cs | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs index e8133cb67b2..b439581fd99 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageItemRootViewModel.cs @@ -133,7 +133,7 @@ internal void AddChildren(PackageItemRootViewModel item) } /// /// 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". /// diff --git a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs index 2de82641ae3..2f039048924 100644 --- a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs +++ b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs @@ -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 testDirs = new List { + { @"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); + } } }