Example #1
0
        private void InstallPackageInternal(string packagePath, bool updateAll = false)
        {
            using (NuGetPackageTestHelper nugetHelper = new NuGetPackageTestHelper())
            {
                //nugetHelper.vsProjectManager.CloseAllSkus();
                //Launch appropriate version of VS and SKU
                nugetHelper.vsProjectManager.LaunchVS(vsVersion, vsSKU);
                //Create project with desired template and framework.
                if (string.IsNullOrEmpty(AppSettingsHelper.ProjectTemplateFullPathKeyValue))
                {
                    nugetHelper.vsProjectManager.CreateProject(AppSettingsHelper.ProjectTemplateNameKeyValue, AppSettingsHelper.ProjectTemplateLanguageKeyValue, ProjectTargetFrameworks.Net45, projName, Path.Combine(TestRunPath, DateTime.Now.Ticks.ToString()));
                }
                else
                {
                    nugetHelper.vsProjectManager.CreateProject(AppSettingsHelper.ProjectTemplateFullPathKeyValue, ProjectTargetFrameworks.Net45, projName, Path.Combine(TestRunPath, DateTime.Now.Ticks.ToString()));
                }
                string packageInstallOutput = string.Empty;
                //Install package and get output.
                bool installPassed = nugetHelper.nuGetPackageManager.InstallPackage(packagePath, out packageInstallOutput, updateAll);
                TestContext.WriteLine("Output from package installation :{0} {1}", Environment.NewLine, packageInstallOutput);

                //Get output from individual verifiers.
                bool          individualVerifierResults = true;
                StringBuilder resultString = new StringBuilder();
                foreach (var verifier in nugetHelper.PackageInstallationVerifiers)
                {
                    bool?passed = verifier.Value.Validate(packagePath, nugetHelper.vsProjectManager);
                    if (!passed.HasValue)
                    {
                        continue;
                    }
                    else
                    {
                        resultString.AppendFormat("Output from {0} :", verifier.Metadata.Name);
                        if (passed == true)
                        {
                            resultString.AppendLine(verifier.Value.Output);
                        }
                        if (passed == false)
                        {
                            individualVerifierResults = false;
                            resultString.AppendLine(verifier.Value.Error);
                        }
                    }
                }
                TestContext.WriteLine(resultString.ToString());
                testContextInstance.Properties.Add("Details", packageInstallOutput);
                nugetHelper.vsProjectManager.CloseSolution();
                Assert.IsTrue(installPassed);
                Assert.IsTrue(individualVerifierResults, "Verification from individual verifiers has failed. Check logs for details");
            }
        }
Example #2
0
 public void StaticAnalysis()
 {
     using (NuGetPackageTestHelper nugetHelper = new NuGetPackageTestHelper())
     {
         //Analyze package and verify package installtion
         string analysisOutput = nugetHelper.nuGetPackageManager.AnalyzePackage(packagePath);
         testContextInstance.Properties.Add("Details", analysisOutput);
         TestContext.WriteLine("Output from package Analysis :{0}", analysisOutput);
         if (!string.IsNullOrEmpty(analysisOutput))
         {
             string summaryLine = analysisOutput.Substring(0, analysisOutput.IndexOf(" found with package '"));
             warningCount = Convert.ToInt32(summaryLine.Substring(summaryLine.IndexOf("warnings") - 3, 2).Trim());
             Assert.IsTrue(!summaryLine.Contains("errors"), "static analysis errors found in the package");
         }
     }
 }
        private void StaticAnalysis()
        {
            try
            {
                using (NuGetPackageTestHelper nugetHelper = new NuGetPackageTestHelper())
                {
                    //Analyze package and verify package installtion
                    bool   analysisPassed = true;
                    string analysisOutput = nugetHelper.nuGetPackageManager.AnalyzePackage(packagePath);

                    if (!string.IsNullOrEmpty(analysisOutput))
                    {
                        analysisPassed = !analysisOutput.Contains("ERROR: ");
                    }
                    resultsDict.Add(new Tuple <string, string, string>("StaticAnalysis", analysisPassed ? "Passed" : "Failed", analysisOutput));
                }
            }catch (Exception e)
            {
                resultsDict.Add(new Tuple <string, string, string>("StaticAnalysis", "Failed", string.Format("Error while running static analysis. Message {0} {1} Stack track {2}", e.Message, Environment.NewLine, e.StackTrace)));
            }
        }
Example #4
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();
            }
        }
        private void InstallPackage(string packagePath, bool updateAll = false)
        {
            try
            {
                using (NuGetPackageTestHelper nugetHelper = new NuGetPackageTestHelper())
                {
                    if (AppSettingsHelper.CloseAllSKUsKeyValue.Equals("true", StringComparison.OrdinalIgnoreCase))
                    {
                        nugetHelper.vsProjectManager.CloseAllSkus();
                    }
                    //Launch appropriate version of VS and SKU
                    nugetHelper.vsProjectManager.LaunchVS(vsVersion, vsSKU);
                    //Create project with desired template and framework.
                    try
                    {
                        if (string.IsNullOrEmpty(AppSettingsHelper.ProjectTemplateFullPathKeyValue))
                        {
                            nugetHelper.vsProjectManager.CreateProject(AppSettingsHelper.ProjectTemplateNameKeyValue, AppSettingsHelper.ProjectTemplateLanguageKeyValue, ProjectTargetFrameworks.Net45, projName, Path.Combine(TestRunPath, DateTime.Now.Ticks.ToString()));
                        }
                        else
                        {
                            nugetHelper.vsProjectManager.CreateProject(AppSettingsHelper.ProjectTemplateFullPathKeyValue, ProjectTargetFrameworks.Net45, projName, Path.Combine(TestRunPath, DateTime.Now.Ticks.ToString()));
                        }
                    }catch (Exception e)
                    {
                        throw new ArgumentException(string.Format("Error while creating project out of template {0} for package {1}.Make sure that the template name is specified properly", AppSettingsHelper.ProjectTemplateNameKeyValue, packagePath));
                    }
                    string packageInstallOutput = string.Empty;
                    //Install package and get output.
                    bool installPassed = nugetHelper.nuGetPackageManager.InstallPackage(packagePath, out packageInstallOutput, updateAll);


                    //Get output from individual verifiers.
                    bool          individualVerifierResults = true;
                    StringBuilder resultString = new StringBuilder();
                    foreach (var verifier in nugetHelper.PackageInstallationVerifiers)
                    {
                        bool?passed = verifier.Value.Validate(packagePath, nugetHelper.vsProjectManager);
                        if (!passed.HasValue)
                        {
                            continue;
                        }
                        else
                        {
                            resultString.AppendFormat("Output from {0} :", verifier.Metadata.Name);
                            if (passed == true)
                            {
                                resultString.AppendLine(verifier.Value.Output);
                            }
                            if (passed == false)
                            {
                                individualVerifierResults = false;
                                resultString.AppendLine(verifier.Value.Error);
                            }
                        }
                    }

                    nugetHelper.vsProjectManager.CloseSolution();
                    resultsDict.Add(new Tuple <string, string, string>("Install", installPassed ? "Passed" : "Failed", packageInstallOutput + Environment.NewLine + "Output from individual verifiers :" + Environment.NewLine + resultString));
                }
            }catch (Exception e)
            {
                resultsDict.Add(new Tuple <string, string, string>("Install", "Failed", string.Format("Error while installing package from VS. Message {0} {1} Stack track {2}", e.Message, Environment.NewLine, e.StackTrace)));
            }
        }