Skip to content

Commit

Permalink
removing items more tests added
Browse files Browse the repository at this point in the history
- added more tests around removing items
  • Loading branch information
dnenov committed Oct 28, 2023
1 parent 27277f2 commit c1bd03b
Show file tree
Hide file tree
Showing 7 changed files with 391 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ internal IEnumerable<string> GetAllFiles()

// make sure workspaces are saved
var unsavedWorkspaceNames =
workspaces.Where(ws => ws.HasUnsavedChanges || ws.FileName == null).Select(ws => ws.Name).ToList();
workspaces.Where(ws => ws.HasUnsavedChanges || ws.FileName == null).Select( ws => ws.Name).ToList();
if (unsavedWorkspaceNames.Any())
{
throw new Exception(Wpf.Properties.Resources.MessageUnsavedChanges0 +
Expand Down Expand Up @@ -1484,6 +1484,14 @@ private void SelectDirectoryAndAddFilesRecursively()

string directoryPath = packagePathEventArgs.Path;

if (!IsDirectoryWritable(directoryPath))
{
ErrorString = String.Format(Resources.FolderNotWritableError, directoryPath);
var ErrorMessage = ErrorString + "\n" + Resources.SolutionToFolderNotWritatbleError;
Dynamo.Wpf.Utilities.MessageBoxService.Show(ErrorMessage, Resources.FileNotPublishCaption, MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}

List<string> filePaths = Directory
.GetFiles
(
Expand Down Expand Up @@ -1608,13 +1616,14 @@ private void RemoveItemRecursively(PackageItemRootViewModel packageItemRootViewM
}
else
{
string fileName = packageItemRootViewModel.FileInfo == null ? packageItemRootViewModel.Name : packageItemRootViewModel.FileInfo.FullName;
RemoveSingleItem(fileName, fileType);
RemoveSingleItem(packageItemRootViewModel, fileType);
}
}

private void RemoveSingleItem(string fileName, DependencyType fileType)
private void RemoveSingleItem(PackageItemRootViewModel vm, DependencyType fileType)
{
var fileName = vm.DisplayName;

if (fileName.ToLower().EndsWith(".dll") || fileType.Equals(DependencyType.Assembly))
{
// It is possible that the .dll was external and added as an additional file
Expand All @@ -1629,13 +1638,17 @@ private void RemoveSingleItem(string fileName, DependencyType fileType)
.First(x => x.Name == Path.GetFileNameWithoutExtension(fileName)));
}
}
else if (fileType.Equals(DependencyType.CustomNode))
else if (fileType.Equals(DependencyType.CustomNode) || fileType.Equals(DependencyType.CustomNodePreview))
{
fileName = Path.GetFileNameWithoutExtension(fileName);
CustomNodeDefinitions.Remove(CustomNodeDefinitions
.First(x => x.DisplayName == fileName));

CustomDyfFilepaths.Remove(fileName + ".dyf");
}
else
{
fileName = vm.FilePath;
AdditionalFiles.Remove(AdditionalFiles
.First(x => x == fileName));
}
Expand Down
112 changes: 107 additions & 5 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using Dynamo;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
Expand All @@ -7,11 +12,6 @@
using Dynamo.Wpf.Utilities;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;

namespace DynamoCoreWpfTests
{
Expand Down Expand Up @@ -351,6 +351,108 @@ public void RemoveAllChildrenFilesUpdatesContentItem()
}


[Test]
public void CanRemoveCustomDefinitionDependencyTypes()
{
// Arrange
string nodePath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\AllFileTypesPackageDocs");
string dyfPath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\AllFileTypesPackageDocs\\dyf\\3DView by BoundingBox.dyf");
var allFiles = Directory.GetFiles(nodePath, "*", SearchOption.AllDirectories).ToList();
var vm = new PublishPackageViewModel(this.ViewModel);

ViewModel.OnRequestPackagePublishDialog(vm);

vm.AddAllFilesAfterSelection(allFiles);

// Act
// One root folder, one custom definition
Assert.AreEqual(2, vm.PackageContents.Count);

var customDefinition = vm.PackageContents.Where(x => x.DependencyType.Equals(DependencyType.CustomNode));
var rootFolder = vm.PackageContents.Where(x => x.DependencyType.Equals(DependencyType.Folder));

Assert.AreEqual(1, customDefinition.Count());
Assert.AreEqual(1, rootFolder.Count());

var childItems = PackageItemRootViewModel.GetFiles(rootFolder.First());
var customPreviewDefinition = childItems.Where(x => x.DependencyType.Equals(DependencyType.CustomNodePreview));

Assert.AreEqual(1, customPreviewDefinition.Count());

// Assert
// Remove using the custom definition
vm.RemoveItemCommand.Execute(customDefinition.First());

var updatedCustomDefinitionCount = vm.PackageContents.Count(x => x.DependencyType.Equals(DependencyType.CustomNode));
var updatedCustomPreviewDefinitionCount = PackageItemRootViewModel.GetFiles(rootFolder.First()).
Count(x => x.DependencyType.Equals(DependencyType.CustomNodePreview));

Assert.AreEqual(0, updatedCustomDefinitionCount, updatedCustomPreviewDefinitionCount);

// Add
vm.AddAllFilesAfterSelection(new List<string>() { dyfPath });

updatedCustomDefinitionCount = vm.PackageContents.Count(x => x.DependencyType.Equals(DependencyType.CustomNode));
updatedCustomPreviewDefinitionCount = PackageItemRootViewModel.GetFiles(rootFolder.First()).
Count(x => x.DependencyType.Equals(DependencyType.CustomNodePreview));

Assert.AreEqual(1, updatedCustomDefinitionCount, updatedCustomPreviewDefinitionCount);

// Remove using the preview
vm.RemoveItemCommand.Execute(customPreviewDefinition.First());

updatedCustomDefinitionCount = vm.PackageContents.Count(x => x.DependencyType.Equals(DependencyType.CustomNode));
updatedCustomPreviewDefinitionCount = PackageItemRootViewModel.GetFiles(rootFolder.First()).
Count(x => x.DependencyType.Equals(DependencyType.CustomNodePreview));

Assert.AreEqual(0, updatedCustomDefinitionCount, updatedCustomPreviewDefinitionCount);
}

[Test]
public void CanRemoveAllDependencyTypes()
{
// Arrange
string nodePath = Path.Combine(TestDirectory, "core", "docbrowser\\pkgs\\AllFileTypesPackageDocs");
var allFiles = Directory.GetFiles(nodePath, "*", SearchOption.AllDirectories).ToList();
var vm = new PublishPackageViewModel(this.ViewModel);

ViewModel.OnRequestPackagePublishDialog(vm);

vm.AddAllFilesAfterSelection(allFiles);

// Act
var rootFolder = vm.PackageContents.Where(x => x.DependencyType.Equals(DependencyType.Folder));

Assert.AreEqual(1, rootFolder.Count());

var childItems = PackageItemRootViewModel.GetFiles(rootFolder.First());

var files = childItems.Where(x => x.DependencyType.Equals(DependencyType.File));
var dllFiles = childItems.Where(x => x.DependencyType.Equals(DependencyType.Assembly));
var dyfPreviewFiles = childItems.Where(x => x.DependencyType.Equals(DependencyType.CustomNodePreview));
var folders = childItems.Where(x => x.DependencyType.Equals(DependencyType.Folder));

Assert.AreEqual(5, files.Count());
Assert.AreEqual(1, dllFiles.Count());
Assert.AreEqual(1, dyfPreviewFiles.Count());
Assert.AreEqual(5, folders.Count());

// Assert
Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(dllFiles.First()));
Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(dyfPreviewFiles.First()));
Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(files.First(x => x.DisplayName.EndsWith(".json"))));
Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(files.First(x => x.DisplayName.EndsWith(".xml"))));

rootFolder = vm.PackageContents.Where(x => x.DependencyType.Equals(DependencyType.Folder));

Assert.AreEqual(2, rootFolder.Count());
Assert.DoesNotThrow(() => vm.RemoveItemCommand.Execute(rootFolder.First()));
Assert.AreEqual(1, rootFolder.Count());
Assert.AreEqual(2, PackageItemRootViewModel.GetFiles(rootFolder.First()).Count());
}



[Test]
public void CancelCommandClearsAllData()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Hello Dynamo!
This content is from the markdown file created for the `CustomNodeExample` node!

In Markdown we can create headers simply by using `#`, let's try it:

# Here's a header 1 `#`
## This is a header 2 `##`
### This is a header 3 `###`
#### This i.. Okay think you got it!

We can also create cool stuff like tables! Here's an example:

| column1 | column2 |
| ------- | ------- |
| row_1_1 | row_1_2 |
| row_2_1 | row_2_2 |
| row_3_1 | row_3_2 |

Here's how you create the above table in markdown:
```
| column1 | column2 |
| ------- | ------- |
| row_1_1 | row_1_2 |
| row_2_1 | row_2_2 |
| row_3_1 | row_3_2 |
```

How about some syntax highlighting in you documentation?
``` csharp
public void HelloDynamo(string message)
{
System.Console.WriteLine(message);
}
```

<pre><code>``` csharp
public void HelloDynamo(string message)
{
System.Console.WriteLine(message);
}
```</code></pre>

![Dynamo Icon image](./icon.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c1bd03b

Please sign in to comment.