public void ReadFromDirectory() {
     using (var manager = new TemporaryFileManager()) {
         var dir = manager.GetNewTempDirectory();
         FilesystemPackageJsonTestHelpers.CreatePackageJson(Path.Combine(dir.FullName, "package.json"), PkgSimple);
         CheckPackage(PackageJsonFactory.Create(new DirectoryPackageJsonSource(dir.FullName)));
     }
 }
        public void AddPackageNoPackageJsonThenUninstall() {
            using (var manager = new TemporaryFileManager()) {
                var rootDir = FilesystemPackageJsonTestHelpers.CreateRootPackage(manager, PkgSimple);
                File.Delete(Path.Combine(rootDir, "package.json"));
                var controller = NpmControllerFactory.Create(rootDir, string.Empty);
                controller.Refresh();
                var rootPackage = controller.RootPackage;
                Assert.IsNotNull(rootPackage, "Root package with no dependencies should not be null.");
                Assert.AreEqual(0, rootPackage.Modules.Count, "Should be no modules before package install.");

                using (var commander = controller.CreateNpmCommander()) {
                    Task<bool> task = commander.InstallPackageByVersionAsync("sax", "*", DependencyType.Standard, true);
                    task.Wait();
                }

                Assert.AreNotEqual(
                    rootPackage,
                    controller.RootPackage,
                    "Root package should be different after package installed.");

                rootPackage = controller.RootPackage;
                Assert.IsNotNull(rootPackage, "Root package should not be null after package installed.");
                Assert.AreEqual(1, rootPackage.Modules.Count, "Should be one module after package installed.");

                var module = controller.RootPackage.Modules["sax"];
                Assert.IsNotNull(module, "Installed package should not be null.");
                Assert.AreEqual("sax", module.Name, "Module name mismatch.");
                Assert.IsNotNull(module.PackageJson, "Module package.json should not be null.");
                Assert.IsFalse(
                    module.IsListedInParentPackageJson,
                    "Should be listed as a dependency in parent package.json.");
                Assert.IsFalse(module.IsMissing, "Should not be marked as missing.");
                Assert.IsFalse(module.IsDevDependency, "Should not be marked as dev dependency.");
                Assert.IsFalse(module.IsOptionalDependency, "Should not be marked as optional dependency.");
                Assert.IsFalse(module.IsBundledDependency, "Should not be marked as bundled dependency.");
                Assert.IsTrue(module.HasPackageJson, "Module should have its own package.json");

                using (var commander = controller.CreateNpmCommander()) {
                    Task<bool> task = commander.UninstallPackageAsync("sax");
                    task.Wait();
                }

                Assert.AreNotEqual(
                    rootPackage,
                    controller.RootPackage,
                    "Root package should be different after package uninstalled.");

                rootPackage = controller.RootPackage;
                Assert.IsNotNull(rootPackage, "Root package should not be null after package uninstalled.");
                Assert.AreEqual(0, rootPackage.Modules.Count, "Should be no modules after package installed.");
            }
        }
 public void ReadRootPackageNoDependencies() {
     using (var manager = new TemporaryFileManager()) {
         var rootDir = FilesystemPackageJsonTestHelpers.CreateRootPackage(manager, PkgSimple);
         var pkg = RootPackageFactory.Create(rootDir);
         Assert.IsNotNull(pkg, "Root package should not be null.");
         Assert.AreEqual(rootDir, pkg.Path, "Package path mismatch.");
         var json = pkg.PackageJson;
         Assert.IsNotNull(json, "package.json should not be null.");
         Assert.AreEqual(json.Name, pkg.Name, "Package name mismatch.");
         Assert.AreEqual(json.Version, pkg.Version, "Package version mismatch.");
         var modules = pkg.Modules;
         Assert.IsNotNull(modules, "Modules should not be null.");
         Assert.AreEqual(0, modules.Count, "Module count mismatch.");
     }
 }
        public void AngularFullstackScaffoldedProject() {
            using (var manager = new TemporaryFileManager()) {
                var rootDir = FilesystemPackageJsonTestHelpers.CreateRootPackageDir(manager);
                var controller = NpmControllerFactory.Create(rootDir, string.Empty);
                controller.OutputLogged += controller_OutputLogged;
                controller.ErrorLogged += controller_OutputLogged;
                controller.Refresh();

                using (var commander = controller.CreateNpmCommander()) {
                    var task = commander.InstallGlobalPackageByVersionAsync("yo", "*");
                    task.Wait();
                }

                var info = new ProcessStartInfo();

                //  TODO!
            }
        }
        public void ReadRootPackageOneDependency() {
            using (var manager = new TemporaryFileManager()) {
                var rootDir = FilesystemPackageJsonTestHelpers.CreateRootPackage(manager, PkgSingleDependency);
                RunNpmInstall(rootDir);

                var pkg = RootPackageFactory.Create(rootDir);

                var json = pkg.PackageJson;
                var dependencies = json.AllDependencies;
                Assert.AreEqual(1, dependencies.Count, "Dependency count mismatch.");

                IDependency dep = dependencies["sax"];
                Assert.IsNotNull(dep, "sax dependency should not be null.");
                Assert.AreEqual(">=0.1.0 <0.2.0", dep.VersionRangeText, "Version range mismatch.");

                var modules = pkg.Modules;
                Assert.AreEqual(1, modules.Count, "Module count mismatch");

                IPackage module = modules[0];
                Assert.IsNotNull(module, "Module should not be null when retrieved by index.");
                module = modules["sax"];
                Assert.IsNotNull(module, "Module should not be null when retrieved by name.");

                Assert.AreEqual(modules[0], modules["sax"], "Modules should be same whether retrieved by name or index.");

                Assert.AreEqual("sax", module.Name, "Module name mismatch.");

                //  All of these should be indicated, in some way, in the Visual Studio treeview.

                Assert.IsNotNull(module.PackageJson, "Module package.json should not be null.");

                Assert.IsTrue(
                    module.IsListedInParentPackageJson,
                    "Should be listed as a dependency in parent package.json.");
                Assert.IsFalse(module.IsMissing, "Should not be marked as missing.");
                Assert.IsFalse(module.IsDevDependency, "Should not be marked as dev dependency.");
                Assert.IsFalse(module.IsOptionalDependency, "Should not be marked as optional dependency.");
                Assert.IsFalse(module.IsBundledDependency, "Should not be marked as bundled dependency.");

                //  Redundant?
                Assert.IsTrue(module.HasPackageJson, "Module should have its own package.json");
            }
        }
Ejemplo n.º 6
0
        public void InstallUninstallMaxPathGlobalModule() {
            using (var manager = new TemporaryFileManager()) {
                var rootDir = FilesystemPackageJsonTestHelpers.CreateRootPackage(manager, PkgSimple);
                var controller = NpmControllerFactory.Create(rootDir, string.Empty);

                using (var commander = controller.CreateNpmCommander()) {
                    commander.InstallPackageByVersionAsync("yo", "^1.2.0", DependencyType.Standard, false).Wait();
                }

                Assert.IsNotNull(controller.RootPackage, "Cannot retrieve packages after install");
                Assert.IsTrue(controller.RootPackage.Modules.Contains("yo"), "Package failed to install");

                using (var commander = controller.CreateNpmCommander()) {
                    commander.UninstallPackageAsync("yo").Wait();
                }

                // Command has completed, but need to wait for all files/folders to be deleted.
                Thread.Sleep(5000);

                Assert.IsNotNull(controller.RootPackage, "Cannot retrieve packages after uninstall");
                Assert.IsFalse(controller.RootPackage.Modules.Contains("yo"), "Package failed to uninstall");
            }
        }
 public void Init() {
     TempFileManager = new TemporaryFileManager();
 }
        public void ReadRootDependencyRecursive() {
            using (var manager = new TemporaryFileManager()) {

                var rootDir = FilesystemPackageJsonTestHelpers.CreateRootPackage(manager, PkgSingleRecursiveDependency);
                RunNpmInstall(rootDir);

                var pkg = RootPackageFactory.Create(rootDir);

                var json = pkg.PackageJson;
                var dependencies = json.AllDependencies;
                Assert.AreEqual(1, dependencies.Count, "Dependency count mismatch.");

                IDependency dep = dependencies["express"];
                Assert.IsNotNull(dep, "express dependency should not be null.");
                Assert.AreEqual("4.0.0", dep.VersionRangeText, "Version range mismatch.");

                var modules = pkg.Modules;
                Assert.AreEqual(1, modules.Count, "Module count mismatch");

                IPackage module = modules[0];
                Assert.IsNotNull(module, "Module should not be null when retrieved by index.");
                module = modules["express"];
                Assert.IsNotNull(module, "Module should not be null when retrieved by name.");

                Assert.AreEqual(
                    modules[0],
                    modules["express"],
                    "Modules should be same whether retrieved by name or index.");

                Assert.AreEqual("express", module.Name, "Module name mismatch.");

                Assert.AreEqual("4.0.0", module.Version.ToString(), "Module version mismatch");

                var expectedModules = new string[] {
                "accepts",
                "buffer-crc32",
                "cookie",
                "cookie-signature",
                "debug",
                "escape-html",
                "fresh",
                "merge-descriptors",
                "methods",
                "parseurl",
                "path-to-regexp",
                "qs",
                "range-parser",
                "send",
                "serve-static",
                "type-is",
                "utils-merge"
            };

                modules = module.Modules;

                Console.WriteLine("module.Modules includes: {0}", string.Join(", ", modules.Select(m => m.Name)));

                Assert.AreEqual(module.PackageJson.Dependencies.Count, modules.Count, "Sub-module count mismatch.");
                foreach (var name in expectedModules) {
                    Console.WriteLine("Expecting {0}", name);
                    var current = modules[name];
                    Assert.IsNotNull(current, "Module should not be null when retrieved by name.");

                    Assert.AreEqual(name, current.Name, "Module name mismatch.");

                    Assert.IsNotNull(current.PackageJson, "Module package.json should not be null.");

                    Assert.IsTrue(
                        current.IsListedInParentPackageJson,
                        "Should be listed as a dependency in parent package.json.");
                    Assert.IsFalse(current.IsMissing, "Should not be marked as missing.");
                    Assert.IsFalse(current.IsDevDependency, "Should not be marked as dev dependency.");
                    Assert.IsFalse(current.IsOptionalDependency, "Should not be marked as optional dependency.");
                    Assert.IsFalse(current.IsBundledDependency, "Should not be marked as bundled dependency.");

                    //  Redundant?
                    Assert.IsTrue(current.HasPackageJson, "Module should have its own package.json");
                }
            }
        }
 public static string CreateRootPackage(TemporaryFileManager manager, string json) {
     var dir = CreateRootPackageDir(manager);
     var path = Path.Combine(dir, "package.json");
     CreatePackageJson(path, json);
     return dir;
 }
 public static string CreateRootPackageDir(TemporaryFileManager manager) {
     return manager.GetNewTempDirectory().FullName;
 }