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 new test cases for Transitive Package into NuGet.Client-VSDaily Tests pipeline #6148

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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
135 changes: 135 additions & 0 deletions test/NuGet.Tests.Apex/NuGet.Tests.Apex.Daily/NuGetUITestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,141 @@ public async Task Uninstall_WithMultiplePackagesThatDependOnEachOther_PackageGoe
uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive);
}

[TestMethod]
[Timeout(DefaultTimeout)]
public async Task SearchTopLevelPackageInInstalledTabFromUI()
{
// Arrange
var transitivePackageName = "Contoso.B";
await CommonUtility.CreateDependenciesPackageInSourceAsync(_pathContext.PackageSource, TestPackageName, TestPackageVersionV1, transitivePackageName, TestPackageVersionV1);

NuGetApexTestService nugetTestService = GetNuGetTestService();

var solutionService = VisualStudio.Get<SolutionService>();
solutionService.CreateEmptySolution("TestSolution", _pathContext.SolutionRoot);
var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.NetCoreClassLib, "TestProject");
VisualStudio.ClearOutputWindow();
solutionService.SaveAll();

CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, Logger);

var uiwindow = nugetTestService.GetUIWindowfromProject(project);
uiwindow.InstallPackageFromUI(TestPackageName, TestPackageVersionV1);
solutionService.Build();

CommonUtility.AssertPackageReferenceExists(VisualStudio, project, TestPackageName, TestPackageVersionV1, Logger);
uiwindow.AssertPackageNameAndType(TestPackageName, NuGet.VisualStudio.PackageLevel.TopLevel);
uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive);
Comment on lines +523 to +524
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear on why this assertion is made both before the SearchPackageFromUI call and after the call. Is there a common bug where installing shows the TopLevel package but a following Search does not show that TopLevel package?

Should uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive); also be asserted after the Act?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review. 😊
First question: We call these assertions before SearchPackageFromUI to make sure that the package is installed successfully with the top-level package under the “top-level packages” node and the transitive packages under the “transitive packages” node.

The second question: the test case is search for packages under the “top-level packages” node, so after searching for top-level packages, only the top-level packages are displayed. So, we didn't add assert transitive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I believe also since the search is for an exact match package ID, there should be no transitive shown.

It may be worth considering a test where you search "Contoso" and find both a top-level Contoso.A and a transitive Contoso.C, or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion, we have added this test case SearchTopLevelAndTransitivePackagePublicFieldInInstalledTabFromUI to this PR, please help to review it, thanks again.


// Act
uiwindow.SearchPackageFromUI(TestPackageName);

// Assert
VisualStudio.AssertNoErrors();
uiwindow.AssertPackageNameAndType(TestPackageName, NuGet.VisualStudio.PackageLevel.TopLevel);
}

[TestMethod]
[Timeout(DefaultTimeout)]
public async Task SearchTopLevelAndTransitivePackagePublicFieldInInstalledTabFromUI()
{
// Arrange
var transitivePackageName = "Contoso.B";
await CommonUtility.CreateDependenciesPackageInSourceAsync(_pathContext.PackageSource, TestPackageName, TestPackageVersionV1, transitivePackageName, TestPackageVersionV1);

NuGetApexTestService nugetTestService = GetNuGetTestService();

var solutionService = VisualStudio.Get<SolutionService>();
solutionService.CreateEmptySolution("TestSolution", _pathContext.SolutionRoot);
var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.NetCoreClassLib, "TestProject");
VisualStudio.ClearOutputWindow();
solutionService.SaveAll();

CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, Logger);

var uiwindow = nugetTestService.GetUIWindowfromProject(project);
uiwindow.InstallPackageFromUI(TestPackageName, TestPackageVersionV1);
solutionService.Build();

CommonUtility.AssertPackageReferenceExists(VisualStudio, project, TestPackageName, TestPackageVersionV1, Logger);
uiwindow.AssertPackageNameAndType(TestPackageName, NuGet.VisualStudio.PackageLevel.TopLevel);
uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive);

// Act
uiwindow.SearchPackageFromUI("Contoso");

// Assert
VisualStudio.AssertNoErrors();
uiwindow.AssertPackageNameAndType(TestPackageName, NuGet.VisualStudio.PackageLevel.TopLevel);
uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive);
}

[TestMethod]
[Timeout(DefaultTimeout)]
public async Task InstallTopLevelPackageFromUI()
{
// Arrange
var transitivePackageName = "Contoso.B";
await CommonUtility.CreateDependenciesPackageInSourceAsync(_pathContext.PackageSource, TestPackageName, TestPackageVersionV1, transitivePackageName, TestPackageVersionV1);

NuGetApexTestService nugetTestService = GetNuGetTestService();

var solutionService = VisualStudio.Get<SolutionService>();
solutionService.CreateEmptySolution("TestSolution", _pathContext.SolutionRoot);
var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.NetCoreConsoleApp, "TestProject");
VisualStudio.ClearOutputWindow();
solutionService.SaveAll();

CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, Logger);

// Act
var uiwindow = nugetTestService.GetUIWindowfromProject(project);
uiwindow.InstallPackageFromUI(TestPackageName, TestPackageVersionV1);
solutionService.Build();

// Assert
VisualStudio.AssertNoErrors();
uiwindow.AssertPackageNameAndType(TestPackageName, NuGet.VisualStudio.PackageLevel.TopLevel);
uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive);
CommonUtility.AssertPackageReferenceExists(VisualStudio, project, TestPackageName, TestPackageVersionV1, Logger);
}

[TestMethod]
[Timeout(DefaultTimeout)]
public async Task UninstallTopLevelPackageFromUI()
{
// Arrange
var transitivePackageName = "Contoso.B";
await CommonUtility.CreateDependenciesPackageInSourceAsync(_pathContext.PackageSource, TestPackageName, TestPackageVersionV1, transitivePackageName, TestPackageVersionV1);

NuGetApexTestService nugetTestService = GetNuGetTestService();

var solutionService = VisualStudio.Get<SolutionService>();
solutionService.CreateEmptySolution("TestSolution", _pathContext.SolutionRoot);
var project = solutionService.AddProject(ProjectLanguage.CSharp, ProjectTemplate.NetCoreClassLib, "Testproject");
VisualStudio.ClearOutputWindow();
solutionService.SaveAll();

CommonUtility.OpenNuGetPackageManagerWithDte(VisualStudio, Logger);

var uiwindow = nugetTestService.GetUIWindowfromProject(project);
uiwindow.InstallPackageFromUI(TestPackageName, TestPackageVersionV1);
solutionService.Build();

CommonUtility.AssertPackageReferenceExists(VisualStudio, project, TestPackageName, TestPackageVersionV1, Logger);
uiwindow.AssertPackageNameAndType(TestPackageName, NuGet.VisualStudio.PackageLevel.TopLevel);
uiwindow.AssertPackageNameAndType(transitivePackageName, NuGet.VisualStudio.PackageLevel.Transitive);

// Act
uiwindow.UninstallPackageFromUI(TestPackageName);
solutionService.Build();

// Assert
VisualStudio.AssertNoErrors();
uiwindow.AssertPackageListIsNullOrEmpty();
CommonUtility.AssertPackageReferenceDoesNotExist(VisualStudio, project, TestPackageName, Logger);
}

[TestMethod]
[DataRow(ProjectTemplate.NetCoreConsoleApp)]
[DataRow(ProjectTemplate.ConsoleApplication)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public void AssertPackageNameAndType(string packageId, PackageLevel packageLevel
package.Id.Should().Be(packageId);
}

public void AssertPackageListIsNullOrEmpty()
{
_uiproject.GetPackageItemsOnInstalledTab().Should().BeNullOrEmpty("Package items list isn't null or empty on installed tab."); ;
}

public bool InstallPackageFromUI(string packageId, string version)
{
Stopwatch sw = Stopwatch.StartNew();
Expand Down