public async Task InstallPackageForPR_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 opensourceRepositoryPath = Path.Combine(solutionDirectory, "OpensourceRepository"); Directory.CreateDirectory(opensourceRepositoryPath); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(opensourceRepositoryPath, packageName, packageVersion1); var privateRepositoryPath = Path.Combine(solutionDirectory, "PrivateRepository"); Directory.CreateDirectory(privateRepositoryPath); await CommonUtility.CreateNetFrameworkPackageInSourceAsync(privateRepositoryPath, packageName, packageVersion1); //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 nugetConsole = GetConsole(testContext.Project); // Act nugetConsole.InstallPackageFromPMC(packageName, packageVersion1); // Assert var expectedMessage = $"Installed {packageName} {packageVersion1} from {privateRepositoryPath}"; Assert.True(nugetConsole.IsMessageFoundInPMC(expectedMessage), expectedMessage); VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); Assert.True(VisualStudio.HasNoErrorsInOutputWindows()); }
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)); }
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)); } }