Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not uninstall NuGet package from shared solution repository if it …

…is still referenced by another project.
  • Loading branch information...
commit 647c81b0494d9722e42657995fcf49c9d036e8fd 1 parent 9a7010a
@mrward mrward authored
View
1  src/AddIns/Misc/PackageManagement/Project/Src/Design/FakePackageRepository.cs
@@ -31,6 +31,7 @@ public void AddPackage(IPackage package)
public void RemovePackage(IPackage package)
{
IsRemovePackageCalled = true;
+ FakePackages.Remove(package as FakePackage);
}
public string Source { get; set; }
View
10 src/AddIns/Misc/PackageManagement/Project/Src/SharpDevelopPackageManager.cs
@@ -85,7 +85,15 @@ public override void InstallPackage(IPackage package, bool ignoreDependencies)
public override void UninstallPackage(IPackage package, bool forceRemove, bool removeDependencies)
{
ProjectManager.RemovePackageReference(package.Id, forceRemove, removeDependencies);
- base.UninstallPackage(package, forceRemove, removeDependencies);
+ if (!IsPackageReferencedByOtherProjects(package)) {
+ base.UninstallPackage(package, forceRemove, removeDependencies);
+ }
+ }
+
+ bool IsPackageReferencedByOtherProjects(IPackage package)
+ {
+ var sharedRepository = LocalRepository as ISharedPackageRepository;
+ return sharedRepository.IsReferenced(package.Id, package.Version);
}
public IEnumerable<PackageOperation> GetInstallPackageOperations(IPackage package, bool ignoreDependencies)
View
9 src/AddIns/Misc/PackageManagement/Test/Src/Helpers/FakeSharedPackageRepository.cs
@@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
+using System.Collections.Generic;
using System.Linq;
using ICSharpCode.PackageManagement.Design;
using NuGet;
@@ -12,9 +13,15 @@ public class FakeSharedPackageRepository : FakePackageRepository, ISharedPackage
{
public string PathPassedToRegisterRepository;
+ public List<string> PackageIdsReferences = new List<string>();
+ public string PackageIdPassedToIsReferenced;
+ public Version VersionPassedToIsReferenced;
+
public bool IsReferenced(string packageId, Version version)
{
- throw new NotImplementedException();
+ PackageIdPassedToIsReferenced = packageId;
+ VersionPassedToIsReferenced = version;
+ return PackageIdsReferences.Contains(packageId);
}
public void RegisterRepository(string path)
View
76 src/AddIns/Misc/PackageManagement/Test/Src/SharpDevelopPackageManagerTests.cs
@@ -168,7 +168,7 @@ FakePackage UninstallPackageAndRemoveDependencies()
PackageOperation CreateOneInstallPackageOperation()
{
- var package = CreateFakePackage();
+ FakePackage package = CreateFakePackage();
package.Id = "PackageToInstall";
return new PackageOperation(package, PackageAction.Install);
@@ -253,7 +253,7 @@ public void ProjectManager_InstanceCreated_PathResolverIsPackageManagerPathResol
public void InstallPackage_PackageInstancePassed_AddsReferenceToProject()
{
CreatePackageManager();
- var package = InstallPackage();
+ FakePackage package = InstallPackage();
Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
}
@@ -325,7 +325,7 @@ public void InstallPackage_PackageDependenciesIgnored_AddsReferenceToPackage()
{
CreatePackageManager();
CreateTestableProjectManager();
- var package = InstallPackageAndIgnoreDependencies();
+ FakePackage package = InstallPackageAndIgnoreDependencies();
Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
}
@@ -345,7 +345,7 @@ public void InstallPackage_PackageDependenciesNotIgnored_AddsReferenceToPackage(
{
CreatePackageManager();
CreateTestableProjectManager();
- var package = InstallPackageAndDoNotIgnoreDependencies();
+ FakePackage package = InstallPackageAndDoNotIgnoreDependencies();
Assert.AreEqual(package, testableProjectManager.PackagePassedToAddPackageReference);
}
@@ -355,7 +355,7 @@ public void UninstallPackage_PackageInProjectLocalRepository_RemovesReferenceFro
{
CreatePackageManager();
CreateTestableProjectManager();
- var package = UninstallPackage();
+ FakePackage package = UninstallPackage();
Assert.AreEqual(package.Id, testableProjectManager.PackagePassedToRemovePackageReference.Id);
}
@@ -423,13 +423,55 @@ public void UninstallPackage_ProjectLocalRepositoryHasPackage_PackageRemovedFrom
}
[Test]
+ public void UninstallPackage_PackageReferencedByNoProjects_PackageIsRemovedFromSharedSolutionRepository()
+ {
+ CreatePackageManager();
+ CreateTestableProjectManager();
+
+ FakePackage package = CreateFakePackage();
+ package.Id = "MyPackageId";
+
+ testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
+ fakeSolutionSharedRepository.FakePackages.Add(package);
+
+ packageManager.UninstallPackage(package);
+
+ bool containsPackage = fakeSolutionSharedRepository.FakePackages.Contains(package);
+
+ Assert.IsFalse(containsPackage);
+ }
+
+ [Test]
+ public void UninstallPackage_PackageReferencedByTwoProjects_PackageIsNotRemovedFromSharedSolutionRepository()
+ {
+ CreatePackageManager();
+ CreateTestableProjectManager();
+
+ FakePackage package = CreateFakePackage();
+ package.Id = "MyPackageId";
+ package.Version = new Version("1.4.5.2");
+
+ testableProjectManager.FakeLocalRepository.FakePackages.Add(package);
+ fakeSolutionSharedRepository.FakePackages.Add(package);
+ fakeSolutionSharedRepository.PackageIdsReferences.Add("MyPackageId");
+
+ packageManager.UninstallPackage(package);
+
+ bool containsPackage = fakeSolutionSharedRepository.FakePackages.Contains(package);
+
+ Assert.IsTrue(containsPackage);
+ Assert.AreEqual("MyPackageId", fakeSolutionSharedRepository.PackageIdPassedToIsReferenced);
+ Assert.AreEqual(package.Version, fakeSolutionSharedRepository.VersionPassedToIsReferenced);
+ }
+
+ [Test]
public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_PackageOperationsReturnedFromPackageOperationsResolverCreated()
{
CreatePackageManager();
var package = new FakePackage();
- var operations = GetInstallPackageOperations(package);
+ IEnumerable<PackageOperation> operations = GetInstallPackageOperations(package);
- var expectedOperations = fakePackageOperationResolverFactory.FakeInstallPackageOperationResolver.PackageOperations;
+ IEnumerable<PackageOperation> expectedOperations = fakePackageOperationResolverFactory.FakeInstallPackageOperationResolver.PackageOperations;
Assert.AreEqual(expectedOperations, operations);
}
@@ -441,8 +483,8 @@ public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_Pack
var package = new FakePackage();
GetInstallPackageOperations(package);
- var expectedRepository = packageManager.LocalRepository;
- var actualRepository = fakePackageOperationResolverFactory.LocalRepositoryPassedToCreateInstallPackageOperationsResolver;
+ IPackageRepository expectedRepository = packageManager.LocalRepository;
+ IPackageRepository actualRepository = fakePackageOperationResolverFactory.LocalRepositoryPassedToCreateInstallPackageOperationsResolver;
Assert.AreEqual(expectedRepository, actualRepository);
}
@@ -454,8 +496,8 @@ public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_Pack
var package = new FakePackage();
GetInstallPackageOperations(package);
- var expectedRepository = packageManager.SourceRepository;
- var actualRepository = fakePackageOperationResolverFactory.SourceRepositoryPassedToCreateInstallPackageOperationsResolver;
+ IPackageRepository expectedRepository = packageManager.SourceRepository;
+ IPackageRepository actualRepository = fakePackageOperationResolverFactory.SourceRepositoryPassedToCreateInstallPackageOperationsResolver;
Assert.AreEqual(expectedRepository, actualRepository);
}
@@ -467,7 +509,7 @@ public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_Depe
var package = new FakePackage();
GetInstallPackageOperations(package);
- var result = fakePackageOperationResolverFactory.IgnoreDependenciesPassedToCreateInstallPackageOperationResolver;
+ bool result = fakePackageOperationResolverFactory.IgnoreDependenciesPassedToCreateInstallPackageOperationResolver;
Assert.IsFalse(result);
}
@@ -479,8 +521,8 @@ public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_Pack
var package = new FakePackage();
GetInstallPackageOperations(package);
- var expectedLogger = packageManager.Logger;
- var actualLogger = fakePackageOperationResolverFactory.LoggerPassedToCreateInstallPackageOperationResolver;
+ ILogger expectedLogger = packageManager.Logger;
+ ILogger actualLogger = fakePackageOperationResolverFactory.LoggerPassedToCreateInstallPackageOperationResolver;
Assert.AreEqual(expectedLogger, actualLogger);
}
@@ -492,7 +534,7 @@ public void GetInstallPackageOperations_PackageOperationResolverFactoryUsed_Pack
var package = new FakePackage();
GetInstallPackageOperations(package);
- var actualPackage = fakePackageOperationResolverFactory
+ IPackage actualPackage = fakePackageOperationResolverFactory
.FakeInstallPackageOperationResolver
.PackagePassedToResolveOperations;
@@ -515,7 +557,7 @@ public void UpdatePackage_PackageInstanceAndNoPackageOperationsPassed_UpdatesRef
{
CreatePackageManager();
CreateTestableProjectManager();
- var package = UpdatePackageWithNoPackageOperations();
+ FakePackage package = UpdatePackageWithNoPackageOperations();
Assert.AreEqual(package, testableProjectManager.PackagePassedToUpdatePackageReference);
}
@@ -525,7 +567,7 @@ public void UpdatePackage_PackageInstanceAndNoPackageOperationsPassed_UpdatesDep
{
CreatePackageManager();
CreateTestableProjectManager();
- var package = UpdatePackageWithNoPackageOperations();
+ FakePackage package = UpdatePackageWithNoPackageOperations();
Assert.IsTrue(testableProjectManager.UpdateDependenciesPassedToUpdatePackageReference);
}
Please sign in to comment.
Something went wrong with that request. Please try again.