public void InstallPackageFailureTest() { string wd = "c:\\root\\project1"; Uri registry = null; NpmFactory factory = new MockNpmFactory(); NpmPackageManager target = new NpmPackageManager(factory, wd, registry); NpmPackage package = new NpmPackage("bogusmod", null); NpmException expected = MockTestData.ErrorInstallExpected(); try { target.InstallPackage(package); Assert.Fail("Expected exception"); } catch (NpmException ex) { Assert.IsNotNull(ex); Assert.AreEqual(expected.Message, ex.Message); Assert.AreEqual(expected.NpmCode, ex.NpmCode); Assert.AreEqual(expected.NpmErrno, ex.NpmErrno); Assert.AreEqual(expected.NpmFile, ex.NpmFile); Assert.AreEqual(expected.NpmPath, ex.NpmPath); Assert.AreEqual(expected.NpmType, ex.NpmType); Assert.AreEqual(expected.NpmSyscall, ex.NpmSyscall); Assert.AreEqual(expected.NpmSystem, ex.NpmSystem); Assert.AreEqual(expected.NpmCommand, ex.NpmCommand); Assert.AreEqual(expected.NpmNodeVersion, ex.NpmNodeVersion); Assert.AreEqual(expected.NpmNpmVersion, ex.NpmNpmVersion); Assert.AreEqual(expected.NpmMessage, ex.NpmMessage); Assert.AreEqual(expected.NpmArguments, ex.NpmArguments); Assert.AreEqual(expected.NpmCwd, ex.NpmCwd); Assert.AreEqual(expected.NpmVerbose, ex.NpmVerbose); } }
/// <summary> /// Exercise the NpmPackageManager class /// </summary> /// <param name="wd">working directory path</param> /// <param name="installPath">node installation path</param> /// <param name="module">module name to use</param> /// <returns>true or false</returns> public static bool RunSample(string wd, string installPath, string module) { try { NpmPackageManager npm = new NpmPackageManager(wd); if (npm == null) { Console.WriteLine("Failed to create NpmPackageManager"); return false; } npm.NpmClient.InstallPath = installPath; INpmSearchResultPackage found = null; IEnumerable<INpmSearchResultPackage> searchResults = npm.SearchRemotePackages(module); if (searchResults != null) { foreach (INpmSearchResultPackage result in searchResults) { if (result.Name == module) { found = result; break; } } } if (found == null) { Console.WriteLine("SearchRemotePackages failed to find '{0}'", module); return false; } // install module as a dependency npm.InstallPackage(found); // list packages at parent IEnumerable<INpmInstalledPackage> installedPkg = npm.GetInstalledPackages(); if (installedPkg == null) { Console.WriteLine("GetInstalledPackages failed for {0}", found.Name); return false; } // there should be at least 1 item since we installed one if (installedPkg.Count() == 0) { Console.WriteLine("There are no packages listed"); return false; } // now call update npm.UpdatePackage(found); IEnumerable<INpmPackageDependency> outdated = npm.FindDependenciesToBeInstalled(found); if (outdated != null && outdated.Count() > 0) { Console.WriteLine("Expected no outdated entry after update of {0}", module); return false; } npm.UninstallPackage(installedPkg.First()); Console.WriteLine("Success! {0} was installed and uninstalled.", module); return true; } catch (NpmException ex) { Console.WriteLine("Npm failed with exception."); Console.WriteLine("Message: " + ex.Message); if (ex.InnerException != null) { Console.WriteLine("Inner message: " + ex.InnerException.Message); } else { if (ex.NpmCode != null) { Console.WriteLine("Code: " + ex.NpmCode); } if (ex.NpmCommand != null) { Console.WriteLine("calling: " + ex.NpmCommand); } } return false; } }
public void InstallPackageTest() { string wd = "c:\\root\\project1"; Uri registry = null; NpmFactory factory = new MockNpmFactory(); NpmPackageManager target = new NpmPackageManager(factory, wd, registry); NpmPackage package = new NpmPackage("install1", null); target.InstallPackage(package); Assert.IsTrue(true); // no exception thrown }
/// <summary> /// Execute InstallPackage /// </summary> /// <param name="npm">NpmPackageManager instance</param> /// <param name="name">name of package</param> private static void DoInstall(NpmPackageManager npm, string name) { NpmPackage pkg = new NpmPackage(name, null); npm.InstallPackage(pkg); }