public void InstallPackageToProjectsFromUI()
        {
            // Arrange
            EnsureVisualStudioHost();
            var dte             = VisualStudio.Dte;
            var solutionService = VisualStudio.Get <SolutionService>();

            solutionService.CreateEmptySolution();
            var project   = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");
            var nuProject = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "NuProject");

            // Act
            dte.ExecuteCommand("Project.ManageNuGetPackages");
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(nuProject);

            uiwindow.InstallPackageFromUI("newtonsoft.json", "9.0.1");
            VisualStudio.SelectProjectInSolutionExplorer(project.Name);
            dte.ExecuteCommand("Project.ManageNuGetPackages");

            VisualStudio.ClearOutputWindow();
            var uiwindow2 = nugetTestService.GetUIWindowfromProject(project);

            uiwindow2.InstallPackageFromUI("newtonsoft.json", "9.0.1");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "newtonsoft.json", "9.0.1", XunitLogger);
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, nuProject, "newtonsoft.json", "9.0.1", XunitLogger);
        }
        public async Task WithExpiredCertificate_InstallFromPMCForPC_WarnAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
                using (var trustedExpiringTestCert = SigningUtility.GenerateTrustedTestCertificateThatWillExpireSoon())
                {
                    XunitLogger.LogInformation("Creating package");
                    var package = CommonUtility.CreatePackage("ExpiredTestPackage", "1.0.0");

                    XunitLogger.LogInformation("Signing package");
                    var expiredTestPackage = CommonUtility.RepositorySignPackage(package, trustedExpiringTestCert.Source.Cert, new Uri("https://v3serviceIndexUrl.test/api/index.json"));
                    await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, expiredTestPackage);

                    XunitLogger.LogInformation("Waiting for package to expire");
                    SigningUtility.WaitForCertificateToExpire(trustedExpiringTestCert.Source.Cert);

                    var nugetConsole = GetConsole(testContext.Project);

                    nugetConsole.InstallPackageFromPMC(expiredTestPackage.Id, expiredTestPackage.Version);

                    // TODO: Fix bug where no warnings are shown when package is untrusted but still installed
                    //nugetConsole.IsMessageFoundInPMC("expired certificate").Should().BeTrue("expired certificate warning");
                    CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                }
        }
Exemple #3
0
        public async Task DowngradeSignedToUnsignedVersionFromPMCForPC_SucceedAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            // This test is not considered an ideal behavior of the product but states the current behavior.
            // A package that is already installed as signed should be specailly treated and a user should not be
            // able to downgrade to an unsigned version. This test needs to be updated once this behavior gets
            // corrected in the product.

            var packageVersion09 = "0.9.0";
            var signedPackage    = _fixture.AuthorSignedTestPackage;

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, signedPackage.Id, packageVersion09);

                await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, signedPackage);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(signedPackage.Id, signedPackage.Version);
                nugetConsole.UpdatePackageFromPMC(signedPackage.Id, packageVersion09);

                CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, signedPackage.Id, packageVersion09, XunitLogger);
            }
        }
        public void UpdatePackageFromUI()
        {
            // Arrange
            EnsureVisualStudioHost();
            var dte             = VisualStudio.Dte;
            var solutionService = VisualStudio.Get <SolutionService>();

            solutionService.CreateEmptySolution();
            var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            VisualStudio.ClearWindows();
            solutionService.SaveAll();

            // Act
            OpenNuGetPackageManagerWithDte();
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(project);

            uiwindow.InstallPackageFromUI("newtonsoft.json", "9.0.1");

            // Act
            VisualStudio.ClearWindows();
            uiwindow.UpdatePackageFromUI("newtonsoft.json", "10.0.3");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "newtonsoft.json", "10.0.3", XunitLogger);
        }
Exemple #5
0
        public async Task InstallPackageFromUI_PC_PackageSourceMapping_WithMultiFeed_Succeed()
        {
            // Arrange
            EnsureVisualStudioHost();
            var    solutionService        = VisualStudio.Get <SolutionService>();
            string solutionDirectory      = CommonUtility.CreateSolutionDirectory(Directory.GetCurrentDirectory());
            var    externalRepositoryPath = Path.Combine(solutionDirectory, "ExternalRepository");

            Directory.CreateDirectory(externalRepositoryPath);
            var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");

            Directory.CreateDirectory(privateRepositoryPath);

            // Create nuget.config with Package source mapping filtering rules before project is created.
            CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key=""encyclopaedia"" value=""{externalRepositoryPath}"" />
    <add key=""encyclopædia"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageSourceMapping>
        <packageSource key=""encyclopaedia"">
            <package pattern=""External.*"" />
            <package pattern=""Others.*"" />
        </packageSource>
        <packageSource key=""encyclopædia"">
            <package pattern=""Contoso.*"" />
            <package pattern=""Test.*"" />
        </packageSource>
    </packageSourceMapping>
//</configuration>");

            solutionService.CreateEmptySolution("TestSolution", solutionDirectory);
            var packageName     = "Contoso.A";
            var packageVersion1 = "1.0.0";
            await CommonUtility.CreatePackageInSourceAsync(externalRepositoryPath, packageName, packageVersion1);

            await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1);

            var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            VisualStudio.ClearOutputWindow();
            solutionService.SaveAll();

            // Act
            CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, XunitLogger);
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(project);

            // Set option to package source option to All
            uiwindow.SetPackageSourceOptionToAll();
            uiwindow.InstallPackageFromUI("contoso.a", "1.0.0");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "contoso.a", XunitLogger);
        }
Exemple #6
0
        public async Task SimpleUpdateFromIVsInstaller_PackageSourceMapping_WithSingleFeed()
        {
            // Arrange
            EnsureVisualStudioHost();
            var    dte               = VisualStudio.Dte;
            string mainDirectory     = CommonUtility.CreateSolutionDirectory(Directory.GetCurrentDirectory());
            string solutionDirectory = Path.Combine(mainDirectory, "Solution");
            var    solutionService   = VisualStudio.Get <SolutionService>();
            var    nugetTestService  = GetNuGetTestService();

            var privateRepositoryPath = Path.Combine(mainDirectory, "PrivateRepository");

            Directory.CreateDirectory(privateRepositoryPath);

            var packageName      = "Contoso.A";
            var packageVersionV1 = "1.0.0";
            var packageVersionV2 = "2.0.0";

            await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersionV1, "Thisisfromprivaterepo1.txt");

            await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersionV2, "Thisisfromprivaterepo2.txt");

            // Create nuget.config with Package source mapping filtering rules before project is created.
            CommonUtility.CreateConfigurationFile(Path.Combine(mainDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageSourceMapping>
        <packageSource key=""PrivateRepository"">
            <package pattern=""Contoso.*"" />
            <package pattern=""Test.*"" />
        </packageSource>
    </packageSourceMapping>
</configuration>");

            solutionService.CreateEmptySolution("TestSolution", solutionDirectory);
            var projExt = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            solutionService.SaveAll();
            var project = dte.Solution.Projects.Item(1);

            // Act
            nugetTestService.InstallPackage(project.UniqueName, "contoso.a", "1.0.0");
            nugetTestService.InstallPackage(project.UniqueName, "contoso.a", "2.0.0");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, projExt, packageName, XunitLogger);

            var packagesDirectory = Path.Combine(solutionDirectory, "packages");
            var uniqueContentFile = Path.Combine(packagesDirectory, packageName + '.' + packageVersionV2, "lib", "net45", "Thisisfromprivaterepo2.txt");

            // Make sure version 2 is restored.
            Assert.True(File.Exists(uniqueContentFile));
        }
Exemple #7
0
        public async Task InstallPackageToProjectsFromUI_PackageNamespace_WithSingleFeed_Match_Succeeds()
        {
            // Arrange
            EnsureVisualStudioHost();
            var    solutionService   = VisualStudio.Get <SolutionService>();
            string solutionDirectory = CommonUtility.CreateSolutionDirectory(Directory.GetCurrentDirectory());

            solutionService.CreateEmptySolution("TestSolution", solutionDirectory);

            var privateRepositoryPath = Path.Combine(solutionService.ContainingDirectory, "PrivateRepository");

            Directory.CreateDirectory(privateRepositoryPath);

            var packageName    = "Contoso.A";
            var packageVersion = "1.0.0";

            await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion);

            // Create nuget.config with Package namespace filtering rules before project is created.
            CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageNamespaces>
        <packageSource key=""PrivateRepository"">
            <namespace id=""Contoso.*"" />
            <namespace id=""Test.*"" />
        </packageSource>
    </packageNamespaces>
//</configuration>");

            var project   = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");
            var nuProject = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "NuProject");

            solutionService.SaveAll();

            // Act
            OpenNuGetPackageManagerWithDte();
            var nugetTestService = GetNuGetTestService();
            var uiwindow         = nugetTestService.GetUIWindowfromProject(nuProject);

            uiwindow.InstallPackageFromUI("contoso.a", "1.0.0");
            VisualStudio.SelectProjectInSolutionExplorer(project.Name);
            OpenNuGetPackageManagerWithDte();

            VisualStudio.ClearOutputWindow();
            var uiwindow2 = nugetTestService.GetUIWindowfromProject(project);

            uiwindow2.InstallPackageFromUI("contoso.a", "1.0.0");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "contoso.a", "1.0.0", XunitLogger);
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, nuProject, "contoso.a", "1.0.0", XunitLogger);
        }
Exemple #8
0
        public async Task UpdatePackageForPC_PackageNamespace_WithSingleFeed(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using var simpleTestPathContext = new SimpleTestPathContext();
            string solutionDirectory     = simpleTestPathContext.SolutionRoot;
            var    privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");

            Directory.CreateDirectory(privateRepositoryPath);

            var packageName     = "Contoso.A";
            var packageVersion1 = "1.0.0";
            var packageVersion2 = "2.0.0";

            await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1);

            await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion2);

            //Create nuget.config with Package namespace filtering rules.
            CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageNamespaces>
        <packageSource key=""PrivateRepository"">
            <namespace id=""Contoso.*"" />             
            <namespace id=""Test.*"" />
        </packageSource>
    </packageNamespaces>
//</configuration>");

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext))
            {
                var nugetConsole = GetConsole(testContext.Project);

                // Act
                nugetConsole.InstallPackageFromPMC(packageName, packageVersion1);
                nugetConsole.UpdatePackageFromPMC(packageName, packageVersion2);

                // Assert
                CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, packageVersion2, XunitLogger);
            }
        }
Exemple #9
0
        public async Task InstallPackageFromPMCVerifyInstallForPCAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                var packageName    = "TestPackage";
                var packageVersion = "1.0.0";
                await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(packageName, packageVersion);

                CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, packageVersion, XunitLogger);
            }
        }
        public async Task InstallFromPMCForPC_SucceedAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            var signedPackage = _fixture.RepositorySignedTestPackage;

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
            {
                await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, signedPackage);

                var nugetConsole = GetConsole(testContext.Project);

                nugetConsole.InstallPackageFromPMC(signedPackage.Id, signedPackage.Version);

                CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, signedPackage.Id, signedPackage.Version, XunitLogger);
            }
        }
        public void SimpleInstallFromIVsInstaller()
        {
            // Arrange
            EnsureVisualStudioHost();
            var dte              = VisualStudio.Dte;
            var solutionService  = VisualStudio.Get <SolutionService>();
            var nugetTestService = GetNuGetTestService();

            solutionService.CreateEmptySolution();
            var projExt = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.ClassLibrary, ProjectTargetFramework.V46, "TestProject");

            var project = dte.Solution.Projects.Item(1);

            // Act
            nugetTestService.InstallPackage(project.UniqueName, "newtonsoft.json");

            // Assert
            CommonUtility.AssertPackageInPackagesConfig(VisualStudio, projExt, "newtonsoft.json", XunitLogger);
        }
Exemple #12
0
        public async Task WithExpiredAuthorCertificateAtCountersigning_InstallFromPMCForPC_WarnAsync(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            var timestampService = await _fixture.GetDefaultTrustedTimestampServiceAsync();

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger))
                using (var trustedCert = _fixture.TrustedRepositoryTestCertificate)
                    using (var trustedExpiringTestCert = SigningUtility.GenerateTrustedTestCertificateThatWillExpireSoon())
                    {
                        XunitLogger.LogInformation("Creating package");
                        var package = CommonUtility.CreatePackage("ExpiredTestPackage", "1.0.0");

                        XunitLogger.LogInformation("Signing package");
                        var expiredTestPackage = CommonUtility.AuthorSignPackage(package, trustedExpiringTestCert.Source.Cert);
                        await SimpleTestPackageUtility.CreatePackagesAsync(testContext.PackageSource, expiredTestPackage);

                        var packageFullName = Path.Combine(testContext.PackageSource, expiredTestPackage.PackageName);

                        XunitLogger.LogInformation("Waiting for package to expire");
                        SigningUtility.WaitForCertificateToExpire(trustedExpiringTestCert.Source.Cert);

                        XunitLogger.LogInformation("Countersigning package");
                        var countersignedPackage = await SignedArchiveTestUtility.RepositorySignPackageAsync(
                            new X509Certificate2(trustedCert.Source.Cert),
                            packageFullName,
                            testContext.PackageSource,
                            new Uri("https://v3serviceIndexUrl.test/api/index.json"),
                            timestampService.Url);

                        File.Copy(countersignedPackage, packageFullName, overwrite: true);
                        File.Delete(countersignedPackage);

                        var nugetConsole = GetConsole(testContext.Project);

                        nugetConsole.InstallPackageFromPMC(expiredTestPackage.Id, expiredTestPackage.Version);

                        // TODO: Fix bug where no warnings are shown when package is untrusted but still installed
                        //nugetConsole.IsMessageFoundInPMC("expired certificate").Should().BeTrue("expired certificate warning");
                        CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, expiredTestPackage.Id, expiredTestPackage.Version, XunitLogger);
                    }
        }
Exemple #13
0
        public async Task UpdatePackageForPC_PackageNamespace_WithMultipleFeedsWithIdenticalPackages_UpdatesCorrectPackage(ProjectTemplate projectTemplate)
        {
            // Arrange
            EnsureVisualStudioHost();

            using var simpleTestPathContext = new SimpleTestPathContext();
            string solutionDirectory = simpleTestPathContext.SolutionRoot;
            var    packageName       = "Contoso.A";
            var    packageVersion1   = "1.0.0";
            var    packageVersion2   = "2.0.0";

            var opensourceRepositoryPath = Path.Combine(solutionDirectory, "OpensourceRepository");

            Directory.CreateDirectory(opensourceRepositoryPath);

            await CommonUtility.CreateNetCorePackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion1, "Thisisfromopensourcerepo1.txt");

            await CommonUtility.CreateNetCorePackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion2, "Thisisfromopensourcerepo2.txt");

            var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository");

            Directory.CreateDirectory(privateRepositoryPath);

            await CommonUtility.CreateNetCorePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1, "Thisisfromprivaterepo1.txt");

            await CommonUtility.CreateNetCorePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion2, "Thisisfromprivaterepo2.txt");

            //Create nuget.config with Package namespace filtering rules.
            CommonUtility.CreateConfigurationFile(Path.Combine(solutionDirectory, "NuGet.config"), $@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
    <!--To inherit the global NuGet package sources remove the <clear/> line below -->
    <clear />
    <add key=""ExternalRepository"" value=""{opensourceRepositoryPath}"" />
    <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" />
    </packageSources>
    <packageNamespaces>
        <packageSource key=""externalRepository"">
            <namespace id=""External.*"" />
            <namespace id=""Others.*"" />
        </packageSource>
        <packageSource key=""PrivateRepository"">
            <namespace id=""Contoso.*"" />             
            <namespace id=""Test.*"" />
        </packageSource>
    </packageNamespaces>
//</configuration>");

            using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger, noAutoRestore: false, addNetStandardFeeds: false, simpleTestPathContext: simpleTestPathContext))
            {
                var nugetConsole = GetConsole(testContext.Project);

                // Act
                nugetConsole.InstallPackageFromPMC(packageName, packageVersion1);
                nugetConsole.UpdatePackageFromPMC(packageName, packageVersion2);

                // Assert
                CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, packageVersion2, XunitLogger);

                var packagesDirectory = Path.Combine(solutionDirectory, "packages");
                var uniqueContentFile = Path.Combine(packagesDirectory, packageName + '.' + packageVersion2, "lib", "net5.0", "Thisisfromprivaterepo2.txt");
                // Make sure name squatting package not restored from  opensource repository.
                Assert.True(File.Exists(uniqueContentFile));
            }
        }