示例#1
0
        public void FailureOnGetPackageVersionHeaderByPackageName()
        {
            var mockGreg = new Mock <IGregClient>();

            mockGreg.Setup(m => m.ExecuteAndDeserializeWithContent <PackageVersion>(It.IsAny <Request>()))
            .Returns(new ResponseWithContentBody <PackageVersion>()
            {
                message = "The package does not exist",
                success = false
            });

            var client = new PackageManagerClient(mockGreg.Object, MockMaker.Empty <IPackageUploadBuilder>(), string.Empty);

            client.GetPackageVersionHeader(string.Empty, string.Empty);
        }
        public void ListAll_ReturnsEmptyListWhenQueryThrowsException()
        {
            // Returns mpl for any arguments
            var c = new Mock <IGregClient>();

            c.Setup(x =>
                    x.ExecuteAndDeserializeWithContent <List <PackageHeader> >(It.IsAny <HeaderCollectionDownload>()))
            .Throws(new Exception("Fail!"));

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

            var pl = m.ListAll();

            Assert.AreEqual(0, pl.Count());
        }
        public void Undeprecate_ReturnsSuccessObjectWhenRequestSucceeds()
        {
            var gc = new Mock <IGregClient>();

            gc.Setup(x => x.ExecuteAndDeserialize(It.IsAny <Undeprecate>())).Returns(new ResponseBody()
            {
                success = true
            });

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

            var res = pc.Undeprecate("id");

            Assert.IsTrue(res.Success);
        }
        public void Deprecate_ReturnsFailureObjectWhenRequestFails()
        {
            var gc = new Mock <IGregClient>();

            gc.Setup(x => x.ExecuteAndDeserialize(It.IsAny <Deprecate>())).Returns(new ResponseBody()
            {
                success = false // set to false
            });

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

            var res = pc.Deprecate("id");

            Assert.IsFalse(res.Success);
        }
        public void DownloadPackageHeader_ReturnsFailureObjectWhenDownloadThrowsAnException()
        {
            // Returns mock for any arguments
            var c = new Mock <IGregClient>();

            c.Setup(x =>
                    x.ExecuteAndDeserializeWithContent <PackageHeader>(It.IsAny <HeaderDownload>()))
            .Throws <Exception>();

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

            PackageHeader header;
            var           res = pc.DownloadPackageHeader("1", out header);

            Assert.IsFalse(res.Success);
        }
        public void Publish_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));

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

            Assert.AreEqual(PackageUploadHandle.State.Error, handle.UploadState);
        }
        public void Login_CausesLoginMethodToBeInvokedOnAuthProvider()
        {
            var called = false;

            var ap = new Mock <IAuthProvider>();

            ap.Setup(x => x.Login()).Callback(() => called = true);

            var gc = new Mock <IGregClient>();

            gc.Setup(x => x.AuthProvider).Returns(ap.Object);

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

            pc.Login();

            Assert.IsTrue(called);
        }
示例#8
0
        public void BuildPackageDirectory_DoesExpectedNumberOfOperations()
        {
            var files = new[] { @"C:\file1.dyf", @"C:\file2.dyf" };
            var pkg   = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");

            var fs = new RecordedFileSystem((fn) => files.Any((x) => ComparePaths(x, fn)));

            var db = new PackageDirectoryBuilder(fs, MockMaker.Empty <IPathRemapper>());

            var pkgsDir = @"C:\dynamopackages";

            db.BuildDirectory(pkg, pkgsDir, files);

            Assert.AreEqual(5, fs.DirectoriesCreated.Count());
            Assert.AreEqual(2, fs.CopiedFiles.Count());
            Assert.AreEqual(2, fs.DeletedFiles.Count());
            Assert.AreEqual(1, fs.NewFilesWritten.Count());
        }
        public void Publish_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));

            pc.Publish(pkg, Enumerable.Empty <string>(), true, handle);

            Assert.AreEqual(PackageUploadHandle.State.Error, handle.UploadState);
        }
        public void Publish_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));

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

            Assert.AreEqual(PackageUploadHandle.State.Uploaded, handle.UploadState);
        }
        public void SetTermsOfUseAcceptanceStatus_ReturnsTrueWhenRequestSucceeds()
        {
            var resp = new ResponseWithContentBody <TermsOfUseStatus>()
            {
                content = new TermsOfUseStatus()
                {
                    accepted = true
                }
            };

            var gc = new Mock <IGregClient>();

            gc.Setup(x => x.ExecuteAndDeserializeWithContent <TermsOfUseStatus>(It.IsAny <TermsOfUse>())).Returns(resp);

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

            var res = pc.SetTermsOfUseAcceptanceStatus();

            Assert.IsTrue(res);
        }
示例#12
0
        public void SuccessfullyGetPackageVersionHeaderByPackageName()
        {
            var version  = "1.0.0";
            var mockGreg = new Mock <IGregClient>();

            mockGreg.Setup(m => m.ExecuteAndDeserializeWithContent <PackageVersion>(It.IsAny <Request>()))
            .Returns(new ResponseWithContentBody <PackageVersion>()
            {
                content = new PackageVersion()
                {
                    version = version
                },
                success = true
            });

            var client = new PackageManagerClient(mockGreg.Object, MockMaker.Empty <IPackageUploadBuilder>(), string.Empty);
            var result = client.GetPackageVersionHeader(string.Empty, version);

            Assert.AreEqual(result.version, version);
        }
        public void BuildPackageDirectory_BuildsExpectedDirectories()
        {
            var files = new[] { @"C:\file1.dyf", @"C:\file2.dyf" };
            var pkg   = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");

            var fs = new RecordedFileSystem((fn) => files.Contains(fn));

            var db = new PackageDirectoryBuilder(fs, MockMaker.Empty <IPathRemapper>());

            var pkgsDir = @"C:\dynamopackages";

            db.BuildDirectory(pkg, pkgsDir, files);

            var rootDir  = Path.Combine(pkgsDir, pkg.Name);
            var binDir   = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.BinaryDirectoryName);
            var dyfDir   = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.CustomNodeDirectoryName);
            var extraDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.ExtraDirectoryName);

            Assert.IsTrue(fs.DirectoriesCreated.Any(x => x.FullName == rootDir));
            Assert.IsTrue(fs.DirectoriesCreated.Any(x => x.FullName == dyfDir));
            Assert.IsTrue(fs.DirectoriesCreated.Any(x => x.FullName == binDir));
            Assert.IsTrue(fs.DirectoriesCreated.Any(x => x.FullName == extraDir));
        }
示例#14
0
        public void PackageSearchDialogSearchIntersectAgainstFilters()
        {
            //Arrange
            int    numberOfPackages         = 9;
            string packageId                = "c5ecd20a-d41c-4e0c-8e11-8ddfb953d77f";
            string packageVersionNumber     = "1.0.0.0";
            string packageCreatedDateString = "2016 - 12 - 02T13:13:20.135000 + 00:00";
            string advSteelFilterName       = "Advance Steel";
            string formItFilterName         = "FormIt";

            //Formit Packages
            List <string> formItPackagesName = new List <string> {
                "DynamoIronPython2.7", "dynamo", "Celery for Dynamo 2.5"
            };
            //Advance Steel Packages
            List <string> advanceSteelPackagesName = new List <string> {
                "DynamoIronPython2.7", "dynamo", "mise en barre", "Test-PackageDependencyFilter"
            };
            //Advance Steel Packages & Formit
            List <string> intersectionPackagesName = new List <string> {
                "DynamoTestPackage1", "DynamoTestPackage2"
            };

            var mockGreg   = new Mock <IGregClient>();
            var clientmock = new Mock <PackageManagerClient>(mockGreg.Object, MockMaker.Empty <IPackageUploadBuilder>(), string.Empty);
            var pmCVM      = new Mock <PackageManagerClientViewModel>(ViewModel, clientmock.Object);

            var packageManagerSearchViewModel = new PackageManagerSearchViewModel(pmCVM.Object);

            packageManagerSearchViewModel.RegisterTransientHandlers();

            //Adds the filters for FormIt and Advance Steel
            packageManagerSearchViewModel.HostFilter = new List <FilterEntry>
            {
                new FilterEntry(advSteelFilterName, packageManagerSearchViewModel)
                {
                    OnChecked = true
                },
                new FilterEntry(formItFilterName, packageManagerSearchViewModel)
                {
                    OnChecked = true
                },
            };

            //Adding FormIt packages
            foreach (var package in formItPackagesName)
            {
                var tmpPackageVersion = new PackageVersion {
                    version = packageVersionNumber, host_dependencies = new List <string> {
                        formItFilterName
                    }, created = packageCreatedDateString
                };
                var tmpPackage = new PackageManagerSearchElementViewModel(new PackageManagerSearchElement(new PackageHeader()
                {
                    _id      = packageId,
                    name     = package,
                    versions = new List <PackageVersion> {
                        tmpPackageVersion
                    },
                    host_dependencies = new List <string> {
                        formItFilterName
                    },
                }), false);
                packageManagerSearchViewModel.AddToSearchResults(tmpPackage);
            }

            //Adding Advance Steel packages
            foreach (var package in advanceSteelPackagesName)
            {
                var tmpPackageVersion = new PackageVersion {
                    version = packageVersionNumber, host_dependencies = new List <string> {
                        advSteelFilterName
                    }, created = packageCreatedDateString
                };
                var tmpPackage = new PackageManagerSearchElementViewModel(new PackageManagerSearchElement(new PackageHeader()
                {
                    _id      = packageId,
                    name     = package,
                    versions = new List <PackageVersion> {
                        tmpPackageVersion
                    },
                    host_dependencies = new List <string> {
                        advSteelFilterName
                    },
                }), false);
                packageManagerSearchViewModel.AddToSearchResults(tmpPackage);
            }

            //Adding packages that belong to FormIt and Advance Steel (intersection packages)
            foreach (var package in intersectionPackagesName)
            {
                var tmpPackageVersion = new PackageVersion {
                    version = packageVersionNumber, host_dependencies = new List <string> {
                        advSteelFilterName, formItFilterName
                    }, created = packageCreatedDateString
                };
                var tmpPackage = new PackageManagerSearchElementViewModel(new PackageManagerSearchElement(new PackageHeader()
                {
                    _id      = packageId,
                    name     = package,
                    versions = new List <PackageVersion> {
                        tmpPackageVersion
                    },
                    host_dependencies = new List <string> {
                        advSteelFilterName, formItFilterName
                    },
                }), false);
                packageManagerSearchViewModel.AddToSearchResults(tmpPackage);
            }

            //We need to add the PackageManagerSearchElementViewModel because otherwise the search will crash
            packageManagerSearchViewModel.LastSync = new List <PackageManagerSearchElement>();
            foreach (var result in packageManagerSearchViewModel.SearchResults)
            {
                packageManagerSearchViewModel.LastSync.Add(result.Model);
            }

            //Validate the total added packages match
            Assert.That(packageManagerSearchViewModel.SearchResults.Count == numberOfPackages);

            //Act
            //Check the Advance Steel filter
            packageManagerSearchViewModel.HostFilter[0].FilterCommand.Execute(advSteelFilterName);
            //Check the FormIt filter
            packageManagerSearchViewModel.HostFilter[1].FilterCommand.Execute(formItFilterName);

            //Assert
            //Validates that we have results and that the result match the expected 2 packages (intersection)
            Assert.IsNotNull(packageManagerSearchViewModel.SearchResults, "There was no results");
            Assert.That(packageManagerSearchViewModel.SearchResults.Count > 0, "There was no results");
            Assert.That(packageManagerSearchViewModel.SearchResults.Count == intersectionPackagesName.Count, "The search results are not getting the packages intersected");
        }
        public void NewPackageUpload_ThrowsForNullArguments()
        {
            var files   = new[] { @"C:\file1.dyf", @"C:\file2.dyf" };
            var pkg     = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");
            var pkgsDir = @"C:\dynamopackages";
            var handle  = new PackageUploadHandle(PackageUploadBuilder.NewRequestBody(pkg));

            var m = new PackageUploadBuilder(MockMaker.Empty <IPackageDirectoryBuilder>(), MockMaker.Empty <IFileCompressor>());

            Assert.Throws <ArgumentNullException>(() => m.NewPackageUpload(null, pkgsDir, files, handle));
            Assert.Throws <ArgumentNullException>(() => m.NewPackageUpload(pkg, null, files, handle));
            Assert.Throws <ArgumentNullException>(() => m.NewPackageUpload(pkg, pkgsDir, null, handle));
            Assert.Throws <ArgumentNullException>(() => m.NewPackageUpload(pkg, pkgsDir, files, null));
        }
示例#16
0
        public void PackageManagerConflictsWithStdLib()
        {
            var pkgLoader = GetPackageLoader();

            pkgLoader.StandardLibraryDirectory = StandardLibraryTestDirectory;

            // Load a std lib package
            var stdPackageLocation = Path.Combine(StandardLibraryTestDirectory, "SignedPackage2");

            pkgLoader.ScanPackageDirectory(stdPackageLocation);

            var stdLibPkg = pkgLoader.LocalPackages.Where(x => x.Name == "SignedPackage").FirstOrDefault();

            Assert.IsNotNull(stdLibPkg);

            // Simulate the user downloading the same package from PM
            var mockGreg = new Mock <IGregClient>();

            mockGreg.Setup(x => x.Execute(It.IsAny <PackageDownload>())).Throws(new Exception("Failed to get your package!"));

            var client = new Dynamo.PackageManager.PackageManagerClient(mockGreg.Object, MockMaker.Empty <IPackageUploadBuilder>(), string.Empty);
            var pmVm   = new PackageManagerClientViewModel(ViewModel, client);

            var dlgMock = new Mock <MessageBoxService.IMessageBox>();

            dlgMock.Setup(m => m.Show(It.IsAny <string>(), It.IsAny <string>(), It.Is <MessageBoxButton>(x => x == MessageBoxButton.OKCancel || x == MessageBoxButton.OK), It.IsAny <MessageBoxImage>()))
            .Returns(MessageBoxResult.OK);
            MessageBoxService.OverrideMessageBoxDuringTests(dlgMock.Object);

            //
            // 1. User downloads the exact version of a std lib package
            //
            {
                var id   = "test-123";
                var deps = new List <Dependency>()
                {
                    new Dependency()
                    {
                        _id = id, name = stdLibPkg.Name
                    }
                };
                var depVers = new List <string>()
                {
                    stdLibPkg.VersionName
                };

                mockGreg.Setup(m => m.ExecuteAndDeserializeWithContent <PackageVersion>(It.IsAny <Request>()))
                .Returns(new ResponseWithContentBody <PackageVersion>()
                {
                    content = new PackageVersion()
                    {
                        version                  = stdLibPkg.VersionName,
                        engine_version           = stdLibPkg.EngineVersion,
                        name                     = stdLibPkg.Name,
                        id                       = id,
                        full_dependency_ids      = deps,
                        full_dependency_versions = depVers
                    },
                    success = true
                });

                var pkgInfo = new Dynamo.Graph.Workspaces.PackageInfo(stdLibPkg.Name, VersionUtilities.PartialParse(stdLibPkg.VersionName));
                pmVm.DownloadAndInstallPackage(pkgInfo);

                // Users should get 2 warnings :
                // 1. To confirm that they want to download the specified package.
                // 2. That a package with the same name and version already exists as part of the Standard Library.
                dlgMock.Verify(x => x.Show(It.IsAny <string>(), It.IsAny <string>(),
                                           It.IsAny <MessageBoxButton>(), It.IsAny <MessageBoxImage>()), Times.Exactly(2));
                dlgMock.ResetCalls();
            }

            //
            // 2. User downloads a different version of a std lib package
            //
            {
                var id   = "test-234";
                var deps = new List <Dependency>()
                {
                    new Dependency()
                    {
                        _id = id, name = stdLibPkg.Name
                    }
                };
                var stdLibPkgVers = VersionUtilities.PartialParse(stdLibPkg.VersionName);
                var newPkgVers    = new Version(stdLibPkgVers.Major + 1, stdLibPkgVers.Minor, stdLibPkgVers.Build);

                var depVers = new List <string>()
                {
                    newPkgVers.ToString()
                };

                mockGreg.Setup(m => m.ExecuteAndDeserializeWithContent <PackageVersion>(It.IsAny <Request>()))
                .Returns(new ResponseWithContentBody <PackageVersion>()
                {
                    content = new PackageVersion()
                    {
                        version                  = newPkgVers.ToString(),
                        engine_version           = stdLibPkg.EngineVersion,
                        name                     = stdLibPkg.Name,
                        id                       = id,
                        full_dependency_ids      = deps,
                        full_dependency_versions = depVers
                    },
                    success = true
                });

                var pkgInfo = new Dynamo.Graph.Workspaces.PackageInfo(stdLibPkg.Name, newPkgVers);
                pmVm.DownloadAndInstallPackage(pkgInfo);

                // Users should get 2 warnings :
                // 1. To confirm that they want to download the specified package.
                // 2. That a package with a different version already exists as part of the Standard Library.
                dlgMock.Verify(x => x.Show(It.IsAny <string>(), It.IsAny <string>(),
                                           It.IsAny <MessageBoxButton>(), It.IsAny <MessageBoxImage>()), Times.Exactly(2));
                dlgMock.ResetCalls();
            }

            //
            // 3. User downloads a package that is not part of a std lib package
            //
            {
                var id   = "test-345";
                var deps = new List <Dependency>()
                {
                    new Dependency()
                    {
                        _id = id, name = "non-std-libg"
                    }
                };
                var pkgVersion = new Version(1, 0, 0);
                var depVers    = new List <string>()
                {
                    pkgVersion.ToString()
                };

                mockGreg.Setup(m => m.ExecuteAndDeserializeWithContent <PackageVersion>(It.IsAny <Request>()))
                .Returns(new ResponseWithContentBody <PackageVersion>()
                {
                    content = new PackageVersion()
                    {
                        version                  = pkgVersion.ToString(),
                        engine_version           = stdLibPkg.EngineVersion,
                        name                     = "non-std-libg",
                        id                       = id,
                        full_dependency_ids      = deps,
                        full_dependency_versions = depVers
                    },
                    success = true
                });

                var pkgInfo = new Dynamo.Graph.Workspaces.PackageInfo("Non-stdlib-package", new Version(1, 0, 0));
                pmVm.DownloadAndInstallPackage(pkgInfo);

                // Users should get 1 warning :
                // 1. To confirm that they want to download the specified package.
                dlgMock.Verify(x => x.Show(It.IsAny <string>(), It.IsAny <string>(),
                                           It.IsAny <MessageBoxButton>(), It.IsAny <MessageBoxImage>()), Times.Exactly(1));
                dlgMock.ResetCalls();
            }
        }
示例#17
0
        public void TestPackageManagerSearchElementCanInstall()
        {
            var name1   = "non-duplicate";
            var name2   = "duplicate";
            var version = "1.0.0";

            var mockGreg   = new Mock <IGregClient>();
            var clientmock = new Mock <PackageManagerClient>(mockGreg.Object, MockMaker.Empty <IPackageUploadBuilder>(), string.Empty);
            var pmCVM      = new Mock <PackageManagerClientViewModel>(ViewModel, clientmock.Object);

            var ext    = Model.GetPackageManagerExtension();
            var loader = ext.PackageLoader;

            loader.Add(new Package("", name2, version, ""));

            var packageManagerSearchViewModel = new PackageManagerSearchViewModel(pmCVM.Object);

            packageManagerSearchViewModel.RegisterTransientHandlers();

            var newSE1 = new PackageManagerSearchElementViewModel(new PackageManagerSearchElement(new PackageHeader()
            {
                name = name1
            }), false);

            var newSE2 = new PackageManagerSearchElementViewModel(new PackageManagerSearchElement(new PackageHeader()
            {
                name = name2
            }), false);

            packageManagerSearchViewModel.AddToSearchResults(newSE1);
            packageManagerSearchViewModel.AddToSearchResults(newSE2);

            // Default CanInstall should be true
            Assert.AreEqual(true, newSE1.CanInstall);
            Assert.AreEqual(true, newSE2.CanInstall);

            var dHandle1 = new PackageDownloadHandle()
            {
                Id          = name1,
                VersionName = version,
                Name        = name1
            };

            var dHandle2 = new PackageDownloadHandle()
            {
                Id          = name2,
                VersionName = version,
                Name        = name2
            };

            pmCVM.Object.Downloads.Add(dHandle1);
            pmCVM.Object.Downloads.Add(dHandle2);

            Assert.AreEqual(true, newSE1.CanInstall);
            Assert.AreEqual(true, newSE2.CanInstall);

            dHandle1.DownloadState = PackageDownloadHandle.State.Downloading;
            Assert.AreEqual(false, newSE1.CanInstall);

            dHandle1.DownloadState = PackageDownloadHandle.State.Downloaded;
            Assert.AreEqual(false, newSE1.CanInstall);

            dHandle1.DownloadState = PackageDownloadHandle.State.Error;
            dHandle2.DownloadState = PackageDownloadHandle.State.Downloading;

            Assert.AreEqual(true, newSE1.CanInstall);
            Assert.AreEqual(false, newSE2.CanInstall);

            dHandle1.DownloadState = PackageDownloadHandle.State.Installing;
            dHandle2.DownloadState = PackageDownloadHandle.State.Downloaded;
            Assert.AreEqual(false, newSE1.CanInstall);
            Assert.AreEqual(false, newSE2.CanInstall);

            // Simulate that the package corresponding to name1 was added successfully
            var package1 = new Package("", name1, version, "")
            {
            };

            package1.SetAsLoaded();
            loader.Add(package1);

            dHandle1.DownloadState = PackageDownloadHandle.State.Installed;
            dHandle2.DownloadState = PackageDownloadHandle.State.Installed;

            Assert.AreEqual(false, newSE1.CanInstall);
            Assert.AreEqual(false, newSE2.CanInstall);

            packageManagerSearchViewModel.ClearSearchResults();
        }