public void TestIfCorrectPackagesAreInstalled() { bool arePackagesCorrect = true; Packages allPackages = new Packages(); allPackages.AllPackages = new Dictionary<string, string[]>(); allPackages.AllPackages.Add("backbone", new string[] { "jQuery", "underscore" }); allPackages.AllPackages.Add("jQuery" , new string[] { "queryJ" }); allPackages.AllPackages.Add("underscore", new string[] { "lodash" }); allPackages.AllPackages.Add("queryJ", new string[] { }); allPackages.AllPackages.Add("lodash", new string[] { }); Dependency dependency = new Dependency("Test0000", new object[] {"backbone"}); IOperator mockOperator = new PackagesOperatorMock(); mockOperator.InstallRequiredPackages(allPackages, dependency, "lodash"); string[] packagesResult = new string[] { "backbone", "jQuery", "queryJ", "underscore", "lodash", }; int position = 0; foreach (KeyValuePair<string, bool> package in mockOperator.ShowInstalledPackages()) { if(package.Key != packagesResult[position]) { arePackagesCorrect = false; break; } position++; } Assert.AreEqual(true, arePackagesCorrect); }
// <summary> /// Deserializes the project's dependencies /// </summary> /// <param name="path">String path of the dependencies .json file</param> /// <param name="jsSerializer">Javascript deserializer instanace used for the deserialization</param> /// <returns>Dependacy of all project dependencies</returns> public static Dependency DeserializeJsonDependencies(string path, JavaScriptSerializer jsSerializer) { Dependency dependencies = new Dependency(); using (var reader = new StreamReader(path)) { var dependenciesPackagesFile = reader.ReadToEnd(); dependencies = jsSerializer.Deserialize<Dependency>(dependenciesPackagesFile); } return dependencies; }
public void InstallRequiredPackages(Packages packages, Dependency dependencies, string installedPackagesString) { installedPackages = this.GetInstalledPackages(installedPackagesString); if (!Object.ReferenceEquals(null, dependencies)) { foreach (var dependcyPackage in dependencies.Dependencies) { InstallPackage(packages, dependencies, installedPackages, dependcyPackage.ToString()); } } else { throw new ArgumentException("Error! Dependencies object is null"); } }
private void InstallPackage(Packages packages, Dependency dependencies, Dictionary<string, bool> installedPackages, string currentPackage) { if (packages.AllPackages.ContainsKey(currentPackage)) { if (!installedPackages.ContainsKey(currentPackage)) { installedPackages.Add(currentPackage, true); } foreach (var package in packages.AllPackages[currentPackage]) { if (!installedPackages.ContainsKey(package)) { InstallPackage(packages, dependencies, installedPackages, package); } } } }
/// <summary> /// Install all required packages for the projecy /// </summary> /// <param name="packages">All available packages and their dependencies</param> /// <param name="dependencies">Project's dependencies</param> /// <param name="path">Path to install the packages</param> public void InstallRequiredPackages(Packages packages, Dependency dependencies, string path) { Dictionary<string, bool> installedPackages = this.GetInstalledPackages(path); if (!Object.ReferenceEquals(null, dependencies)) { foreach (var dependcyPackage in dependencies.Dependencies) { InstallNotifier.DisplayCurrentInstall(dependcyPackage.ToString()); InstallNotifier.DisplayDependencyPackages(packages, dependcyPackage.ToString(), installedPackages); InstallPackage(packages, dependencies, installedPackages, path, dependcyPackage.ToString()); Directory.CreateDirectory(path + @"\" + dependcyPackage); } InstallNotifier.DisplayEndMessage(); } else { InstallNotifier.DisplayNoProjectErrorMessage(); } }
/// <summary> /// Installs single package /// </summary> /// <param name="packages">All available packages and their dependencies</param> /// <param name="dependencies">Project's dependencies</param> /// <param name="installedPackages">Allready installed packages</param> /// <param name="path">Directory path to install the packages</param> /// <param name="currentPackage">Current packge to be installed</param> private void InstallPackage(Packages packages, Dependency dependencies, Dictionary<string, bool> installedPackages, string path, string currentPackage) { if (packages.AllPackages.ContainsKey(currentPackage)) { foreach (var package in packages.AllPackages[currentPackage]) { if (!installedPackages.ContainsKey(package)) { InstallNotifier.DisplayCurrentInstall(package); InstallNotifier.DisplayDependencyPackages(packages, package, installedPackages); InstallPackage(packages, dependencies, installedPackages, path, package); installedPackages.Add(package, true); Directory.CreateDirectory(path + @"\" + package); } } } }