Exemple #1
0
        public void Initialize()
        {
            //extract package id and version.
            packagePath = AppSettingsHelper.PackageFullPathKeyValue;
            ZipPackage zipPackage = new ZipPackage(packagePath);

            packageId      = zipPackage.Id;
            packageVersion = zipPackage.Version.ToString();

            //set package sources.
            string PackageSource = Path.GetDirectoryName(packagePath);

            if (string.IsNullOrEmpty(PackageSource))
            {
                PackageSource = Environment.CurrentDirectory;
            }
            IList <KeyValuePair <string, string> > sources = new List <KeyValuePair <string, string> >();

            sources.Add(new KeyValuePair <string, string>("TestSource", PackageSource));
            //If additional sources are specified in the app.config file, add them too.
            if (!string.IsNullOrEmpty(AppSettingsHelper.PackageSourceKeyValue))
            {
                string[] additionalPackageSources = AppSettingsHelper.PackageSourceKeyValue.Split(new char[] { ',', ';' });
                int      i = 1;
                foreach (string additionalSource in additionalPackageSources)
                {
                    sources.Add(new KeyValuePair <string, string>("AdditionalSources_" + i.ToString(), additionalSource));
                    i++;
                }
            }
            NugetSettingsUtility.SetPackageSources(sources);
            NugetSettingsUtility.SetActivePackageSource("TestSource", PackageSource);

            //Set test run directory.
            if (string.IsNullOrEmpty(AppSettingsHelper.TestResultsPathKeyValue))
            {
                TestRunPath = Path.Combine(Environment.CurrentDirectory, packageId);
            }
            else
            {
                TestRunPath = AppSettingsHelper.TestResultsPathKeyValue;
            }
            //Create root level test run Dir
            if (!Directory.Exists(TestRunPath))
            {
                Directory.CreateDirectory(TestRunPath);
            }

            //initialize other values.
            projName  = DateTime.Now.Ticks.ToString();
            vsVersion = (VSVersion)Enum.Parse(typeof(VSVersion), AppSettingsHelper.VSVersionKeyValue, true);
            vsSKU     = (VSSKU)Enum.Parse(typeof(VSSKU), AppSettingsHelper.VSSKUKeyValue, true);
        }
Exemple #2
0
        public void InstallPackageFromFeed()
        {
            string feedUrl = NuGetTestHelper.Constants.NuGetOfficialSourceFeedValue;
            IList <KeyValuePair <string, string> > sources = new List <KeyValuePair <string, string> >();

            sources.Add(new KeyValuePair <string, string>("TestSource", feedUrl));
            NugetSettingsUtility.SetPackageSources(sources);
            NugetSettingsUtility.SetActivePackageSource("TestSource", feedUrl);
            using (NuGetPackageTestHelper nugetHelper = new NuGetPackageTestHelper())
            {
                nugetHelper.vsProjectManager.CloseAllSkus();
                //Launch appropriate version of VS and SKU
                nugetHelper.vsProjectManager.LaunchVS(VSVersion.VS2012, VSSKU.VSU);
                //Create project with desired template and framework.
                nugetHelper.vsProjectManager.CreateProject(ProjectTemplates.ConsoleAppCSharp, ProjectTargetFrameworks.Net45, Path.Combine(TestRunPath, DateTime.Now.Ticks.ToString()));
                string packageInstallOutput = string.Empty;
                //Install package and get output.
                bool installPassed = nugetHelper.nuGetPackageManager.InstallPackage("id", "version", out packageInstallOutput);
                TestContext.WriteLine("Output from package installation :{0} {1}", Environment.NewLine, packageInstallOutput);
                Assert.IsTrue(installPassed);
                nugetHelper.vsProjectManager.CloseSolution();
            }
        }