From bf6ce0b288103f6f75c79cc483142885bb3ab442 Mon Sep 17 00:00:00 2001 From: "Sue Su (BEYONDSOFT CONSULTING INC)" Date: Mon, 5 Aug 2024 01:28:29 +0000 Subject: [PATCH 1/4] add tests --- .../NetCoreProjectTestCase.cs | 18 ++++++-- .../NuGetConsoleTestCase.cs | 42 +++++++++++-------- .../SimpleTestSettingsContext.cs | 12 ++++++ 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs index 3fa86602ba7..734d230a577 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs @@ -12,7 +12,11 @@ namespace NuGet.Tests.Apex.Daily public class NetCoreProjectTestCase : SharedVisualStudioHostTestClass { [DataTestMethod] - [DynamicData(nameof(GetNetCoreTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.NetCoreConsoleApp)] + [DataRow(ProjectTemplate.NetCoreClassLib)] + [DataRow(ProjectTemplate.NetCoreXUnitTest)] + [DataRow(ProjectTemplate.NetStandardClassLib)] + [DataRow(ProjectTemplate.ASPNETCoreWebApplication)] [Timeout(DefaultTimeout)] public async Task InstallPackageToNetCoreProjectFromUI(ProjectTemplate projectTemplate) { @@ -40,7 +44,11 @@ public async Task InstallPackageToNetCoreProjectFromUI(ProjectTemplate projectTe } [DataTestMethod] - [DynamicData(nameof(GetNetCoreTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.NetCoreConsoleApp)] + [DataRow(ProjectTemplate.NetCoreClassLib)] + [DataRow(ProjectTemplate.NetCoreXUnitTest)] + [DataRow(ProjectTemplate.NetStandardClassLib)] + [DataRow(ProjectTemplate.ASPNETCoreWebApplication)] [Timeout(DefaultTimeout)] public async Task UpdatePackageToNetCoreProjectFromUI(ProjectTemplate projectTemplate) { @@ -77,7 +85,11 @@ public async Task UpdatePackageToNetCoreProjectFromUI(ProjectTemplate projectTem } [DataTestMethod] - [DynamicData(nameof(GetNetCoreTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.NetCoreConsoleApp)] + [DataRow(ProjectTemplate.NetCoreClassLib)] + [DataRow(ProjectTemplate.NetCoreXUnitTest)] + [DataRow(ProjectTemplate.NetStandardClassLib)] + [DataRow(ProjectTemplate.ASPNETCoreWebApplication)] [Timeout(DefaultTimeout)] public async Task UninstallPackageFromNetCoreProjectFromUI(ProjectTemplate projectTemplate) { diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs index 52099c61ceb..94d353abb68 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs @@ -17,34 +17,40 @@ namespace NuGet.Tests.Apex.Daily public class NuGetConsoleTestCase : SharedVisualStudioHostTestClass { [DataTestMethod] - [DynamicData(nameof(GetNetCoreTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.NetCoreConsoleApp)] + [DataRow(ProjectTemplate.ConsoleApplication)] + [DataRow(ProjectTemplate.UAPBlankApplication)] [Timeout(DefaultTimeout)] public async Task VerifyCacheFileInsideObjFolder(ProjectTemplate projectTemplate) { // Arrange EnsureVisualStudioHost(); - - using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, addNetStandardFeeds: true)) + using (var simpleTestPathContext = new SimpleTestPathContext()) { - var packageName = "VerifyCacheFilePackage"; - var packageVersion = "1.0.0"; - await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion); - var nugetConsole = GetConsole(testContext.Project); + simpleTestPathContext.Settings.SetPackageManagementToPackageReference(); - //Act - nugetConsole.InstallPackageFromPMC(packageName, packageVersion); - FileInfo CacheFilePath = CommonUtility.GetCacheFilePath(testContext.Project.FullPath); + using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, addNetStandardFeeds: true, simpleTestPathContext: simpleTestPathContext)) + { + var packageName = "VerifyCacheFilePackage"; + var packageVersion = "1.0.0"; + await CommonUtility.CreatePackageInSourceAsync(testContext.PackageSource, packageName, packageVersion); + var nugetConsole = GetConsole(testContext.Project); - // Assert - testContext.SolutionService.Build(); - testContext.NuGetApexTestService.WaitForAutoRestore(); - CommonUtility.WaitForFileExists(CacheFilePath); + //Act + nugetConsole.InstallPackageFromPMC(packageName, packageVersion); + FileInfo CacheFilePath = CommonUtility.GetCacheFilePath(testContext.Project.FullPath); + + // Assert + testContext.SolutionService.Build(); + testContext.NuGetApexTestService.WaitForAutoRestore(); + CommonUtility.WaitForFileExists(CacheFilePath); - testContext.Project.Rebuild(); - CommonUtility.WaitForFileExists(CacheFilePath); + testContext.Project.Rebuild(); + CommonUtility.WaitForFileExists(CacheFilePath); - testContext.Project.Clean(); - CommonUtility.WaitForFileNotExists(CacheFilePath); + testContext.Project.Clean(); + CommonUtility.WaitForFileNotExists(CacheFilePath); + } } } diff --git a/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs b/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs index 36ecf241bdd..967e0052e13 100644 --- a/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs +++ b/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs @@ -76,6 +76,18 @@ public void DisableAutomaticInPackageRestoreSection() Save(); } + /// + /// Set default package management format to PackageReference. + /// + public void SetPackageManagementToPackageReference() + { + var section = GetOrAddSection(XML, "packageManagement"); + + AddEntry(section, "format", "1"); + AddEntry(section, "disabled", "False"); + Save(); + } + private static XDocument GetDefault(string userPackagesFolder, string packagesV2, string fallbackFolder, string packageSource) { var doc = GetEmptyConfig(); From 9f79c45146634f9d573dd8658d43660a69aa7de9 Mon Sep 17 00:00:00 2001 From: "Sue Su (BEYONDSOFT CONSULTING INC)" Date: Wed, 7 Aug 2024 06:12:08 +0000 Subject: [PATCH 2/4] Change tests name --- .../NetCoreProjectTestCase.cs | 6 +-- .../NuGetConsoleTestCase.cs | 50 ++++++++++++++----- .../NuGet.Tests.Apex.Daily/NuGetUITestCase.cs | 4 +- .../SimpleTestSettingsContext.cs | 2 +- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs index 734d230a577..fd2bd41800d 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NetCoreProjectTestCase.cs @@ -18,7 +18,7 @@ public class NetCoreProjectTestCase : SharedVisualStudioHostTestClass [DataRow(ProjectTemplate.NetStandardClassLib)] [DataRow(ProjectTemplate.ASPNETCoreWebApplication)] [Timeout(DefaultTimeout)] - public async Task InstallPackageToNetCoreProjectFromUI(ProjectTemplate projectTemplate) + public async Task InstallPackageToSDKBasedProjectFromUI(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); @@ -50,7 +50,7 @@ public async Task InstallPackageToNetCoreProjectFromUI(ProjectTemplate projectTe [DataRow(ProjectTemplate.NetStandardClassLib)] [DataRow(ProjectTemplate.ASPNETCoreWebApplication)] [Timeout(DefaultTimeout)] - public async Task UpdatePackageToNetCoreProjectFromUI(ProjectTemplate projectTemplate) + public async Task UpdatePackageToSDKBasedProjectFromUI(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); @@ -91,7 +91,7 @@ public async Task UpdatePackageToNetCoreProjectFromUI(ProjectTemplate projectTem [DataRow(ProjectTemplate.NetStandardClassLib)] [DataRow(ProjectTemplate.ASPNETCoreWebApplication)] [Timeout(DefaultTimeout)] - public async Task UninstallPackageFromNetCoreProjectFromUI(ProjectTemplate projectTemplate) + public async Task UninstallPackageFromSDKBasedProjectFromUI(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs index 94d353abb68..464891554b7 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs @@ -27,7 +27,7 @@ public async Task VerifyCacheFileInsideObjFolder(ProjectTemplate projectTemplate EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) { - simpleTestPathContext.Settings.SetPackageManagementToPackageReference(); + simpleTestPathContext.Settings.SetPackageFormatToPackageReference(); using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, addNetStandardFeeds: true, simpleTestPathContext: simpleTestPathContext)) { @@ -102,15 +102,16 @@ public async Task UpdateAllPackagesInPMC(ProjectTemplate projectTemplate, string } [DataTestMethod] - [DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.MauiClassLibrary)] + [DataRow(ProjectTemplate.WebApplicationEmpty)] [Timeout(DefaultTimeout)] - public async Task InstallPackageForMauiProjectInPMC(ProjectTemplate projectTemplate) + public async Task InstallPackageInPMC(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) { // Arrange - var packageName = "IOSTestPackage"; + var packageName = "TestPackage"; var v100 = "1.0.0"; await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, packageName, v100); simpleTestPathContext.Settings.AddSource(NuGetConstants.NuGetHostName, NuGetConstants.V3FeedUrl); @@ -130,22 +131,30 @@ public async Task InstallPackageForMauiProjectInPMC(ProjectTemplate projectTempl // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v100, Logger); + if (projectTemplate.ToString().Equals("WebApplicationEmpty")) + { + CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v100, Logger); + } + else + { + CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v100, Logger); + } Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); } } } [DataTestMethod] - [DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.MauiClassLibrary)] + [DataRow(ProjectTemplate.WebApplicationEmpty)] [Timeout(DefaultTimeout)] - public async Task UpdatePackageForMauiProjectInPMC(ProjectTemplate projectTemplate) + public async Task UpdatePackageInPMC(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) { // Arrange - var packageName = "IOSTestPackage"; + var packageName = "TestPackage"; var v100 = "1.0.0"; var v200 = "2.0.0"; @@ -172,22 +181,30 @@ public async Task UpdatePackageForMauiProjectInPMC(ProjectTemplate projectTempla // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v200, Logger); + if (projectTemplate.ToString().Equals("WebApplicationEmpty")) + { + CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v200, Logger); + } + else + { + CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v200, Logger); + } Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); } } } [DataTestMethod] - [DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)] + [DataRow(ProjectTemplate.MauiClassLibrary)] + [DataRow(ProjectTemplate.WebApplicationEmpty)] [Timeout(DefaultTimeout)] - public async Task UninstallPackageForMauiProjectInPMC(ProjectTemplate projectTemplate) + public async Task UninstallPackageInPMC(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) { // Arrange - var PackageName = "IOSTestPackage"; + var PackageName = "TestPackage"; var v100 = "1.0.0"; await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, PackageName, v100); @@ -213,7 +230,14 @@ public async Task UninstallPackageForMauiProjectInPMC(ProjectTemplate projectTem // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - CommonUtility.AssertPackageNotInAssetsFile(VisualStudio, testContext.Project, PackageName, v100, Logger); + if (projectTemplate.ToString().Equals("WebApplicationEmpty")) + { + CommonUtility.AssertPackageNotInPackagesConfig(VisualStudio, testContext.Project, PackageName, v100, Logger); + } + else + { + CommonUtility.AssertPackageNotInAssetsFile(VisualStudio, testContext.Project, PackageName, v100, Logger); + } Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); } } diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetUITestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetUITestCase.cs index 32c1bdd877b..16fd5b9b2ac 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetUITestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetUITestCase.cs @@ -25,7 +25,7 @@ public NuGetUITestCase() { } - [Ignore] + [Ignore("https://github.com/NuGet/Client.Engineering/issues/2829")] [TestMethod] [Timeout(DefaultTimeout)] public void InstallPackageToWebSiteProjectFromUI() @@ -49,7 +49,7 @@ public void InstallPackageToWebSiteProjectFromUI() CommonUtility.AssertPackageInPackagesConfig(VisualStudio, project, "log4net", "2.0.12", Logger); } - [Ignore] + [Ignore("https://github.com/NuGet/Client.Engineering/issues/2829")] [TestMethod] [Timeout(DefaultTimeout)] public void UpdateWebSitePackageFromUI() diff --git a/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs b/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs index 967e0052e13..d4028cd4b67 100644 --- a/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs +++ b/test/TestUtilities/Test.Utility/SimpleTestSetup/SimpleTestSettingsContext.cs @@ -79,7 +79,7 @@ public void DisableAutomaticInPackageRestoreSection() /// /// Set default package management format to PackageReference. /// - public void SetPackageManagementToPackageReference() + public void SetPackageFormatToPackageReference() { var section = GetOrAddSection(XML, "packageManagement"); From 278d1728c4b8eaec8ff49fe7a26698ddebdfc856 Mon Sep 17 00:00:00 2001 From: "Sue Su (BEYONDSOFT CONSULTING INC)" Date: Wed, 7 Aug 2024 07:03:27 +0000 Subject: [PATCH 3/4] change project template --- .../NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs index 464891554b7..32e044bb396 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs @@ -103,7 +103,7 @@ public async Task UpdateAllPackagesInPMC(ProjectTemplate projectTemplate, string [DataTestMethod] [DataRow(ProjectTemplate.MauiClassLibrary)] - [DataRow(ProjectTemplate.WebApplicationEmpty)] + [DataRow(ProjectTemplate.WebSiteEmpty)] [Timeout(DefaultTimeout)] public async Task InstallPackageInPMC(ProjectTemplate projectTemplate) { @@ -131,7 +131,7 @@ public async Task InstallPackageInPMC(ProjectTemplate projectTemplate) // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - if (projectTemplate.ToString().Equals("WebApplicationEmpty")) + if (projectTemplate.ToString().Equals("WebSiteEmpty")) { CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v100, Logger); } @@ -146,7 +146,7 @@ public async Task InstallPackageInPMC(ProjectTemplate projectTemplate) [DataTestMethod] [DataRow(ProjectTemplate.MauiClassLibrary)] - [DataRow(ProjectTemplate.WebApplicationEmpty)] + [DataRow(ProjectTemplate.WebSiteEmpty)] [Timeout(DefaultTimeout)] public async Task UpdatePackageInPMC(ProjectTemplate projectTemplate) { @@ -181,7 +181,7 @@ public async Task UpdatePackageInPMC(ProjectTemplate projectTemplate) // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - if (projectTemplate.ToString().Equals("WebApplicationEmpty")) + if (projectTemplate.ToString().Equals("WebSiteEmpty")) { CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v200, Logger); } @@ -196,7 +196,7 @@ public async Task UpdatePackageInPMC(ProjectTemplate projectTemplate) [DataTestMethod] [DataRow(ProjectTemplate.MauiClassLibrary)] - [DataRow(ProjectTemplate.WebApplicationEmpty)] + [DataRow(ProjectTemplate.WebSiteEmpty)] [Timeout(DefaultTimeout)] public async Task UninstallPackageInPMC(ProjectTemplate projectTemplate) { @@ -230,7 +230,7 @@ public async Task UninstallPackageInPMC(ProjectTemplate projectTemplate) // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - if (projectTemplate.ToString().Equals("WebApplicationEmpty")) + if (projectTemplate.ToString().Equals("WebSiteEmpty")) { CommonUtility.AssertPackageNotInPackagesConfig(VisualStudio, testContext.Project, PackageName, v100, Logger); } From 5e56f736b7dd294960db6502546342b099bf2e6f Mon Sep 17 00:00:00 2001 From: "Sue Su (BEYONDSOFT CONSULTING INC)" Date: Mon, 12 Aug 2024 09:07:56 +0000 Subject: [PATCH 4/4] add tests for website --- .../NuGetConsoleTestCase.cs | 156 ++++++++++++++---- 1 file changed, 123 insertions(+), 33 deletions(-) diff --git a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs index 32e044bb396..6e44e68ea7b 100644 --- a/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs +++ b/test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs @@ -102,10 +102,9 @@ public async Task UpdateAllPackagesInPMC(ProjectTemplate projectTemplate, string } [DataTestMethod] - [DataRow(ProjectTemplate.MauiClassLibrary)] - [DataRow(ProjectTemplate.WebSiteEmpty)] + [DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)] [Timeout(DefaultTimeout)] - public async Task InstallPackageInPMC(ProjectTemplate projectTemplate) + public async Task InstallPackageForPRInPMC(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) @@ -131,24 +130,16 @@ public async Task InstallPackageInPMC(ProjectTemplate projectTemplate) // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - if (projectTemplate.ToString().Equals("WebSiteEmpty")) - { - CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v100, Logger); - } - else - { - CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v100, Logger); - } + CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v100, Logger); Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); } } } [DataTestMethod] - [DataRow(ProjectTemplate.MauiClassLibrary)] - [DataRow(ProjectTemplate.WebSiteEmpty)] + [DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)] [Timeout(DefaultTimeout)] - public async Task UpdatePackageInPMC(ProjectTemplate projectTemplate) + public async Task UpdatePackageForPRInPMC(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) @@ -181,24 +172,16 @@ public async Task UpdatePackageInPMC(ProjectTemplate projectTemplate) // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - if (projectTemplate.ToString().Equals("WebSiteEmpty")) - { - CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v200, Logger); - } - else - { - CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v200, Logger); - } + CommonUtility.AssertPackageInAssetsFile(VisualStudio, testContext.Project, packageName, v200, Logger); Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); } } } [DataTestMethod] - [DataRow(ProjectTemplate.MauiClassLibrary)] - [DataRow(ProjectTemplate.WebSiteEmpty)] + [DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)] [Timeout(DefaultTimeout)] - public async Task UninstallPackageInPMC(ProjectTemplate projectTemplate) + public async Task UninstallPackageForPRInPMC(ProjectTemplate projectTemplate) { EnsureVisualStudioHost(); using (var simpleTestPathContext = new SimpleTestPathContext()) @@ -230,14 +213,115 @@ public async Task UninstallPackageInPMC(ProjectTemplate projectTemplate) // Assert VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); - if (projectTemplate.ToString().Equals("WebSiteEmpty")) - { - CommonUtility.AssertPackageNotInPackagesConfig(VisualStudio, testContext.Project, PackageName, v100, Logger); - } - else - { - CommonUtility.AssertPackageNotInAssetsFile(VisualStudio, testContext.Project, PackageName, v100, Logger); - } + CommonUtility.AssertPackageNotInAssetsFile(VisualStudio, testContext.Project, PackageName, v100, Logger); + Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); + } + } + } + + [DataTestMethod] + [DynamicData(nameof(GetWebSiteTemplates), DynamicDataSourceType.Method)] + [Timeout(DefaultTimeout)] + public async Task InstallPackageForPCInPMC(ProjectTemplate projectTemplate) + { + EnsureVisualStudioHost(); + using (var simpleTestPathContext = new SimpleTestPathContext()) + { + // Arrange + var packageName = "TestPackage"; + var v100 = "1.0.0"; + await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, packageName, v100); + + using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, simpleTestPathContext: simpleTestPathContext)) + { + VisualStudio.AssertNoErrors(); + var solutionService = VisualStudio.Get(); + testContext.SolutionService.Build(); + + // Act + var nugetConsole = GetConsole(testContext.Project); + + nugetConsole.InstallPackageFromPMC(packageName, v100); + testContext.SolutionService.Build(); + + // Assert + VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); + CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v100, Logger); + Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); + } + } + } + + [DataTestMethod] + [DynamicData(nameof(GetWebSiteTemplates), DynamicDataSourceType.Method)] + [Timeout(DefaultTimeout)] + public async Task UpdatePackageForPCInPMC(ProjectTemplate projectTemplate) + { + EnsureVisualStudioHost(); + using (var simpleTestPathContext = new SimpleTestPathContext()) + { + // Arrange + var packageName = "TestPackage"; + var v100 = "1.0.0"; + var v200 = "2.0.0"; + + await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, packageName, v100); + await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, packageName, v200); + + using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, simpleTestPathContext: simpleTestPathContext)) + { + VisualStudio.AssertNoErrors(); + var solutionService = VisualStudio.Get(); + testContext.SolutionService.Build(); + + // Act + var nugetConsole = GetConsole(testContext.Project); + + nugetConsole.InstallPackageFromPMC(packageName, v100); + testContext.SolutionService.Build(); + + nugetConsole.UpdatePackageFromPMC(packageName, v200); + testContext.SolutionService.Build(); + + // Assert + VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); + CommonUtility.AssertPackageInPackagesConfig(VisualStudio, testContext.Project, packageName, v200, Logger); + Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); + } + } + } + + [DataTestMethod] + [DynamicData(nameof(GetWebSiteTemplates), DynamicDataSourceType.Method)] + [Timeout(DefaultTimeout)] + public async Task UninstallPackageForPCInPMC(ProjectTemplate projectTemplate) + { + EnsureVisualStudioHost(); + using (var simpleTestPathContext = new SimpleTestPathContext()) + { + // Arrange + var PackageName = "TestPackage"; + var v100 = "1.0.0"; + + await CommonUtility.CreatePackageInSourceAsync(simpleTestPathContext.PackageSource, PackageName, v100); + + using (var testContext = new ApexTestContext(VisualStudio, projectTemplate, Logger, simpleTestPathContext: simpleTestPathContext)) + { + VisualStudio.AssertNoErrors(); + var solutionService = VisualStudio.Get(); + testContext.SolutionService.Build(); + + // Act + var nugetConsole = GetConsole(testContext.Project); + + nugetConsole.InstallPackageFromPMC(PackageName, v100); + testContext.SolutionService.Build(); + + nugetConsole.UninstallPackageFromPMC(PackageName); + testContext.SolutionService.Build(); + + // Assert + VisualStudio.AssertNuGetOutputDoesNotHaveErrors(); Assert.IsTrue(VisualStudio.HasNoErrorsInOutputWindows()); } } @@ -425,5 +509,11 @@ public static IEnumerable GetMauiTemplates() { yield return new object[] { ProjectTemplate.MauiClassLibrary }; } + + public static IEnumerable GetWebSiteTemplates() + { + yield return new object[] { ProjectTemplate.WebSiteEmpty }; + } + } }