Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pm publishpackage cherrypick tests #14654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
670 changes: 659 additions & 11 deletions test/DynamoCoreWpfTests/PackageManager/PackageManagerUITests.cs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions test/DynamoCoreWpfTests/PublishPackageViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Dynamo;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Workspaces;
using Dynamo.PackageManager;
using Dynamo.PackageManager.UI;
using Dynamo.Tests;
using NUnit.Framework;
using Moq;
using Dynamo.PackageManager.UI;
using NUnit.Framework;

namespace DynamoCoreWpfTests
{
Expand Down
212 changes: 212 additions & 0 deletions test/Libraries/PackageManagerTests/PackageDirectoryBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ public void BuildPackageDirectory_DoesExpectedNumberOfOperations()
Assert.AreEqual(1, fs.NewFilesWritten.Count());
}

[Test]
public void BuildRetainPackageDirectory_DoesExpectedNumberOfOperations()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));
var db = new PackageDirectoryBuilder(fs, MockMaker.Empty<IPathRemapper>());

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

Assert.AreEqual(1, fs.DirectoriesCreated.Count());
Assert.AreEqual(2, fs.CopiedFiles.Count());
Assert.AreEqual(2, fs.DeletedFiles.Count());
Assert.AreEqual(1, fs.NewFilesWritten.Count());
}

[Test]
public void BuildPackageDirectory_BuildsExpectedDirectories()
{
Expand Down Expand Up @@ -65,6 +83,23 @@ public void BuildPackageDirectory_BuildsExpectedDirectories()
Assert.IsTrue(fs.DirectoriesCreated.Any(x => x.FullName == docDir));
}

[Test]
public void BuildRetainPackageDirectory_BuildsExpectedDirectories()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));
var db = new PackageDirectoryBuilder(fs, MockMaker.Empty<IPathRemapper>());

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var rootDir = Path.Combine(pkgsDir, pkg.Name);

Assert.IsTrue(fs.DirectoriesCreated.Any(x => x.FullName == rootDir));
}

[Test]
public void BuildPackageDirectory_FormsPackageHeader()
{
Expand All @@ -87,6 +122,27 @@ public void BuildPackageDirectory_FormsPackageHeader()
Assert.IsTrue(fs.NewFilesWritten.Any(x => x.Item1 == Path.Combine(rootDir, PackageDirectoryBuilder.PackageJsonName)));
}

[Test]
public void BuildRetainPackageDirectory_FormsPackageHeader()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));

var pr = new Mock<IPathRemapper>();
var db = new PackageDirectoryBuilder(fs, pr.Object);

var pkgsDir = @"C:\dynamopackages";

// where the magic happens...
db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var rootDir = Path.Combine(pkgsDir, pkg.Name);

Assert.AreEqual(1, fs.NewFilesWritten.Count());
Assert.IsTrue(fs.NewFilesWritten.Any(x => x.Item1 == Path.Combine(rootDir, PackageDirectoryBuilder.PackageJsonName)));
}

[Test]
public void BuildPackageDirectory_RemapsCustomNodePaths()
{
Expand Down Expand Up @@ -117,6 +173,35 @@ public void BuildPackageDirectory_RemapsCustomNodePaths()
Assert.IsTrue(remappedPaths.Any(x => x.Item1 == files[1] && x.Item2 == dyfDir));
}

[Test]
public void BuildRetainPackageDirectory_RemapsCustomNodePaths()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));

var pr = new Mock<IPathRemapper>();
var remappedPaths = new List<Tuple<string, string>>();

pr.Setup(x => x.SetPath(files[0].First(), It.IsAny<string>()))
.Callback((string f, string s) => remappedPaths.Add(new Tuple<string, string>(f, s)));

pr.Setup(x => x.SetPath(files[1].First(), It.IsAny<string>()))
.Callback((string f, string s) => remappedPaths.Add(new Tuple<string, string>(f, s)));

var db = new PackageDirectoryBuilder(fs, pr.Object);

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var dyfDir1 = Path.Combine(pkgsDir, pkg.Name, Path.GetFileName(Path.GetDirectoryName(files[0].First())), Path.GetFileName(files[0].First()));
var dyfDir2 = Path.Combine(pkgsDir, pkg.Name, Path.GetFileName(Path.GetDirectoryName(files[1].First())), Path.GetFileName(files[1].First()));

Assert.IsTrue(remappedPaths.Any(x => x.Item1 == files[0].First() && x.Item2 == dyfDir1));
Assert.IsTrue(remappedPaths.Any(x => x.Item1 == files[1].First() && x.Item2 == dyfDir2));
}

[Test]
public void BuildPackageDirectory_UpdatesTheArgumentPackageWithNewDirectories()
{
Expand Down Expand Up @@ -147,6 +232,28 @@ public void BuildPackageDirectory_UpdatesTheArgumentPackageWithNewDirectories()
Assert.AreEqual(docDir, pkg.NodeDocumentaionDirectory);
}

[Test]
public void BuildRetainPackageDirectory_UpdatesTheArgumentPackageWithNewDirectories()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));


var pr = new Mock<IPathRemapper>();
var db = new PackageDirectoryBuilder(fs, pr.Object);

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var rootDir = Path.Combine(pkgsDir, pkg.Name);

// The package itself is updated

Assert.AreEqual(rootDir, pkg.RootDirectory);
}

[Test]
public void BuildPackageDirectory_CopiesTheOriginalFiles()
{
Expand All @@ -172,6 +279,31 @@ public void BuildPackageDirectory_CopiesTheOriginalFiles()
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(dyfDir, "file2.dyf"))));
}

[Test]
public void BuildPackageRetainDirectory_CopiesTheOriginalFiles()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));

var pr = new Mock<IPathRemapper>();
var db = new PackageDirectoryBuilder(fs, pr.Object);

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var dyfDir1 = Path.Combine(pkgsDir, pkg.Name, Path.GetFileName(Path.GetDirectoryName(files[0].First())));
var dyfDir2 = Path.Combine(pkgsDir, pkg.Name, Path.GetFileName(Path.GetDirectoryName(files[1].First())));

Assert.AreEqual(2, fs.CopiedFiles.Count());
Assert.AreEqual(2, fs.DeletedFiles.Count());
Assert.AreEqual(0, fs.DeletedDirectories.Count());

Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(dyfDir1, "file1.dyf"))));
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(dyfDir2, "file2.dyf"))));
}

[Test]
public void BuildPackageDirectory_CopiesMarkDownFiles()
{
Expand Down Expand Up @@ -199,6 +331,32 @@ public void BuildPackageDirectory_CopiesMarkDownFiles()
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file3.jpg"))));
}

[Test]
public void BuildRetainPackageDirectory_CopiesMarkDownFiles()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyn" }, new[] { @"C:\folder2\file2.dyn" } };
var markdownFiles = new[] { @"C:\file1.md", @"C:\file2.md", @"C:\image\file3.jpg" };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));

var pr = new Mock<IPathRemapper>();
var db = new PackageDirectoryBuilder(fs, pr.Object);

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, markdownFiles);

var mdDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.DocumentationDirectoryName);

Assert.AreEqual(5, fs.CopiedFiles.Count());
Assert.AreEqual(0, fs.DeletedFiles.Count());
Assert.AreEqual(0, fs.DeletedDirectories.Count());

Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file1.md"))));
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file2.md"))));
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file3.jpg"))));
}

[Test]
public void BuildPackageDirectory_DeletesTheOriginalFiles()
{
Expand All @@ -224,6 +382,30 @@ public void BuildPackageDirectory_DeletesTheOriginalFiles()
Assert.Contains(files[1], fs.DeletedFiles.ToList());
}

[Test]
public void BuildRetainPackageDirectory_DeletesTheOriginalFiles()
{
var files = new List<IEnumerable<string>>() { new[] { @"C:\folder1\file1.dyf" }, new[] { @"C:\folder2\file2.dyf" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));

var pr = new Mock<IPathRemapper>();

var db = new PackageDirectoryBuilder(fs, pr.Object);

var pkgsDir = @"C:\dynamopackages";

db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

// The original files are moved

Assert.AreEqual(2, fs.DeletedFiles.Count());
Assert.AreEqual(0, fs.DeletedDirectories.Count());

Assert.Contains(files[0].First(), fs.DeletedFiles.ToList());
Assert.Contains(files[1].First(), fs.DeletedFiles.ToList());
}

[Test]
public void BuildPackageDirectory_DoesNotIncludeUnselectedFiles()
{
Expand Down Expand Up @@ -253,6 +435,36 @@ public void BuildPackageDirectory_DoesNotIncludeUnselectedFiles()
Assert.AreEqual(1, fs.NewFilesWritten.Count());
}

[Test]
public void BuildRetainPackageDirectory_DoesNotIncludeUnselectedFiles()
{
// For http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-7676

var files = new List<IEnumerable<string>>() { new[] { "C:/pkg/bin/file1.dll", "C:/pkg/dyf/file2.dyf",
"C:/pkg/extra/file3.txt", "C:/pkg/extra/subfolder/file4.dwg" } };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
var fs = new RecordedFileSystem((fn) => files.SelectMany(files => files).ToList().Any((x) => ComparePaths(x, fn)));

// Specifying directory contents in the disk
fs.SetFiles(new List<string>() {
"C:/pkg/bin/file1.dll", "C:/pkg/dyf/file2.dyf", "C:/pkg/dyf/backup/file2.dyf.0.backup",
"C:/pkg/extra/file3.txt", "C:/pkg/extra/Backup/file3.txt.backup", "C:/pkg/extra/subfolder/file4.dwg" });
fs.SetDirectories(new List<string>() {
"C:/pkg/bin", "C:/pkg/dyf", "C:/pkg/dyf/backup", "C:/pkg/extra",
"C:/pkg/extra/Backup", "C:/pkg/extra/subfolder" });

var db = new PackageDirectoryBuilder(fs, MockMaker.Empty<IPathRemapper>());
var pkgsDir = @"C:\dynamopackages";
db.BuildRetainDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());


Assert.AreEqual(1, fs.DirectoriesCreated.Count());
Assert.AreEqual(4, fs.CopiedFiles.Count());
Assert.AreEqual(3, fs.DeletedFiles.Count());
Assert.AreEqual(2, fs.DeletedDirectories.Count());
Assert.AreEqual(1, fs.NewFilesWritten.Count());
}

#endregion

#region CopyFilesIntoPackageDirectory
Expand Down
88 changes: 88 additions & 0 deletions test/Libraries/PackageManagerTests/PackageManagerClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,94 @@ public void Publish_SetsErrorStatusWhenResponseIsNull()

#endregion

#region PublishRetainingFolderStructure

[Test]
public void PublishRetain_SetsHandleToDoneWhenNewPackagePublishSucceeds()
{
var gc = new Mock<IGregClient>();
gc.Setup(x => x.ExecuteAndDeserialize(It.IsAny<PackageUpload>()))
.Returns(new ResponseBody()
{
success = true
});

var pc = new PackageManagerClient(gc.Object, MockMaker.Empty<IPackageUploadBuilder>(), "");

var pkg = new Package("", "Package", "0.1.0", "MIT");

var handle = new PackageUploadHandle(PackageUploadBuilder.NewRequestBody(pkg));
var listOfEmptyEnumerables = Enumerable.Range(1, 5)
.Select(_ => Enumerable.Empty<string>());

pc.PublishRetainFolderStructure(pkg, listOfEmptyEnumerables, Enumerable.Empty<string>(), false, handle);

Assert.AreEqual(PackageUploadHandle.State.Uploaded, handle.UploadState);
}

[Test]
public void PublishRetain_SetsHandleToDoneWhenNewPackageVersionPublishSucceeds()
{
var gc = new Mock<IGregClient>();
gc.Setup(x => x.ExecuteAndDeserialize(It.IsAny<PackageVersionUpload>()))
.Returns(new ResponseBody()
{
success = true
});

var pc = new PackageManagerClient(gc.Object, MockMaker.Empty<IPackageUploadBuilder>(), "");

var pkg = new Package("", "Package", "0.1.0", "MIT");

var handle = new PackageUploadHandle(PackageUploadBuilder.NewRequestBody(pkg));
var listOfEmptyEnumerables = Enumerable.Range(1, 5)
.Select(_ => Enumerable.Empty<string>());
pc.PublishRetainFolderStructure(pkg, listOfEmptyEnumerables, Enumerable.Empty<string>(), false, handle);

Assert.AreEqual(PackageUploadHandle.State.Uploaded, handle.UploadState);
}

[Test]
public void PublishRetain_SetsErrorStatusWhenRequestThrowsAnException()
{
var gc = new Mock<IGregClient>();
gc.Setup(x => x.ExecuteAndDeserialize(It.IsAny<PackageUpload>())).Throws<Exception>();

var pc = new PackageManagerClient(gc.Object, MockMaker.Empty<IPackageUploadBuilder>(), "");

var pkg = new Package("", "Package", "0.1.0", "MIT");

var handle = new PackageUploadHandle(PackageUploadBuilder.NewRequestBody(pkg));
var listOfEmptyEnumerables = Enumerable.Range(1, 5)
.Select(_ => Enumerable.Empty<string>());
pc.PublishRetainFolderStructure(pkg, listOfEmptyEnumerables, Enumerable.Empty<string>(), false, handle);

Assert.AreEqual(PackageUploadHandle.State.Error, handle.UploadState);
}

[Test]
public void PublishRetain_SetsErrorStatusWhenResponseIsNull()
{
var gc = new Mock<IGregClient>();
var rb = new ResponseBody();
rb.success = false;

gc.Setup(x => x.ExecuteAndDeserialize(It.IsAny<PackageUpload>())).Returns(rb);

var pc = new PackageManagerClient(gc.Object, MockMaker.Empty<IPackageUploadBuilder>(), "");

var pkg = new Package("", "Package", "0.1.0", "MIT");

var handle = new PackageUploadHandle(PackageUploadBuilder.NewRequestBody(pkg));
var listOfEmptyEnumerables = Enumerable.Range(1, 5)
.Select(_ => Enumerable.Empty<string>());
pc.PublishRetainFolderStructure(pkg, listOfEmptyEnumerables, Enumerable.Empty<string>(), true, handle);

Assert.AreEqual(PackageUploadHandle.State.Error, handle.UploadState);
}

#endregion

#region Deprecate

[Test]
Expand Down
Loading
Loading