Browse Source
Update-Package does not currently support reinstalling across multiple projects or reinstalling all packages for a single project.pull/701/head
13 changed files with 478 additions and 9 deletions
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Design |
||||
{ |
||||
public class FakeReinstallPackageAction : ReinstallPackageAction |
||||
{ |
||||
public bool IsExecuted; |
||||
|
||||
public FakePackageManagementProject FakeProject; |
||||
|
||||
public FakeReinstallPackageAction() |
||||
: this(new FakePackageManagementProject()) |
||||
{ |
||||
} |
||||
|
||||
public FakeReinstallPackageAction(IPackageManagementProject project) |
||||
: base(project, null) |
||||
{ |
||||
FakeProject = project as FakePackageManagementProject; |
||||
} |
||||
|
||||
protected override void ExecuteCore() |
||||
{ |
||||
IsExecuted = true; |
||||
} |
||||
|
||||
protected override void BeforeExecute() |
||||
{ |
||||
} |
||||
|
||||
protected override RunPackageScriptsAction CreateRunPackageScriptsAction( |
||||
IPackageScriptRunner scriptRunner, |
||||
IPackageManagementProject project) |
||||
{ |
||||
return new RunPackageScriptsAction( |
||||
project, |
||||
scriptRunner, |
||||
new PackageScriptFactory(), |
||||
new NullGlobalMSBuildProjectCollection()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// ReinstallPackageAction.cs
|
||||
//
|
||||
// Author:
|
||||
// Matt Ward <matt.ward@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ReinstallPackageAction : ProcessPackageAction |
||||
{ |
||||
public ReinstallPackageAction( |
||||
IPackageManagementProject project, |
||||
IPackageManagementEvents packageManagementEvents) |
||||
: base(project, packageManagementEvents) |
||||
{ |
||||
} |
||||
|
||||
public bool UpdateDependencies { get; set; } |
||||
|
||||
protected override void ExecuteCore() |
||||
{ |
||||
UninstallPackage(); |
||||
InstallPackage(); |
||||
} |
||||
|
||||
void UninstallPackage() |
||||
{ |
||||
UninstallPackageAction action = Project.CreateUninstallPackageAction(); |
||||
action.Package = Package; |
||||
action.ForceRemove = true; |
||||
action.RemoveDependencies = UpdateDependencies; |
||||
action.Execute(); |
||||
} |
||||
|
||||
void InstallPackage() |
||||
{ |
||||
InstallPackageAction action = Project.CreateInstallPackageAction(); |
||||
action.Package = Package; |
||||
action.IgnoreDependencies = !UpdateDependencies; |
||||
action.AllowPrereleaseVersions = !Package.IsReleaseVersion(); |
||||
action.Execute(); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,148 @@
@@ -0,0 +1,148 @@
|
||||
//
|
||||
// ReinstallPackageActionTests.cs
|
||||
//
|
||||
// Author:
|
||||
// Matt Ward <matt.ward@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2014 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class ReinstallPackageActionTests |
||||
{ |
||||
ReinstallPackageAction action; |
||||
PackageManagementEvents packageManagementEvents; |
||||
FakePackageManagementProject project; |
||||
|
||||
void CreateAction(string packageId = "MyPackage", string packageVersion = "1.2.3.4") |
||||
{ |
||||
project = new FakePackageManagementProject(); |
||||
project.AddFakeInstallOperation(); |
||||
|
||||
packageManagementEvents = new PackageManagementEvents(); |
||||
|
||||
action = new ReinstallPackageAction(project, packageManagementEvents); |
||||
action.PackageId = packageId; |
||||
action.PackageVersion = new SemanticVersion(packageVersion); |
||||
} |
||||
|
||||
FakePackage AddPackageToSourceRepository(string packageId, string packageVersion) |
||||
{ |
||||
return project.FakeSourceRepository.AddFakePackageWithVersion(packageId, packageVersion); |
||||
} |
||||
|
||||
[Test] |
||||
public void Execute_PackageExistsInSourceRepository_PackageIsUninstalled() |
||||
{ |
||||
CreateAction("MyPackage", "1.2.3.4"); |
||||
FakePackage package = AddPackageToSourceRepository("MyPackage", "1.2.3.4"); |
||||
|
||||
action.Execute(); |
||||
|
||||
Assert.IsTrue(project.FakeUninstallPackageAction.IsExecuted); |
||||
Assert.AreEqual(package, project.FakeUninstallPackageAction.Package); |
||||
} |
||||
|
||||
[Test] |
||||
public void Execute_PackageExistsInSourceRepository_PackageIsInstalled() |
||||
{ |
||||
CreateAction("MyPackage", "1.2.3.4"); |
||||
FakePackage package = AddPackageToSourceRepository("MyPackage", "1.2.3.4"); |
||||
|
||||
action.Execute(); |
||||
|
||||
Assert.IsTrue(project.LastInstallPackageCreated.IsExecuteCalled); |
||||
Assert.AreEqual(package, project.LastInstallPackageCreated.Package); |
||||
} |
||||
|
||||
[Test] |
||||
public void Execute_PackageExistsInSourceRepository_PackageIsForcefullyRemovedSoItDoesNotFailIfOtherPackagesDependOnIt() |
||||
{ |
||||
CreateAction("MyPackage", "1.2.3.4"); |
||||
AddPackageToSourceRepository("MyPackage", "1.2.3.4"); |
||||
|
||||
action.Execute(); |
||||
|
||||
Assert.IsTrue(project.FakeUninstallPackageAction.ForceRemove); |
||||
} |
||||
|
||||
[Test] |
||||
public void Execute_UpdateDependenciesIsFalse_PackageInstalledWithoutUpdatingDependencies() |
||||
{ |
||||
CreateAction("MyPackage", "1.2.3.4"); |
||||
AddPackageToSourceRepository("MyPackage", "1.2.3.4"); |
||||
action.UpdateDependencies = false; |
||||
|
||||
action.Execute(); |
||||
|
||||
Assert.IsTrue(project.LastInstallPackageCreated.IsExecuteCalled); |
||||
Assert.IsTrue(project.LastInstallPackageCreated.IgnoreDependencies); |
||||
Assert.IsFalse(project.FakeUninstallPackageAction.RemoveDependencies); |
||||
} |
||||
|
||||
[Test] |
||||
public void Execute_UpdateDependenciesIsTrue_PackageInstalledWithoutIgnoringDependencies() |
||||
{ |
||||
CreateAction("MyPackage", "1.2.3.4"); |
||||
AddPackageToSourceRepository("MyPackage", "1.2.3.4"); |
||||
action.UpdateDependencies = true; |
||||
|
||||
action.Execute(); |
||||
|
||||
Assert.IsTrue(project.LastInstallPackageCreated.IsExecuteCalled); |
||||
Assert.IsFalse(project.LastInstallPackageCreated.IgnoreDependencies); |
||||
Assert.IsTrue(project.FakeUninstallPackageAction.RemoveDependencies); |
||||
Assert.IsFalse(project.LastInstallPackageCreated.AllowPrereleaseVersions); |
||||
} |
||||
|
||||
[Test] |
||||
public void Execute_PackageIsPrerelease_PackageInstalledAllowingPrereleases() |
||||
{ |
||||
CreateAction("MyPackage", "1.2.3-alpha1"); |
||||
AddPackageToSourceRepository("MyPackage", "1.2.3-alpha1"); |
||||
action.UpdateDependencies = true; |
||||
|
||||
action.Execute(); |
||||
|
||||
Assert.IsTrue(project.LastInstallPackageCreated.IsExecuteCalled); |
||||
Assert.IsTrue(project.LastInstallPackageCreated.AllowPrereleaseVersions); |
||||
} |
||||
|
||||
// [Test]
|
||||
// public void Execute_PackageExistsInSourceRepository_PackageIsInstalledWithoutOpeningReadmeTxt ()
|
||||
// {
|
||||
// CreateAction("MyPackage", "1.2.3.4");
|
||||
// FakePackage package = AddPackageToSourceRepository("MyPackage", "1.2.3.4");
|
||||
//
|
||||
// action.Execute();
|
||||
//
|
||||
// Assert.IsTrue(project.LastInstallPackageCreated.IsExecuteCalled);
|
||||
// Assert.IsFalse(project.LastInstallPackageCreated.OpenReadMeText);
|
||||
// }
|
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue