public PackageInstallsFromCacheStatus GetInstallFromCacheStatus(string mode) { #if DEBUG if (mode == "Testing") { if (installsFromCacheStatusTesting == null) { installsFromCacheStatusTesting = new PackageInstallsFromCacheStatus("Testing"); 10.Countdown((n) => { installsFromCacheStatusTesting.IncrementAll(); }); } else { installsFromCacheStatusTesting.RequestedRemaining--; installsFromCacheStatusTesting.TotalRemaining--; } return(installsFromCacheStatusTesting); } #endif return(packageCacheStatusProvider.GetInstallFromCacheStatus(mode)); }
private static void TestPackageWorkingInstallFromCache() { var name = "ionic"; var folderRoot = Environment.CurrentDirectory; var nodeModulesPath = Path.GetFullPath(Path.Combine(folderRoot, @"..\..\TestOutput\AngularProject\node_modules")); var cachePath = Environment.ExpandEnvironmentVariables(@"%APPDATA%\hydra\cache\" + name); var packagePath = Path.Combine(nodeModulesPath, name.BackSlashes()); var packageModules = new NpmNodeModules(nodeModulesPath); var workingInstallFromCache = new PackageWorkingInstallFromCache("installs", name, cachePath, packagePath, packageModules); var installsFromCacheStatus = new PackageInstallsFromCacheStatus("No activity reported"); string printTree; bool validate; TestPeerExists(); workingInstallFromCache.OnUpdateCacheStatus += (sender, e) => { switch (e.IncrementKind) { case IncrementKind.IncrementAll: Debug.Assert(e.Increment == 1); installsFromCacheStatus.IncrementAll(); break; case IncrementKind.IncrementTotal: Debug.Assert(e.Increment == 1); installsFromCacheStatus.IncrementTotal(); break; case IncrementKind.Total: installsFromCacheStatus.Total += e.Increment; break; case IncrementKind.TotalRemaining: installsFromCacheStatus.TotalRemaining += e.Increment; break; case IncrementKind.Requested: installsFromCacheStatus.Requested += e.Increment; break; case IncrementKind.RequestedRemaining: installsFromCacheStatus.RequestedRemaining += e.Increment; break; } }; workingInstallFromCache.OnAddInstallStatus += (sender, e) => { var installFromCache = e.InstallFromCache; var mode = e.StatusMode; var status = e.Status; var args = e.Args; if (args.Length > 0) { status = string.Format(status, args); } installFromCache.InstallStatusList.Add(installFromCache.CreateStatus(status, mode)); }; workingInstallFromCache.InstallPackage(false); validate = workingInstallFromCache.ValidateTree(installsFromCacheStatus); printTree = workingInstallFromCache.PrintTree(); workingInstallFromCache.ExecuteActions(); Console.WriteLine(installsFromCacheStatus.StatusText); Console.WriteLine(); Console.WriteLine(printTree); }