Ejemplo n.º 1
0
        private void SetupPackagesForTest(PackageManager packageManager, IEnumerable <MockPackageSpec> setup)
        {
            try
            {
                // Install all required packages
                foreach (MockPackageSpec package in setup)
                {
                    PackageInfo packageInfo = packageManager.GetPackage(package.Name);
                    if (packageInfo == null || packageInfo.Name != package.Name)
                    {
                        Assert.Inconclusive(
                            "Failed to create the required package setup for the test. Unable to retrieve package '{0}'",
                            package.Name);
                    }

                    packageManager.InstallPackage(packageInfo.Name);
                }

                // Make sure all required packages are really there
                foreach (MockPackageSpec package in setup)
                {
                    // Skip checking non-Duality packages, as they do not show up in
                    // the local package setup and thus would always fail this check.
                    bool isDualityPackage = package.Tags.Contains(PackageManager.DualityTag);
                    if (!isDualityPackage)
                    {
                        continue;
                    }

                    LocalPackage localPackage = packageManager.LocalSetup.GetPackage(package.Name);
                    if (localPackage == null)
                    {
                        Assert.Inconclusive(
                            "Failed to create the required package setup for the test. Install failed for package '{0}'",
                            package.Name);
                    }
                }

                // Make sure that the install didn't leave the setup out of sync with the install
                if (packageManager.IsPackageSyncRequired)
                {
                    Assert.Inconclusive(
                        "Failed to create the required package setup for the test. " +
                        "Local setup out of sync with installs.");
                }

                // Apply all scheduled copy and delete operations immediately
                if (File.Exists(this.workEnv.UpdateFilePath))
                {
                    PackageUpdateSchedule applyScript = PackageUpdateSchedule.Load(this.workEnv.UpdateFilePath);
                    applyScript.ApplyChanges(applyScript.Items);

                    // Get rid of the other scheduled updates
                    File.Delete(this.workEnv.UpdateFilePath);
                }
            }
            catch (Exception e)
            {
                Assert.Inconclusive(
                    "Failed to create the required package setup for the test because an exception occurred: {0}",
                    e);
            }
        }