Browse Source
install-package jquery -FileConflictAction Overwrite update-package jquery -FileConflictAction Ignorepull/44/head
17 changed files with 329 additions and 8 deletions
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class ConsoleHostFileConflictResolver : IConsoleHostFileConflictResolver |
||||
{ |
||||
IPackageManagementEvents packageEvents; |
||||
FileConflictResolution conflictResolution; |
||||
|
||||
public ConsoleHostFileConflictResolver( |
||||
IPackageManagementEvents packageEvents, |
||||
FileConflictAction fileConflictAction) |
||||
{ |
||||
this.packageEvents = packageEvents; |
||||
|
||||
conflictResolution = GetFileConflictResolution(fileConflictAction); |
||||
packageEvents.ResolveFileConflict += ResolveFileConflict; |
||||
} |
||||
|
||||
void ResolveFileConflict(object sender, ResolveFileConflictEventArgs e) |
||||
{ |
||||
e.Resolution = conflictResolution; |
||||
} |
||||
|
||||
FileConflictResolution GetFileConflictResolution(FileConflictAction fileConflictAction) |
||||
{ |
||||
switch (fileConflictAction) { |
||||
case FileConflictAction.Overwrite: |
||||
return FileConflictResolution.Overwrite; |
||||
default: |
||||
return FileConflictResolution.Ignore; |
||||
} |
||||
} |
||||
|
||||
public void Dispose() |
||||
{ |
||||
packageEvents.ResolveFileConflict -= ResolveFileConflict; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public enum FileConflictAction |
||||
{ |
||||
None, |
||||
Overwrite, |
||||
Ignore |
||||
} |
||||
} |
||||
@ -0,0 +1,11 @@
@@ -0,0 +1,11 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public interface IConsoleHostFileConflictResolver : IDisposable |
||||
{ |
||||
} |
||||
} |
||||
@ -0,0 +1,70 @@
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PackageManagement.Scripting.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class ConsoleHostFileConflictResolverTests |
||||
{ |
||||
ConsoleHostFileConflictResolver resolver; |
||||
PackageManagementEvents packageEvents; |
||||
|
||||
void CreateResolver(FileConflictAction action) |
||||
{ |
||||
packageEvents = new PackageManagementEvents(); |
||||
resolver = new ConsoleHostFileConflictResolver(packageEvents, action); |
||||
} |
||||
|
||||
FileConflictResolution ResolveConflict() |
||||
{ |
||||
return packageEvents.OnResolveFileConflict(String.Empty); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveConflict_FileConflictActionIsNone_ResolutionIsIgnore() |
||||
{ |
||||
CreateResolver(FileConflictAction.None); |
||||
|
||||
FileConflictResolution resolution = ResolveConflict(); |
||||
|
||||
Assert.AreEqual(FileConflictResolution.Ignore, resolution); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveConflict_FileConflictActionIsIgnore_ResolutionIsIgnore() |
||||
{ |
||||
CreateResolver(FileConflictAction.Ignore); |
||||
|
||||
FileConflictResolution resolution = ResolveConflict(); |
||||
|
||||
Assert.AreEqual(FileConflictResolution.Ignore, resolution); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveConflict_FileConflictActionIsOverwrite_ResolutionIsOverwrite() |
||||
{ |
||||
CreateResolver(FileConflictAction.Overwrite); |
||||
|
||||
FileConflictResolution resolution = ResolveConflict(); |
||||
|
||||
Assert.AreEqual(FileConflictResolution.Overwrite, resolution); |
||||
} |
||||
|
||||
[Test] |
||||
public void ResolveConflict_FileConflictActionIsOverwriteButResolverIsDisposed_ResolutionIsNotChangedByResolver() |
||||
{ |
||||
CreateResolver(FileConflictAction.Overwrite); |
||||
resolver.Dispose(); |
||||
|
||||
FileConflictResolution resolution = ResolveConflict(); |
||||
|
||||
Assert.AreEqual(FileConflictResolution.IgnoreAll, resolution); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue