diff options
author | Matt Ward <matt.ward@microsoft.com> | 2019-08-20 12:02:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-20 12:02:42 +0300 |
commit | 23c57c3f5e50e54cbc32a5bf69590c2ed9947c7d (patch) | |
tree | 42ee1764cb0a44f49b5f6f29ab4d480442a77209 /main/src/addins/MonoDevelop.PackageManagement | |
parent | f6a774d63940b4aab440b06890fe8e4dff45cf03 (diff) | |
parent | 89d00a3ba4507a348f8cfcdbe8729d3cf5deb479 (diff) |
Merge pull request #8468 from mono/nuget-manage-packages-tests
[NuGet] Fix duplicate projects in select projects dialog
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement')
6 files changed, 615 insertions, 15 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageMetadataProvider.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageMetadataProvider.cs index 5255095b64..ded0bb3a02 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageMetadataProvider.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/FakePackageMetadataProvider.cs @@ -45,12 +45,15 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers public Task<IPackageSearchMetadata> GetLocalPackageMetadataAsync (PackageIdentity identity, bool includePrerelease, CancellationToken cancellationToken) { - throw new NotImplementedException (); + return GetPackageMetadataAsync (identity, includePrerelease, cancellationToken); } public Task<IPackageSearchMetadata> GetPackageMetadataAsync (PackageIdentity identity, bool includePrerelease, CancellationToken cancellationToken) { - throw new NotImplementedException (); + var metadata = new FakePackageSearchMetadata { + Identity = identity + }; + return Task.FromResult<IPackageSearchMetadata> (metadata); } public Task<IEnumerable<IPackageSearchMetadata>> GetPackageMetadataListAsync (string packageId, bool includePrerelease, bool includeUnlisted, CancellationToken cancellationToken) diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableManagePackagesViewModel.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableManagePackagesViewModel.cs index 44e8697994..883ed96493 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableManagePackagesViewModel.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests.Helpers/TestableManagePackagesViewModel.cs @@ -82,10 +82,11 @@ namespace MonoDevelop.PackageManagement.Tests.Helpers } public FakePackageFeed PackageFeed = new FakePackageFeed (); + public Func<PackageLoadContext, IPackageFeed> CreatePackageFeedAction = context => { return null; }; protected override IPackageFeed CreatePackageFeed (PackageLoadContext context) { - return PackageFeed; + return CreatePackageFeedAction (context) ?? PackageFeed; } protected override Task CreateReadPackagesTask () diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ManagePackagesViewModelTests.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ManagePackagesViewModelTests.cs index 0ee51e6171..e85a3d9a65 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ManagePackagesViewModelTests.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Tests/MonoDevelop.PackageManagement.Tests/ManagePackagesViewModelTests.cs @@ -29,10 +29,9 @@ using System.ComponentModel; using System.Linq; using System.Threading.Tasks; using MonoDevelop.PackageManagement.Tests.Helpers; +using NuGet.Common; using NuGet.Configuration; using NuGet.PackageManagement.UI; -using NuGet.Packaging; -using NuGet.Packaging.Core; using NuGet.ProjectManagement; using NuGet.Versioning; using NUnit.Framework; @@ -1401,7 +1400,6 @@ namespace MonoDevelop.PackageManagement.Tests public async Task CurrentVersion_DifferentPackageVersionInstalledInProjects_MultipleReturned () { CreateProject (); - CreateProject (); project.Name = "LibC"; var nugetProject = CreateNuGetProjectForProject (project); nugetProject.AddPackageReference ("Test", "0.1"); @@ -1434,7 +1432,6 @@ namespace MonoDevelop.PackageManagement.Tests public async Task CurrentVersion_SamePackageVersionInstalledInProjects_PackageVersionReturned () { CreateProject (); - CreateProject (); project.Name = "LibC"; var nugetProject = CreateNuGetProjectForProject (project); nugetProject.AddPackageReference ("Test", "0.1"); @@ -1466,7 +1463,6 @@ namespace MonoDevelop.PackageManagement.Tests public async Task CurrentVersion_TwoProjectsSameVersionOneProjectDifferentVersion_MultipleReturned () { CreateProject (); - CreateProject (); project.Name = "LibC"; var nugetProject = CreateNuGetProjectForProject (project); nugetProject.AddPackageReference ("Test", "0.1"); @@ -1495,5 +1491,594 @@ namespace MonoDevelop.PackageManagement.Tests Assert.AreEqual ("Multiple", package.GetCurrentPackageVersionText ()); Assert.AreEqual (expectedAdditionalText, package.GetCurrentPackageVersionAdditionalText ()); } + + [Test] + public async Task Consolidate_PackageInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("Test", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("Test", "0.2"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("Test", "0.3"); + viewModel.PageSelected = ManagePackagesPage.Consolidate; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels.Single (); + viewModel.SelectedPackage = package; + Assert.AreEqual ("Test", package.Id); + Assert.AreEqual ("0.3", package.Version.ToString ()); + + // Checked projects first. + var projectViewModel = viewModel.ProjectViewModels [0]; + Assert.AreEqual ("LibA", projectViewModel.ProjectName); + Assert.AreEqual ("0.1", projectViewModel.PackageVersion); + Assert.IsTrue (projectViewModel.IsChecked); + + projectViewModel = viewModel.ProjectViewModels [1]; + Assert.AreEqual ("LibB", projectViewModel.ProjectName); + Assert.AreEqual ("0.2", projectViewModel.PackageVersion); + Assert.IsTrue (projectViewModel.IsChecked); + + Assert.IsTrue (viewModel.CanConsolidate ()); + + // Check two install actions - one for each project. + var actions = viewModel.CreateConsolidatePackageActions (package).ToList (); + Assert.AreEqual (2, actions.Count); + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + } + + [Test] + public async Task Consolidate_PackageInNewProject_PackageActionCreatedForNewProject () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("Test", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("Test", "0.2"); + + var project3 = AddProjectToSolution ("LibC"); + nugetProject = CreateNuGetProjectForProject (project3); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("Test", "0.3"); + viewModel.PageSelected = ManagePackagesPage.Consolidate; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels.Single (); + viewModel.SelectedPackage = package; + Assert.AreEqual ("Test", package.Id); + Assert.AreEqual ("0.3", package.Version.ToString ()); + + // Checked projects first. + var projectViewModel = viewModel.ProjectViewModels [0]; + Assert.AreEqual ("LibA", projectViewModel.ProjectName); + Assert.AreEqual ("0.1", projectViewModel.PackageVersion); + Assert.IsTrue (projectViewModel.IsChecked); + + projectViewModel = viewModel.ProjectViewModels [1]; + Assert.AreEqual ("LibB", projectViewModel.ProjectName); + Assert.AreEqual ("0.2", projectViewModel.PackageVersion); + Assert.IsTrue (projectViewModel.IsChecked); + + projectViewModel = viewModel.ProjectViewModels [2]; + Assert.AreEqual ("LibC", projectViewModel.ProjectName); + Assert.IsFalse (projectViewModel.IsChecked); + + Assert.IsTrue (viewModel.CanConsolidate ()); + + // Check LibC and uncheck LibA + viewModel.ProjectViewModels [2].IsChecked = true; + viewModel.ProjectViewModels [0].IsChecked = false; + + // Check two install actions - one for each project. + var actions = viewModel.CreateConsolidatePackageActions (package).ToList (); + Assert.AreEqual (2, actions.Count); + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibC", action.Project.Name); + } + + [Test] + public async Task Consolidate_TwoPackageInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("TestA", "0.1"); + nugetProject.AddPackageReference ("TestB", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("TestA", "0.2"); + nugetProject.AddPackageReference ("TestB", "0.2"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("TestA", "0.3"); + viewModel.PackageFeed.AddPackage ("TestB", "0.4"); + viewModel.PageSelected = ManagePackagesPage.Consolidate; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels [0]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestA", package.Id); + Assert.AreEqual ("0.3", package.Version.ToString ()); + + package = viewModel.PackageViewModels [1]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestB", package.Id); + Assert.AreEqual ("0.4", package.Version.ToString ()); + + // Check install actions - two for each project + var actions = viewModel.CreateConsolidatePackageActions (viewModel.PackageViewModels); + Assert.AreEqual (4, actions.Count); + + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsFalse (action.LicensesMustBeAccepted); + + action = actions [2] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("0.4", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [3] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("0.4", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsFalse (action.LicensesMustBeAccepted); + } + + [Test] + public async Task Install_PackageInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + CreateNuGetProjectForProject (project); + + var project2 = AddProjectToSolution ("LibB"); + CreateNuGetProjectForProject (project2); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("Test", "0.1"); + viewModel.PageSelected = ManagePackagesPage.Browse; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels.Single (); + viewModel.SelectedPackage = package; + Assert.AreEqual ("Test", package.Id); + Assert.AreEqual ("0.1", package.Version.ToString ()); + + // Check two install actions - one for each project. + var selectedProjects = new [] { project, project2 }; + var actions = viewModel.CreatePackageActions (new [] { package }, selectedProjects).ToList (); + + Assert.AreEqual (2, actions.Count); + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.1", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.1", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsFalse (action.LicensesMustBeAccepted); + } + + [Test] + public async Task Install_PackagesInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + CreateNuGetProjectForProject (project); + + var project2 = AddProjectToSolution ("LibB"); + CreateNuGetProjectForProject (project2); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("TestA", "0.1"); + viewModel.PackageFeed.AddPackage ("TestB", "0.2"); + viewModel.PageSelected = ManagePackagesPage.Browse; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels [0]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestA", package.Id); + Assert.AreEqual ("0.1", package.Version.ToString ()); + + package = viewModel.PackageViewModels [1]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestB", package.Id); + Assert.AreEqual ("0.2", package.Version.ToString ()); + + // Check two install actions - one for each project. + var selectedProjects = new [] { project, project2 }; + var actions = viewModel.CreatePackageActions (viewModel.PackageViewModels, selectedProjects).ToList (); + + Assert.AreEqual (4, actions.Count); + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("0.1", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("0.1", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsFalse (action.LicensesMustBeAccepted); + + action = actions [2] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("0.2", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [3] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("0.2", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsFalse (action.LicensesMustBeAccepted); + } + + [Test] + public async Task Update_PackageInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("Test", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("Test", "0.1"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("Test", "0.2"); + viewModel.PageSelected = ManagePackagesPage.Updates; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels.Single (); + viewModel.SelectedPackage = package; + Assert.AreEqual ("Test", package.Id); + Assert.AreEqual ("0.2", package.Version.ToString ()); + + // Check two install actions - one for each project. + var selectedProjects = new [] { project, project2 }; + var actions = viewModel.CreatePackageActions (new [] { package }, selectedProjects).ToList (); + + Assert.AreEqual (2, actions.Count); + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.2", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("0.2", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsFalse (action.LicensesMustBeAccepted); + } + + [Test] + public async Task Update_PackagesInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("TestA", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("TestB", "0.1"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("TestA", "0.2"); + viewModel.PackageFeed.AddPackage ("TestB", "0.3"); + viewModel.PageSelected = ManagePackagesPage.Updates; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels [0]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestA", package.Id); + Assert.AreEqual ("0.2", package.Version.ToString ()); + + package = viewModel.PackageViewModels [1]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestB", package.Id); + Assert.AreEqual ("0.3", package.Version.ToString ()); + + // Check two install actions - one for each project. + var selectedProjects = new [] { project, project2 }; + var actions = viewModel.CreatePackageActions (viewModel.PackageViewModels, selectedProjects).ToList (); + + Assert.AreEqual (2, actions.Count); + var action = actions [0] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("0.2", action.Version.ToString ()); + Assert.AreEqual ("LibA", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + + action = actions [1] as InstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Install, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("0.3", action.Version.ToString ()); + Assert.AreEqual ("LibB", action.Project.Name); + Assert.IsTrue (action.LicensesMustBeAccepted); + } + + [Test] + public async Task Uninstall_PackageInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("Test", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("Test", "0.2"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + var metadataProvider = new FakePackageMetadataProvider (); + viewModel.CreatePackageFeedAction = context => { + return new InstalledPackageFeed (context, metadataProvider, new NullLogger ()); + }; + metadataProvider.AddPackageMetadata ("Test", "0.2"); + viewModel.PageSelected = ManagePackagesPage.Installed; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels.Single (); + viewModel.SelectedPackage = package; + Assert.AreEqual ("Test", package.Id); + Assert.AreEqual ("0.2", package.Version.ToString ()); + + // Check two uninstall actions - one for each project. + var selectedProjects = new [] { project, project2 }; + var actions = viewModel.CreatePackageActions (new [] { package }, selectedProjects).ToList (); + + Assert.AreEqual (2, actions.Count); + var action = actions [0] as UninstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Uninstall, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("LibA", action.Project.Name); + + action = actions [1] as UninstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Uninstall, action.ActionType); + Assert.AreEqual ("Test", action.PackageId); + Assert.AreEqual ("LibB", action.Project.Name); + } + + [Test] + public async Task Uninstall_PackagesInTwoProjects_PackageActionsCreatedForBothProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("TestA", "0.1"); + nugetProject.AddPackageReference ("TestB", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("TestA", "0.1"); + nugetProject.AddPackageReference ("TestB", "0.2"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + var metadataProvider = new FakePackageMetadataProvider (); + viewModel.CreatePackageFeedAction = context => { + return new InstalledPackageFeed (context, metadataProvider, new NullLogger ()); + }; + metadataProvider.AddPackageMetadata ("TestA", "0.1"); + metadataProvider.AddPackageMetadata ("TestB", "0.2"); + viewModel.PageSelected = ManagePackagesPage.Installed; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + var package = viewModel.PackageViewModels [0]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestA", package.Id); + Assert.AreEqual ("0.1", package.Version.ToString ()); + + package = viewModel.PackageViewModels [1]; + viewModel.SelectedPackage = package; + package.IsChecked = true; + Assert.AreEqual ("TestB", package.Id); + Assert.AreEqual ("0.2", package.Version.ToString ()); + + // Check four uninstall actions - one for each package and project. + var selectedProjects = new [] { project, project2 }; + var actions = viewModel.CreatePackageActions (viewModel.PackageViewModels, selectedProjects).ToList (); + + Assert.AreEqual (4, actions.Count); + var action = actions [0] as UninstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Uninstall, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("LibA", action.Project.Name); + + action = actions [1] as UninstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Uninstall, action.ActionType); + Assert.AreEqual ("TestA", action.PackageId); + Assert.AreEqual ("LibB", action.Project.Name); + + action = actions [2] as UninstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Uninstall, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("LibA", action.Project.Name); + + action = actions [3] as UninstallNuGetPackageAction; + Assert.AreEqual (PackageActionType.Uninstall, action.ActionType); + Assert.AreEqual ("TestB", action.PackageId); + Assert.AreEqual ("LibB", action.Project.Name); + } + + [Test] + public async Task GetDotNetProjectsToSelect_ThreeProjectsPackageInstalledInTwoProjects_ProjectNotDuplicatedInSelectedProjects () + { + CreateProject (); + project.Name = "LibA"; + var nugetProject = CreateNuGetProjectForProject (project); + nugetProject.AddPackageReference ("TestA", "0.1"); + + var project2 = AddProjectToSolution ("LibB"); + nugetProject = CreateNuGetProjectForProject (project2); + nugetProject.AddPackageReference ("TestB", "0.2"); + + var project3 = AddProjectToSolution ("LibC"); + nugetProject = CreateNuGetProjectForProject (project3); + nugetProject.AddPackageReference ("TestA", "0.2"); + nugetProject.AddPackageReference ("TestB", "0.2"); + + AddOnePackageSourceToRegisteredSources (); + CreateViewModelForSolution (); + viewModel.PackageFeed.AddPackage ("TestA", "0.2"); + viewModel.PackageFeed.AddPackage ("TestB", "0.5"); + viewModel.PageSelected = ManagePackagesPage.Browse; + + viewModel.ReadPackages (); + await viewModel.ReadPackagesTask; + + viewModel.SelectedPackage = viewModel.PackageViewModels [0]; + + var selectedProjects = viewModel.GetDotNetProjectsToSelect (new [] { "TestA" }).ToList (); + Assert.AreEqual (3, selectedProjects.Count); + Assert.AreEqual (project, selectedProjects [0]); + Assert.AreEqual (project2, selectedProjects [1]); + Assert.AreEqual (project3, selectedProjects [2]); + + viewModel.PageSelected = ManagePackagesPage.Installed; + + // LibB not included - package not installed in this project so cannot be removed. + selectedProjects = viewModel.GetDotNetProjectsToSelect (new [] { "TestA" }).ToList (); + Assert.AreEqual (2, selectedProjects.Count); + Assert.AreEqual (project, selectedProjects [0]); + Assert.AreEqual (project3, selectedProjects [1]); + + viewModel.PageSelected = ManagePackagesPage.Updates; + + // LibB not included - package not installed in this project so cannot be removed. + selectedProjects = viewModel.GetDotNetProjectsToSelect (new [] { "TestA" }).ToList (); + Assert.AreEqual (2, selectedProjects.Count); + Assert.AreEqual (project, selectedProjects [0]); + Assert.AreEqual (project3, selectedProjects [1]); + + // Check two packages. + viewModel.PageSelected = ManagePackagesPage.Browse; + viewModel.PackageViewModels [0].IsChecked = true; + viewModel.PackageViewModels [1].IsChecked = true; + + var packageIds = viewModel.CheckedPackageViewModels.Select (vm => vm.Id).ToList (); + + selectedProjects = viewModel.GetDotNetProjectsToSelect (packageIds).ToList (); + Assert.AreEqual (3, selectedProjects.Count); + Assert.AreEqual (project, selectedProjects [0]); + Assert.AreEqual (project2, selectedProjects [1]); + Assert.AreEqual (project3, selectedProjects [2]); + + viewModel.PageSelected = ManagePackagesPage.Installed; + viewModel.PackageViewModels [0].IsChecked = true; + viewModel.PackageViewModels [1].IsChecked = true; + + // All projects included - packages are installed in multiple projects. + selectedProjects = viewModel.GetDotNetProjectsToSelect (packageIds).ToList (); + Assert.AreEqual (3, selectedProjects.Count); + Assert.AreEqual (project, selectedProjects [0]); + Assert.AreEqual (project2, selectedProjects [1]); + Assert.AreEqual (project3, selectedProjects [2]); + + viewModel.PageSelected = ManagePackagesPage.Updates; + viewModel.PackageViewModels [0].IsChecked = true; + viewModel.PackageViewModels [1].IsChecked = true; + + // All projects included - packages are installed in multiple projects. + selectedProjects = viewModel.GetDotNetProjectsToSelect (packageIds).ToList (); + Assert.AreEqual (3, selectedProjects.Count); + Assert.AreEqual (project, selectedProjects [0]); + Assert.AreEqual (project2, selectedProjects [1]); + Assert.AreEqual (project3, selectedProjects [2]); + } } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesProjectInfo.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesProjectInfo.cs index 91f32d76b9..c6927f0771 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesProjectInfo.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesProjectInfo.cs @@ -56,5 +56,17 @@ namespace MonoDevelop.PackageManagement return string.Compare (Project.Name, other.Project.Name, StringComparison.CurrentCulture); } + + public bool HasAnyPackage (IEnumerable<string> packageIds) + { + foreach (PackageIdentity package in Packages) { + foreach (string packageId in packageIds) { + if (StringComparer.OrdinalIgnoreCase.Equals (package.Id, packageId)) { + return true; + } + } + } + return false; + } } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesViewModel.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesViewModel.cs index 7adcbbb4fa..217ceba987 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesViewModel.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/ManagePackagesViewModel.cs @@ -857,13 +857,8 @@ namespace MonoDevelop.PackageManagement if (projectInfo.Project != project) continue; - foreach (PackageIdentity package in projectInfo.Packages) { - foreach (string packageId in packageIds) { - if (StringComparer.OrdinalIgnoreCase.Equals (package.Id, packageId)) { - yield return project; - } - } - } + if (projectInfo.HasAnyPackage (packageIds)) + yield return project; } } } diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UninstallNuGetPackageAction.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UninstallNuGetPackageAction.cs index 301ece69d8..619a5e88d4 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UninstallNuGetPackageAction.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement/UninstallNuGetPackageAction.cs @@ -81,6 +81,10 @@ namespace MonoDevelop.PackageManagement public PackageActionType ActionType {
get { return PackageActionType.Uninstall; }
+ } + + internal IDotNetProject Project { + get { return dotNetProject; } }
public void Execute ()
|