public async Task SimpleUpdateFromIVsInstaller_PackageSourceMapping_WithMultipleFeedsWithIdenticalPackages_UpdatesCorrectPackage() { // 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 packageName = "Contoso.A"; var packageVersionV1 = "1.0.0"; var packageVersionV2 = "2.0.0"; var opensourceRepositoryPath = Path.Combine(mainDirectory, "OpensourceRepository"); Directory.CreateDirectory(opensourceRepositoryPath); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersionV1, "Thisisfromopensourcerepo1.txt"); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersionV2, "Thisisfromopensourcerepo2.txt"); var privateRepositoryPath = Path.Combine(mainDirectory, "PrivateRepository"); Directory.CreateDirectory(privateRepositoryPath); 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=""ExternalRepository"" value=""{opensourceRepositoryPath}"" /> <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" /> </packageSources> <packageSourceMapping> <packageSource key=""externalRepository""> <package pattern=""External.*"" /> <package pattern=""Others.*"" /> </packageSource> <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 name squatting package not restored from opensource repository. Assert.True(File.Exists(uniqueContentFile)); }
public async Task UpdatePackageForPC_PackageSourceMapping_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.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion1, "Thisisfromopensourcerepo1.txt"); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion2, "Thisisfromopensourcerepo2.txt"); var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository"); Directory.CreateDirectory(privateRepositoryPath); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1, "Thisisfromprivaterepo1.txt"); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersion2, "Thisisfromprivaterepo2.txt"); //Create nuget.config with Package source mapping 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> <packageSourceMapping> <packageSource key=""externalRepository""> <package pattern=""External.*"" /> <package pattern=""Others.*"" /> </packageSource> <packageSource key=""PrivateRepository""> <package pattern=""Contoso.*"" /> <package pattern=""Test.*"" /> </packageSource> </packageSourceMapping> </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", "net45", "Thisisfromprivaterepo2.txt"); // Make sure name squatting package not restored from opensource repository. Assert.True(File.Exists(uniqueContentFile)); } }
public async Task UpdatePackageForPR_PackageNamespace_WithMultipleFeedsWithIdenticalPackages_InstallsCorrectPackage(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.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion1); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion2); var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository"); Directory.CreateDirectory(privateRepositoryPath); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(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> <add key=""ExternalRepository"" value=""{opensourceRepositoryPath}"" /> <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" /> </packageSources> <packageSourceMapping> <packageSource key=""externalRepository""> <package pattern=""External.*"" /> <package pattern=""Others.*"" /> </packageSource> <packageSource key=""PrivateRepository""> <package pattern=""Contoso.*"" /> <package pattern=""Test.*"" /> </packageSource> <packageSource key=""nuget""> <package pattern=""Microsoft.*"" /> <package pattern=""NetStandard*"" /> </packageSource> </packageSourceMapping> </configuration>"); using var testContext = new ApexTestContext(VisualStudio, projectTemplate, XunitLogger, noAutoRestore: false, addNetStandardFeeds: true, simpleTestPathContext: simpleTestPathContext); var solutionService = VisualStudio.Get <SolutionService>(); var nugetConsole = GetConsole(testContext.Project); //Pre-conditions nugetConsole.InstallPackageFromPMC(packageName, packageVersion1); testContext.SolutionService.Build(); VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); VisualStudio.HasNoErrorsInOutputWindows().Should().BeTrue(); nugetConsole.Clear(); // Act nugetConsole.UpdatePackageFromPMC(packageName, packageVersion2); // Assert var expectedMessage = $"Installed {packageName} {packageVersion2} from {privateRepositoryPath}"; nugetConsole.IsMessageFoundInPMC(expectedMessage).Should().BeTrue(because: nugetConsole.GetText()); VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); VisualStudio.HasNoErrorsInOutputWindows().Should().BeTrue(); nugetConsole.Clear(); solutionService.Save(); }
public async Task UpdatePackageFromUI_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=""ExternalRepository"" value=""{externalRepositoryPath}"" /> <add key=""PrivateRepository"" value=""{privateRepositoryPath}"" /> </packageSources> <packageSourceMapping> <packageSource key=""externalRepository""> <package pattern=""External.*"" /> <package pattern=""Others.*"" /> </packageSource> <packageSource key=""PrivateRepository""> <package pattern=""Contoso.*"" /> <package pattern=""Test.*"" /> </packageSource> </packageSourceMapping> //</configuration>"); solutionService.CreateEmptySolution("TestSolution", solutionDirectory); var packageName = "Contoso.A"; var packageVersion1 = "1.0.0"; var packageVersion2 = "2.0.0"; await CommonUtility.CreatePackageInSourceAsync(externalRepositoryPath, packageName, packageVersion1); await CommonUtility.CreatePackageInSourceAsync(externalRepositoryPath, packageName, packageVersion2); await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1); await CommonUtility.CreatePackageInSourceAsync(privateRepositoryPath, packageName, packageVersion2); 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"); // Act uiwindow.InstallPackageFromUI("contoso.a", "2.0.0"); // Assert CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "contoso.a", "2.0.0", XunitLogger); }