diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs index 3cb1025dafb..d82f87e742e 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs @@ -8,7 +8,6 @@ using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Windows; using System.Windows.Forms; @@ -1052,7 +1051,12 @@ private bool IsDuplicateFile(PackageItemRootViewModel item1, PackageItemRootView } } - private List BindParentToChild(Dictionary items) + /// + /// Attempts to recreate the file/folder content structure + /// + /// A dictionary of the content items + /// + internal List BindParentToChild(Dictionary items) { foreach (var parent in items) { @@ -1082,25 +1086,61 @@ private List GetRootItems(Dictionary !x.isChild).ToList(); if (!rootItems.Any()) return rootItems; - var packageSourceDir = CurrentPackageDirectory ??= GetLongestCommonPrefix(items.Keys.ToArray()); - var root = new PackageItemRootViewModel(packageSourceDir); - var updatedItems = new List(); - //check each root item and create any missing connections + var roots = new List(); + + if (CurrentPackageDirectory != null) + { + roots.Add(new PackageItemRootViewModel(CurrentPackageDirectory)); + } + else + { + var commonPaths = GetCommonPaths(items.Keys.ToArray()); + if (commonPaths == null) return null; + + // Add a new root item for each common path found + commonPaths.ForEach(p => roots.Add(new PackageItemRootViewModel(p))); + } + + // Check each root item and create any missing connections foreach (var item in rootItems) { + bool itemAssigned = false; var itemDir = new DirectoryInfo(item.DirectoryName); - if (!itemDir.Parent.FullName.Equals(packageSourceDir)) + + foreach (var root in roots) { - root.AddChildRecursively(item); + var rootDir = new DirectoryInfo(root.DirectoryName); + + if (itemDir.FullName.StartsWith(rootDir.FullName, StringComparison.OrdinalIgnoreCase)) + { + if (itemDir.Parent.FullName.Equals(rootDir.FullName)) + { + root.ChildItems.Add(item); + } + else + { + root.AddChildRecursively(item); + } + itemAssigned = true; + break; + } } - else + + // If the item does not belong to any existing root, create a new root for it + if (!itemAssigned) { - root.ChildItems.Add(item); + var newRoot = new PackageItemRootViewModel(item.DirectoryName); + newRoot.ChildItems.Add(item); + roots.Add(newRoot); } } - return root.ChildItems.ToList(); - } + + // Collect all child items from all roots + var allChildItems = roots.SelectMany(r => r.ChildItems).ToList(); + + return allChildItems; + } /// /// Test if path2 is subpath of path1 @@ -1132,22 +1172,56 @@ internal bool IsSubPathOfDeep(PackageItemRootViewModel path1, PackageItemRootVie /// /// Utility method to get the common file path, this may fail for files with the same partial name. /// - /// A collection of filepaths + /// A collection of file paths /// - internal string GetLongestCommonPrefix(string[] s) + internal List GetCommonPaths(string[] paths) { - int k = s[0].Length; - for (int i = 1; i < s.Length; i++) + if (paths == null || paths.Length == 0) + return new List(); + + // Group paths by their root (drive letter) + var groupedPaths = paths.GroupBy(p => Path.GetPathRoot(p)).ToList(); + List commonPaths = new List(); + + foreach (var group in groupedPaths) { - k = Math.Min(k, s[i].Length); - for (int j = 0; j < k; j++) - if (s[i][j] != s[0][j]) + var pathArray = group.ToArray(); + if (pathArray.Length == 1) + { + commonPaths.Add(Path.GetDirectoryName(pathArray[0])); + continue; + } + + var k = pathArray[0].Length; + for (var i = 1; i < pathArray.Length; i++) + { + k = Math.Min(k, pathArray[i].Length); + for (var j = 0; j < k; j++) { - k = j; - break; + if (pathArray[i][j] != pathArray[0][j]) + { + k = j; + break; + } } + } + + var commonPrefix = pathArray[0].Substring(0, k); + var commonDir = Path.GetDirectoryName(commonPrefix); + + if (string.IsNullOrEmpty(commonDir)) + { + // Special case for the root directory + commonDir = Path.GetPathRoot(commonPrefix); + } + + if (!string.IsNullOrEmpty(commonDir)) + { + commonPaths.Add(commonDir); + } } - return Path.GetDirectoryName(s[0].Substring(0, k)); + + return commonPaths.Distinct().ToList(); } /// @@ -1897,7 +1971,7 @@ private void SelectDirectoryAndAddFilesRecursively() } /// - /// Combines adding files from single file prompt and files in folders propt + /// Combines adding files from single file prompt and files in folders prompt /// /// internal void AddAllFilesAfterSelection(List filePaths, string rootFolder = null) @@ -2033,7 +2107,10 @@ private void RemoveSingleItem(PackageItemRootViewModel vm, DependencyType fileTy CustomNodeDefinitions.Remove(CustomNodeDefinitions .First(x => x.DisplayName == fileName)); - CustomDyfFilepaths.Remove(fileName + ".dyf"); + var keyToRemove = CustomDyfFilepaths.Keys + .FirstOrDefault(k => Path.GetFileNameWithoutExtension(k) == fileName); + + if(keyToRemove != null) CustomDyfFilepaths.Remove(keyToRemove); } else { @@ -2665,6 +2742,7 @@ private void PreviewPackageBuild() } } + // Removes duplicate file names, retaining only the first encounter file path for each unique file name files = files.GroupBy(file => Path.GetFileName(file), StringComparer.OrdinalIgnoreCase) .Select(group => group.First()) .ToList(); @@ -2735,12 +2813,12 @@ internal PackageItemRootViewModel GetPreBuildRootItemViewModel(string publishPat var doc = new PackageItemRootViewModel(new FileInfo(Path.Combine(docDir, fileName))); docItemPreview.AddChildRecursively(doc); } - else if (file.EndsWith(".dyf")) + else if (file.ToLower().EndsWith(".dyf")) { var dyfPreview = new PackageItemRootViewModel(fileName, Path.Combine(dyfDir, fileName)); dyfItemPreview.AddChildRecursively(dyfPreview); } - else if (file.EndsWith(".dll") || PackageDirectoryBuilder.IsXmlDocFile(file, files) || PackageDirectoryBuilder.IsDynamoCustomizationFile(file, files)) + else if (file.ToLower().EndsWith(".dll") || PackageDirectoryBuilder.IsXmlDocFile(file, files) || PackageDirectoryBuilder.IsDynamoCustomizationFile(file, files)) { // Assemblies carry the information if they are NodeLibrary or not if(Assemblies.Any(x => x.Name.Equals(Path.GetFileNameWithoutExtension(fileName)))) diff --git a/src/DynamoPackages/PackageDirectoryBuilder.cs b/src/DynamoPackages/PackageDirectoryBuilder.cs index 844249560ac..2b5873d7d31 100644 --- a/src/DynamoPackages/PackageDirectoryBuilder.cs +++ b/src/DynamoPackages/PackageDirectoryBuilder.cs @@ -64,6 +64,14 @@ public IDirectoryInfo BuildDirectory(Package package, string packagesDirectory, return rootDir; } + /// + /// Attempts to recreate the file/folder structure from an existing data + /// + /// The package to be formed + /// The parent directory (the published folder or the default packages directory) + /// The collection of files to be moved + /// Separately provided markdown files + /// public IDirectoryInfo BuildRetainDirectory(Package package, string packagesDirectory, IEnumerable> contentFiles, IEnumerable markdownFiles) { @@ -127,7 +135,7 @@ private void RemapRetainCustomNodeFilePaths(IEnumerable filePaths, List< private void RemoveRetainDyfFiles(IEnumerable filePaths, List dyfFiles) { var dyfsToRemove = filePaths - .Where(x => x.EndsWith(".dyf") && fileSystem.FileExists(x) && Path.GetDirectoryName(x) != Path.GetDirectoryName(dyfFiles.First(f => Path.GetFileName(f).Equals(Path.GetFileName(x))))); + .Where(x => x.ToLower().EndsWith(".dyf") && fileSystem.FileExists(x) && Path.GetDirectoryName(x) != Path.GetDirectoryName(dyfFiles.First(f => Path.GetFileName(f).Equals(Path.GetFileName(x))))); foreach (var dyf in dyfsToRemove) { @@ -138,7 +146,7 @@ private void RemoveRetainDyfFiles(IEnumerable filePaths, List dy private void RemoveDyfFiles(IEnumerable filePaths, IDirectoryInfo dyfDir) { var dyfsToRemove = filePaths - .Where(x => x.EndsWith(".dyf") && fileSystem.FileExists(x) && Path.GetDirectoryName(x) != dyfDir.FullName); + .Where(x => x.ToLower().EndsWith(".dyf") && fileSystem.FileExists(x) && Path.GetDirectoryName(x) != dyfDir.FullName); foreach (var dyf in dyfsToRemove) { @@ -227,7 +235,8 @@ internal void CopyFilesIntoRetainedPackageDirectory(IEnumerable files, IEnumerab { targetFolder = docDirPath; } - else if (file.EndsWith(".dyf")) + else if (file.ToLower().EndsWith(".dyf")) { targetFolder = dyfDirPath; } - else if (file.EndsWith(".dll") || IsXmlDocFile(file, files) || IsDynamoCustomizationFile(file, files)) + else if (file.ToLower().EndsWith(".dll") || IsXmlDocFile(file, files) || IsDynamoCustomizationFile(file, files)) { targetFolder = binDirPath; } diff --git a/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs b/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs index a74c61f7f4e..7e0a40446fe 100644 --- a/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs +++ b/test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs @@ -2218,7 +2218,7 @@ public void CanRemoveAllDependencyTypes() // This makes sense as we don't want to try to establish 'common parent' for folders that maybe too far apart in a tree structure rootFolder = vm.PackageContents.Where(x => x.DependencyType.Equals(DependencyType.Folder)); Assert.AreEqual(1, rootFolder.Count()); - Assert.AreEqual(4, PackageItemRootViewModel.GetFiles(rootFolder.First()).Count()); + Assert.AreEqual(3, PackageItemRootViewModel.GetFiles(rootFolder.First()).Count()); // the 'doc' folder + the 2 files inside of it Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(rootFolder.First())); Assert.IsFalse(vm.PackageContents.Any()); @@ -2321,8 +2321,8 @@ public void AssertPreviewPackageRetainFolderStructureEqualsPublishLocalPackageRe var createdFolders = Directory.GetDirectories(publishPath, "*", SearchOption.AllDirectories).ToList(); // Assert - Assert.AreEqual(createdFiles.Count(), previewFiles.Count() + 1); - Assert.AreEqual(1, createdFolders.Count(), previewFolders.Count()); // One subfolder was created + Assert.AreEqual(createdFiles.Count(), previewFiles.Count()); + Assert.AreEqual(0, createdFolders.Count()); // When single root, no nested folders should be created // Clean up Directory.Delete(publishPath, true); @@ -2361,8 +2361,8 @@ public void AssertPreviewPackageRetainFolderStructureEqualsPublishLocalPackageRe var createdFolders = Directory.GetDirectories(publishPath, "*", SearchOption.AllDirectories).ToList(); // Assert - Assert.AreEqual(createdFiles.Count(), previewFiles.Count() + 1); - Assert.AreEqual(1, createdFolders.Count(), previewFolders.Count()); // One subfolder was created + Assert.AreEqual(createdFiles.Count(), previewFiles.Count()); + Assert.AreEqual(0, createdFolders.Count()); // When single root, no nested folders should be created // Clean up Directory.Delete(publishPath, true); diff --git a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs index 2f039048924..15c71389dce 100644 --- a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs +++ b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs @@ -14,13 +14,13 @@ namespace DynamoCoreWpfTests { [TestFixture] - public class PublishPackageViewModelTests: DynamoViewModelUnitTest + public class PublishPackageViewModelTests : DynamoViewModelUnitTest { [Test] public void AddingDyfRaisesCanExecuteChangeOnDelegateCommand() { - + var vm = new PublishPackageViewModel(ViewModel); ViewModel.OnRequestPackagePublishDialog(vm); @@ -54,12 +54,12 @@ public void SetsErrorState() string dyfpath = Path.Combine(first, "dyf"); var customnodes = Directory.GetFiles(dyfpath); var firstnode = customnodes.First(); - + OpenModel(firstnode); //add a preset so that customnode has changes that are unsaved GetModel().CurrentWorkspace.AddPreset("a useless preset", "some thing that will modify the definition", - new List(){GetModel().CurrentWorkspace.Nodes.First().GUID}); + new List() { GetModel().CurrentWorkspace.Nodes.First().GUID }); Assert.IsTrue(GetModel().CurrentWorkspace.HasUnsavedChanges); @@ -72,7 +72,7 @@ public void SetsErrorState() vm.PublishLocallyCommand.Execute(); //assert that we have not uploaded the file or indicated that we have - Assert.AreNotEqual(vm.UploadState,PackageUploadHandle.State.Uploaded); + Assert.AreNotEqual(vm.UploadState, PackageUploadHandle.State.Uploaded); Console.WriteLine(vm.ErrorString); } @@ -81,7 +81,7 @@ public void SetsErrorState() public void CanPublishLateInitializedJsonCustomNode() { - string nodePath = Path.Combine(TestDirectory,"core","CustomNodes", "jsonCustomNode.dyf"); + string nodePath = Path.Combine(TestDirectory, "core", "CustomNodes", "jsonCustomNode.dyf"); //add this customNode to the package without opening it. var vm = new PublishPackageViewModel(this.ViewModel); @@ -92,7 +92,7 @@ public void CanPublishLateInitializedJsonCustomNode() //- this will check the customNode has no unsaved changes. Assert.AreEqual(1, vm.CustomNodeDefinitions.Count); - Assert.DoesNotThrow(() => {vm.GetAllFiles();}); + Assert.DoesNotThrow(() => { vm.GetAllFiles(); }); Assert.AreEqual(nodePath, vm.GetAllFiles().First()); } @@ -118,7 +118,7 @@ public void NewPackageDoesNotThrow_NativeBinaryIsAddedAsAdditionalFile_NotBinary { vm = PublishPackageViewModel.FromLocalPackage(ViewModel, package, false); }); - + Assert.AreEqual(1, vm.AdditionalFiles.Count); Assert.AreEqual(0, vm.Assemblies.Count); @@ -184,7 +184,7 @@ public void NewPackageVersionUpload_CanAddAndRemoveFiles() //arrange node libraries var assem = vm.Assemblies.FirstOrDefault().Assembly; - var nodeLibraryNames = (IEnumerable) new [] { assem.FullName }; + var nodeLibraryNames = (IEnumerable)new[] { assem.FullName }; //act var pa = PublishPackageViewModel.GetPackageAssembly(nodeLibraryNames, assem); @@ -212,7 +212,7 @@ public void PublishingACustomNodeSetsPackageInfoCorrectly_() Assert.IsFalse(GetModel().CustomNodeManager.NodeInfos[cnworkspace.CustomNodeId].IsPackageMember); //now lets publish this node as a local package. - var newPkgVm = new PublishPackageViewModel(ViewModel) { CustomNodeDefinitions = new List(){ cnworkspace.CustomNodeDefinition } }; + var newPkgVm = new PublishPackageViewModel(ViewModel) { CustomNodeDefinitions = new List() { cnworkspace.CustomNodeDefinition } }; newPkgVm.Name = "PublishingACustomNodeSetsPackageInfoCorrectly"; newPkgVm.MajorVersion = "0"; newPkgVm.MinorVersion = "0"; @@ -220,11 +220,11 @@ public void PublishingACustomNodeSetsPackageInfoCorrectly_() newPkgVm.PublishLocallyCommand.Execute(); Assert.IsTrue(GetModel().GetPackageManagerExtension().PackageLoader.LocalPackages.Any - (x => x.Name == "PublishingACustomNodeSetsPackageInfoCorrectly" && x.LoadState.State == PackageLoadState.StateTypes.Loaded && x.LoadedCustomNodes.Count ==1)); + (x => x.Name == "PublishingACustomNodeSetsPackageInfoCorrectly" && x.LoadState.State == PackageLoadState.StateTypes.Loaded && x.LoadedCustomNodes.Count == 1)); - Assert.AreEqual(new PackageInfo("PublishingACustomNodeSetsPackageInfoCorrectly", new Version(0,0,1)) - ,GetModel().CustomNodeManager.NodeInfos[cnworkspace.CustomNodeId].PackageInfo); + Assert.AreEqual(new PackageInfo("PublishingACustomNodeSetsPackageInfoCorrectly", new Version(0, 0, 1)) + , GetModel().CustomNodeManager.NodeInfos[cnworkspace.CustomNodeId].PackageInfo); Assert.IsFalse(GetModel().CustomNodeManager.NodeInfos[cnworkspace.CustomNodeId].IsPackageMember); } @@ -300,5 +300,195 @@ public void AssertAddChildRecursively_IsSuccessful() Assert.IsTrue(d2.ChildItems.First().ChildItems.Count == 0); Assert.IsTrue(d3.ChildItems.First().ChildItems.Count == 0); } + + [Test] + public void EnsureMultipleVersionsOfAssembly_CannotBeLoaded() + { + var vm = new PublishPackageViewModel(ViewModel); + ViewModel.OnRequestPackagePublishDialog(vm); + + //arrange the first assembly version + string packagedirectory = Path.Combine(TestDirectory, "pkgs\\PackageManager\\1.0"); + var version_1 = Directory.GetFiles(packagedirectory); + var firstAssembly = version_1.First(); + + //add the first assembly version file + vm.AddFile(firstAssembly); + + //assert that we have successfully added the assembly + Assert.AreEqual(vm.Assemblies.Count, 1); + + //arrange the second assembly version + packagedirectory = Path.Combine(TestDirectory, "pkgs\\PackageManager\\2.0"); + var version_2 = Directory.GetFiles(packagedirectory); + var secondAssembly = version_2.First(); + + //now add the second assembly version file + vm.AddFile(secondAssembly); + + //TODO: assert - do we expect to see 1 or 2 here? + Assert.AreEqual(vm.Assemblies.Count, 1); + } + + + #region CreateContentsRelationships + + [Test] + public void CreatesCorrectRelationships_ControlTest() + { + var vm = new PublishPackageViewModel(ViewModel); + var items = new Dictionary(); + var files = new[] { new FileInfo(@"C:\pkg\file1.dyn"), new FileInfo(@"C:\pkg\file2.DYN") }; + + foreach (var file in files) + { + var item = new PackageItemRootViewModel(file); + if (String.IsNullOrEmpty(item.DirectoryName)) continue; + if (!items.ContainsKey(item.DirectoryName)) + { + var root = new PackageItemRootViewModel(item.DirectoryName); + + root.ChildItems.Add(item); + items[item.DirectoryName] = root; + } + else + { + items[item.DirectoryName].ChildItems.Add(item); + } + } + + List result = vm.BindParentToChild(items); + + Assert.AreEqual(1, result.Count); + Assert.AreEqual(2, result.First().ChildItems.Count); + } + + + [Test] + public void CreatesCorrectRelationships_UncommonRootsTest() + { + var vm = new PublishPackageViewModel(ViewModel); + var items = new Dictionary(); + var files = new[] { new FileInfo(@"D:\pkg\file1.dyn"), new FileInfo(@"C:\pkg\file2.DYN") }; + + foreach (var file in files) + { + var item = new PackageItemRootViewModel(file); + if (String.IsNullOrEmpty(item.DirectoryName)) continue; + if (!items.ContainsKey(item.DirectoryName)) + { + var root = new PackageItemRootViewModel(item.DirectoryName); + + root.ChildItems.Add(item); + items[item.DirectoryName] = root; + } + else + { + items[item.DirectoryName].ChildItems.Add(item); + } + } + + var result = vm.BindParentToChild(items); + + Assert.AreEqual(2, result.Count); + Assert.AreEqual(1, result.First().ChildItems.Count); + } + + [Test] + public void FindCommonPaths_SingleRoot() + { + var vm = new PublishPackageViewModel(ViewModel); + var paths = new string[] + { + "C:\\Users\\Alice\\Documents\\Report.docx", + "C:\\Users\\Alice\\Documents\\Resume.pdf", + "C:\\Users\\Alice\\Documents\\Presentation.pptx" + }; + + var commonPaths = vm.GetCommonPaths(paths); + + Assert.AreEqual(1, commonPaths.Count); + Assert.AreEqual("C:\\Users\\Alice\\Documents", commonPaths.First()); + + } + + [Test] + public void FindCommonPaths_MultipleRootsSingleFiles() + { + var vm = new PublishPackageViewModel(ViewModel); + var paths = new string[] + { + "C:\\Users\\Alice\\Documents\\Report.docx", + "D:\\Users\\Alice\\Documents\\Presentation.pptx" + }; + + var commonPaths = vm.GetCommonPaths(paths); + + Assert.AreEqual(2, commonPaths.Count); + Assert.AreEqual("C:\\Users\\Alice\\Documents", commonPaths[0]); + Assert.AreEqual("D:\\Users\\Alice\\Documents", commonPaths[1]); + + } + + + [Test] + public void FindCommonPaths_MultipleRootsMultipleFiles() + { + var vm = new PublishPackageViewModel(ViewModel); + var paths = new string[] + { + "C:\\Users\\Alice\\Documents\\Report.docx", + "C:\\Users\\Alice\\Documents\\Subfolder\\Resume.pdf", + "D:\\Users\\Alice\\Documents\\Presentation.pptx" + }; + + var commonPaths = vm.GetCommonPaths(paths); + + Assert.AreEqual(2, commonPaths.Count); + Assert.AreEqual("C:\\Users\\Alice\\Documents", commonPaths[0]); + Assert.AreEqual("D:\\Users\\Alice\\Documents", commonPaths[1]); + } + + + + [Test] + public void FindCommonPaths_MultipleRoots() + { + var vm = new PublishPackageViewModel(ViewModel); + var paths = new string[] + { + "C:\\Users\\Alice\\Documents\\Report.docx", + "D:\\Users\\Alice\\Documents\\Resume.pdf", + "E:\\Users\\Alice\\Documents\\Presentation.pptx" + }; + + var commonPaths = vm.GetCommonPaths(paths); + + Assert.AreEqual(3, commonPaths.Count); + Assert.AreEqual("C:\\Users\\Alice\\Documents", commonPaths[0]); + Assert.AreEqual("D:\\Users\\Alice\\Documents", commonPaths[1]); + Assert.AreEqual("E:\\Users\\Alice\\Documents", commonPaths[2]); + } + + + [Test] + public void FindCommonPaths_BaseRoot() + { + var vm = new PublishPackageViewModel(ViewModel); + var paths = new string[] + { + "C:\\Report.docx", + "C:\\Users\\Alice\\Documents\\Subfolder\\Resume.pdf", + }; + + var commonPaths = vm.GetCommonPaths(paths); + + Assert.AreEqual(1, commonPaths.Count); + Assert.AreEqual("C:\\", commonPaths[0]); + } + + + #endregion + } } diff --git a/test/Libraries/PackageManagerTests/PackageDirectoryBuilderTests.cs b/test/Libraries/PackageManagerTests/PackageDirectoryBuilderTests.cs index 56d6170aa5d..b5830036267 100644 --- a/test/Libraries/PackageManagerTests/PackageDirectoryBuilderTests.cs +++ b/test/Libraries/PackageManagerTests/PackageDirectoryBuilderTests.cs @@ -472,8 +472,8 @@ public void BuildRetainPackageDirectory_DoesNotIncludeUnselectedFiles() [Test] public void CopyFilesIntoPackageDirectory_DoesNotMoveFilesAlreadyWithinDirectory() { - var files = new[] { @"C:\foo/dyf\file1.dyf", @"C:\\foo\dyf\file2.dyf", @"C:\\foo\dyf\file3.dyf", - @"C:\foo/bin\file1.dll", @"C:\\foo\bin\file2.dll", @"C:\\foo\bin\file3.dll", + var files = new[] { @"C:\foo/dyf\file1.dyf", @"C:\\foo\dyf\file2.DYF", @"C:\\foo\dyf\file3.dyf", + @"C:\foo/bin\file1.dll", @"C:\\foo\bin\file2.DLL", @"C:\\foo\bin\file3.dll", @"C:\foo/extra\file1.pdf", @"C:\\foo\extra\file2.rvt", @"C:\\foo\extra\file3.poo", @"C:\\foo\doc\file1.md", @"C:\\foo\doc\file2.png" }; var fs = new RecordedFileSystem((fn) => files.Contains(fn), (dn) => true); @@ -499,5 +499,30 @@ public void CopyFilesIntoPackageDirectory_DoesNotMoveFilesAlreadyWithinDirectory #endregion + #region DeleteDyfFilesDuringBuild + [Test] + public void BuildPackageDirectory_DeletesOriginalDyfFiles() + { + // This tests asserts that the initial custom definition files will be deleted in the build process + var files = new[] { @"C:\pkg\file1.dyf", @"C:\pkg\file2.DYF" }; + var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT"); + + var fs = new RecordedFileSystem((fn) => files.Contains(fn)); + + var pr = new Mock(); + var db = new PackageDirectoryBuilder(fs, pr.Object); + + var pkgsDir = @"C:\dynamopackages"; + + db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty()); + + var dyfDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.CustomNodeDirectoryName); + + Assert.AreEqual(files.Length, fs.CopiedFiles.Count()); + Assert.AreEqual(files.Length, fs.DeletedFiles.Count()); + } + + #endregion + } } diff --git a/test/pkgs/PackageManager/1.0/TestAssembly.dll b/test/pkgs/PackageManager/1.0/TestAssembly.dll new file mode 100644 index 00000000000..9d111b0cbab Binary files /dev/null and b/test/pkgs/PackageManager/1.0/TestAssembly.dll differ diff --git a/test/pkgs/PackageManager/2.0/TestAssembly.dll b/test/pkgs/PackageManager/2.0/TestAssembly.dll new file mode 100644 index 00000000000..50a63c18cc5 Binary files /dev/null and b/test/pkgs/PackageManager/2.0/TestAssembly.dll differ