From 1d5b1dbac266f12d8f86f3d3ff2e3323ee5cfec2 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Tue, 31 May 2022 17:11:23 -0400 Subject: [PATCH] Fix Publish package remove item bug (#12941) * update remove item * cvb --- .../PackageManager/PublishPackageViewModel.cs | 25 +++++++++++---- .../PublishPackageViewModelTests.cs | 31 +++++++++++++++++++ test/pkgs/testFile.txt | 0 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 test/pkgs/testFile.txt diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs index ce79accf616..c60f7707aea 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs @@ -1335,15 +1335,28 @@ private void RemoveItem(object parameter) { if (!(parameter is PackageItemRootViewModel packageItemRootViewModel)) return; - if (packageItemRootViewModel.FileInfo == null || packageItemRootViewModel.FileInfo == null) + string fileName = packageItemRootViewModel.FileInfo == null ? packageItemRootViewModel.Name : packageItemRootViewModel.FileInfo.FullName; + string fileType = packageItemRootViewModel.DependencyType.ToString(); + + if (fileName.ToLower().EndsWith(".dll") || fileType.Equals(DependencyType.Assembly)) { - PackageContents.Remove(PackageContents - .First(x => x.Name == packageItemRootViewModel.Name)); - return; + Assemblies.Remove(Assemblies + .First(x => x.Name == Path.GetFileNameWithoutExtension(fileName))); + } + else if (fileType.Equals(DependencyType.CustomNode)) + { + CustomNodeDefinitions.Remove(CustomNodeDefinitions + .First(x => x.DisplayName == fileName)); } + else + { + AdditionalFiles.Remove(AdditionalFiles + .First(x => x == fileName)); + } + + RefreshPackageContents(); + return; - PackageContents.Remove(PackageContents - .First(x => x.FileInfo?.FullName == packageItemRootViewModel.FileInfo.FullName)); } private bool CanShowAddFileDialogAndAdd() diff --git a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs index 72398f00045..2c522ff112f 100644 --- a/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs +++ b/test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs @@ -9,6 +9,7 @@ using Dynamo.Tests; using NUnit.Framework; using Moq; +using Dynamo.PackageManager.UI; namespace DynamoCoreWpfTests { @@ -122,6 +123,36 @@ public void NewPackageVersionUpload_DoesNotThrowExceptionWhenDLLIsLoadedSeveralT Assert.AreEqual(PackageUploadHandle.State.Error, vm.UploadState); } + [Test] + public void NewPackageVersionUpload_CanAddAndRemoveFiles() + { + string packagesDirectory = Path.Combine(TestDirectory, "pkgs"); + string addFilePath = Path.Combine(packagesDirectory, "testFile.txt"); + PackageItemRootViewModel pkgItem = new PackageItemRootViewModel(new FileInfo(addFilePath)); + + var pathManager = new Mock(); + pathManager.SetupGet(x => x.PackagesDirectories).Returns(() => new List { packagesDirectory }); + + var loader = new PackageLoader(pathManager.Object); + loader.LoadAll(new LoadPackageParams + { + Preferences = ViewModel.Model.PreferenceSettings + }); + + PublishPackageViewModel vm = null; + var package = loader.LocalPackages.FirstOrDefault(x => x.Name == "Custom Rounding"); + Assert.DoesNotThrow(() => + { + vm = PublishPackageViewModel.FromLocalPackage(ViewModel, package); + }); + + vm.AddFile(addFilePath); + Assert.AreEqual(1, vm.AdditionalFiles.Count); + + vm.RemoveItemCommand.Execute(pkgItem); + Assert.AreEqual(0, vm.AdditionalFiles.Count); + } + [Test] [Category("Failure")] [Category("TechDebt")] //when a package is published - it does not load its customNodes. This may be intentional. diff --git a/test/pkgs/testFile.txt b/test/pkgs/testFile.txt new file mode 100644 index 00000000000..e69de29bb2d