Skip to content

Commit

Permalink
Fix Publish package remove item bug (#12941)
Browse files Browse the repository at this point in the history
* update remove item

* cvb
  • Loading branch information
zeusongit authored May 31, 2022
1 parent eeb490b commit 1d5b1db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
31 changes: 31 additions & 0 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Dynamo.Tests;
using NUnit.Framework;
using Moq;
using Dynamo.PackageManager.UI;

namespace DynamoCoreWpfTests
{
Expand Down Expand Up @@ -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<Dynamo.Interfaces.IPathManager>();
pathManager.SetupGet(x => x.PackagesDirectories).Returns(() => new List<string> { 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.
Expand Down
Empty file added test/pkgs/testFile.txt
Empty file.

0 comments on commit 1d5b1db

Please sign in to comment.