Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add different project templates to existing test cases. #5958

Merged
merged 4 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ 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)
public async Task InstallPackageToSDKBasedProjectFromUI(ProjectTemplate projectTemplate)
{
EnsureVisualStudioHost();

Expand All @@ -40,9 +44,13 @@ 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)
public async Task UpdatePackageToSDKBasedProjectFromUI(ProjectTemplate projectTemplate)
{
EnsureVisualStudioHost();

Expand Down Expand Up @@ -77,9 +85,13 @@ 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)
public async Task UninstallPackageFromSDKBasedProjectFromUI(ProjectTemplate projectTemplate)
{
EnsureVisualStudioHost();

Expand Down
168 changes: 144 additions & 24 deletions test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetConsoleTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.SetPackageFormatToPackageReference();

//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);

testContext.Project.Rebuild();
CommonUtility.WaitForFileExists(CacheFilePath);
// Assert
testContext.SolutionService.Build();
testContext.NuGetApexTestService.WaitForAutoRestore();
CommonUtility.WaitForFileExists(CacheFilePath);

testContext.Project.Rebuild();
CommonUtility.WaitForFileExists(CacheFilePath);

testContext.Project.Clean();
CommonUtility.WaitForFileNotExists(CacheFilePath);
testContext.Project.Clean();
CommonUtility.WaitForFileNotExists(CacheFilePath);
}
}
}

Expand Down Expand Up @@ -98,13 +104,13 @@ public async Task UpdateAllPackagesInPMC(ProjectTemplate projectTemplate, string
[DataTestMethod]
[DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)]
[Timeout(DefaultTimeout)]
public async Task InstallPackageForMauiProjectInPMC(ProjectTemplate projectTemplate)
public async Task InstallPackageForPRInPMC(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);
Expand Down Expand Up @@ -133,13 +139,13 @@ public async Task InstallPackageForMauiProjectInPMC(ProjectTemplate projectTempl
[DataTestMethod]
[DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)]
[Timeout(DefaultTimeout)]
public async Task UpdatePackageForMauiProjectInPMC(ProjectTemplate projectTemplate)
public async Task UpdatePackageForPRInPMC(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";

Expand Down Expand Up @@ -175,13 +181,13 @@ public async Task UpdatePackageForMauiProjectInPMC(ProjectTemplate projectTempla
[DataTestMethod]
[DynamicData(nameof(GetMauiTemplates), DynamicDataSourceType.Method)]
[Timeout(DefaultTimeout)]
public async Task UninstallPackageForMauiProjectInPMC(ProjectTemplate projectTemplate)
public async Task UninstallPackageForPRInPMC(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);
Expand Down Expand Up @@ -213,6 +219,114 @@ public async Task UninstallPackageForMauiProjectInPMC(ProjectTemplate projectTem
}
}

[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<SolutionService>();
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<SolutionService>();
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<SolutionService>();
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());
}
}
}

[DataTestMethod]
[DataRow(ProjectTemplate.WCFServiceApplication)]
[DataRow(ProjectTemplate.NetStandardClassLib)]
Expand Down Expand Up @@ -395,5 +509,11 @@ public static IEnumerable<object[]> GetMauiTemplates()
{
yield return new object[] { ProjectTemplate.MauiClassLibrary };
}

public static IEnumerable<object[]> GetWebSiteTemplates()
{
yield return new object[] { ProjectTemplate.WebSiteEmpty };
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public NuGetUITestCase()
{
}

[Ignore]
[Ignore("https://github.com/NuGet/Client.Engineering/issues/2829")]
[TestMethod]
[Timeout(DefaultTimeout)]
public void InstallPackageToWebSiteProjectFromUI()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public void DisableAutomaticInPackageRestoreSection()
Save();
}

/// <summary>
/// Set default package management format to PackageReference.
/// </summary>
public void SetPackageFormatToPackageReference()
{
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();
Expand Down