49 changed files with 1201 additions and 694 deletions
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
// 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 System.Management.Automation; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Cmdlets |
||||
{ |
||||
[Cmdlet(VerbsLifecycle.Invoke, "ProcessPackageActions", DefaultParameterSetName = ParameterAttribute.AllParameterSets)] |
||||
public class InvokeProcessPackageActionsCmdlet : PackageManagementCmdlet |
||||
{ |
||||
PackageActionsToRun actionsToRun; |
||||
|
||||
public InvokeProcessPackageActionsCmdlet() |
||||
: this( |
||||
PackageManagementServices.PackageActionsToRun, |
||||
PackageManagementServices.ConsoleHost, |
||||
null) |
||||
{ |
||||
} |
||||
|
||||
public InvokeProcessPackageActionsCmdlet( |
||||
PackageActionsToRun actionsToRun, |
||||
IPackageManagementConsoleHost consoleHost, |
||||
ICmdletTerminatingError terminatingError) |
||||
: base(consoleHost, terminatingError) |
||||
{ |
||||
this.actionsToRun = actionsToRun; |
||||
} |
||||
|
||||
protected override void ProcessRecord() |
||||
{ |
||||
ExecutePackageActions(); |
||||
} |
||||
|
||||
void ExecutePackageActions() |
||||
{ |
||||
ProcessPackageAction action = null; |
||||
while (GetNextAction(out action)) { |
||||
Execute(action); |
||||
} |
||||
} |
||||
|
||||
bool GetNextAction(out ProcessPackageAction action) |
||||
{ |
||||
return actionsToRun.GetNextAction(out action); |
||||
} |
||||
|
||||
void Execute(ProcessPackageAction action) |
||||
{ |
||||
action.PackageScriptRunner = this; |
||||
action.Execute(); |
||||
} |
||||
} |
||||
} |
@ -1,51 +0,0 @@
@@ -1,51 +0,0 @@
|
||||
// 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 System.Management.Automation; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Cmdlets |
||||
{ |
||||
[Cmdlet(VerbsLifecycle.Invoke, "RunPackageScripts", DefaultParameterSetName = ParameterAttribute.AllParameterSets)] |
||||
public class InvokeRunPackageScriptsCmdlet : PackageManagementCmdlet |
||||
{ |
||||
PackageScriptsToRun scriptsToBeRun; |
||||
|
||||
public InvokeRunPackageScriptsCmdlet() |
||||
: this( |
||||
PackageManagementServices.PackageScriptsToRun, |
||||
PackageManagementServices.ConsoleHost, |
||||
null) |
||||
{ |
||||
} |
||||
|
||||
public InvokeRunPackageScriptsCmdlet( |
||||
PackageScriptsToRun scriptsToBeRun, |
||||
IPackageManagementConsoleHost consoleHost, |
||||
ICmdletTerminatingError terminatingError) |
||||
: base(consoleHost, terminatingError) |
||||
{ |
||||
this.scriptsToBeRun = scriptsToBeRun; |
||||
} |
||||
|
||||
protected override void ProcessRecord() |
||||
{ |
||||
RunPackageScripts(); |
||||
} |
||||
|
||||
void RunPackageScripts() |
||||
{ |
||||
IPackageScript script = null; |
||||
while (GetNextScript(out script)) { |
||||
Run(script); |
||||
} |
||||
} |
||||
|
||||
bool GetNextScript(out IPackageScript script) |
||||
{ |
||||
script = scriptsToBeRun.GetNextScript(); |
||||
return script != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
// 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.Design; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Cmdlets.Tests.Helpers; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Cmdlets.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class InvokeProcessPackageActionsCmdletTests |
||||
{ |
||||
TestableInvokeProcessPackageActionsCmdlet cmdlet; |
||||
PackageActionsToRun actionsToRun; |
||||
|
||||
void CreateCmdlet() |
||||
{ |
||||
cmdlet = new TestableInvokeProcessPackageActionsCmdlet(); |
||||
actionsToRun = cmdlet.ActionsToRun; |
||||
} |
||||
|
||||
void RunCmdlet() |
||||
{ |
||||
cmdlet.CallProcessRecord(); |
||||
} |
||||
|
||||
FakeInstallPackageAction AddInstallAction() |
||||
{ |
||||
var project = new FakePackageManagementProject(); |
||||
var action = new FakeInstallPackageAction(project); |
||||
actionsToRun.AddAction(action); |
||||
return action; |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_OnePackageActionToRun_PackageActionIsRun() |
||||
{ |
||||
CreateCmdlet(); |
||||
FakeInstallPackageAction action = AddInstallAction(); |
||||
RunCmdlet(); |
||||
|
||||
bool run = action.IsExecuteCalled; |
||||
|
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_TwoPackageActionsToRun_SecondPackageActionIsRun() |
||||
{ |
||||
CreateCmdlet(); |
||||
AddInstallAction(); |
||||
FakeInstallPackageAction action = AddInstallAction(); |
||||
RunCmdlet(); |
||||
|
||||
bool run = action.IsExecuteCalled; |
||||
|
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_OnePackageActionToRun_PackageActionScriptRunnerIsCmdlet() |
||||
{ |
||||
CreateCmdlet(); |
||||
FakeInstallPackageAction action = AddInstallAction(); |
||||
RunCmdlet(); |
||||
|
||||
IPackageScriptRunner runner = action.PackageScriptRunner; |
||||
|
||||
Assert.AreEqual(cmdlet, runner); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_TwoPackageActionsToRun_TwoPackageActionScriptRunnerIsCmdlet() |
||||
{ |
||||
CreateCmdlet(); |
||||
AddInstallAction(); |
||||
FakeInstallPackageAction action = AddInstallAction(); |
||||
RunCmdlet(); |
||||
|
||||
IPackageScriptRunner runner = action.PackageScriptRunner; |
||||
|
||||
Assert.AreEqual(cmdlet, runner); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_NoPackageActionsToRun_NullReferenceExceptionIsNotThrown() |
||||
{ |
||||
CreateCmdlet(); |
||||
Assert.DoesNotThrow(() => RunCmdlet()); |
||||
} |
||||
} |
||||
} |
@ -1,95 +0,0 @@
@@ -1,95 +0,0 @@
|
||||
// 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.Scripting; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Cmdlets.Tests.Helpers; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Cmdlets.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class InvokeRunPackageScriptsCmdletTests |
||||
{ |
||||
TestableInvokeRunPackageScriptsCmdlet cmdlet; |
||||
FakeCmdletTerminatingError fakeTerminatingError; |
||||
PackageScriptsToRun scriptsToRun; |
||||
|
||||
void CreateCmdlet() |
||||
{ |
||||
cmdlet = new TestableInvokeRunPackageScriptsCmdlet(); |
||||
fakeTerminatingError = cmdlet.FakeCmdletTerminatingError; |
||||
scriptsToRun = cmdlet.ScriptsToBeRun; |
||||
} |
||||
|
||||
void RunCmdlet() |
||||
{ |
||||
cmdlet.CallProcessRecord(); |
||||
} |
||||
|
||||
FakePackageScript AddScript() |
||||
{ |
||||
var script = new FakePackageScript(); |
||||
scriptsToRun.AddScript(script); |
||||
return script; |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_OnePackageScriptToRun_PackageScriptIsRun() |
||||
{ |
||||
CreateCmdlet(); |
||||
FakePackageScript script = AddScript(); |
||||
RunCmdlet(); |
||||
|
||||
bool run = script.IsRun; |
||||
|
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_TwoPackageScriptsToRun_SecondPackageScriptIsRun() |
||||
{ |
||||
CreateCmdlet(); |
||||
AddScript(); |
||||
FakePackageScript script = AddScript(); |
||||
RunCmdlet(); |
||||
|
||||
bool run = script.IsRun; |
||||
|
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_OnePackageScriptToRun_PackageScriptSessionIsCmdlet() |
||||
{ |
||||
CreateCmdlet(); |
||||
FakePackageScript script = AddScript(); |
||||
RunCmdlet(); |
||||
|
||||
IPackageScriptSession session = script.SessionPassedToRun; |
||||
|
||||
Assert.AreEqual(cmdlet, session); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_TwoPackageScriptsToRun_TwoPackageScriptSessionIsCmdlet() |
||||
{ |
||||
CreateCmdlet(); |
||||
AddScript(); |
||||
FakePackageScript script = AddScript(); |
||||
RunCmdlet(); |
||||
|
||||
IPackageScriptSession session = script.SessionPassedToRun; |
||||
|
||||
Assert.AreEqual(cmdlet, session); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_NoPackageScriptsToRun_NullReferenceExceptionIsNotThrown() |
||||
{ |
||||
CreateCmdlet(); |
||||
Assert.DoesNotThrow(() => RunCmdlet()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
// 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.Scripting; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class ConsolePackageActionRunner : IPackageActionRunner |
||||
{ |
||||
IPackageManagementConsoleHost consoleHost; |
||||
PackageActionsToRun packageActionsToRun; |
||||
IPackageManagementWorkbench workbench; |
||||
|
||||
public ConsolePackageActionRunner( |
||||
IPackageManagementConsoleHost consoleHost, |
||||
PackageActionsToRun packageActionsToRun) |
||||
: this(consoleHost, packageActionsToRun, new PackageManagementWorkbench()) |
||||
{ |
||||
} |
||||
|
||||
public ConsolePackageActionRunner( |
||||
IPackageManagementConsoleHost consoleHost, |
||||
PackageActionsToRun packageActionsToRun, |
||||
IPackageManagementWorkbench workbench) |
||||
{ |
||||
this.consoleHost = consoleHost; |
||||
this.packageActionsToRun = packageActionsToRun; |
||||
this.workbench = workbench; |
||||
} |
||||
|
||||
public void Run(ProcessPackageAction action) |
||||
{ |
||||
CreateConsolePadIfConsoleHostIsNotRunning(); |
||||
RunAction(action); |
||||
} |
||||
|
||||
void CreateConsolePadIfConsoleHostIsNotRunning() |
||||
{ |
||||
if (!consoleHost.IsRunning) { |
||||
workbench.CreateConsolePad(); |
||||
} |
||||
} |
||||
|
||||
void RunAction(ProcessPackageAction action) |
||||
{ |
||||
AddNewActionToRun(action); |
||||
InvokeProcessPackageActionsCmdlet(); |
||||
} |
||||
|
||||
void AddNewActionToRun(ProcessPackageAction action) |
||||
{ |
||||
packageActionsToRun.AddAction(action); |
||||
} |
||||
|
||||
void InvokeProcessPackageActionsCmdlet() |
||||
{ |
||||
string command = "Invoke-ProcessPackageActions"; |
||||
consoleHost.ExecuteCommand(command); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
// 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 |
||||
{ |
||||
public interface IPackageActionRunner |
||||
{ |
||||
void Run(ProcessPackageAction action); |
||||
} |
||||
} |
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
// 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 |
||||
{ |
||||
public class PackageActionRunner : IPackageActionRunner |
||||
{ |
||||
IPackageActionRunner consolePackageActionRunner; |
||||
|
||||
public PackageActionRunner(IPackageActionRunner consolePackageActionRunner) |
||||
{ |
||||
this.consolePackageActionRunner = consolePackageActionRunner; |
||||
} |
||||
|
||||
public void Run(ProcessPackageAction action) |
||||
{ |
||||
if (action.HasPackageScriptsToRun()) { |
||||
consolePackageActionRunner.Run(action); |
||||
} else { |
||||
action.Execute(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// 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 System.Collections.Concurrent; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class PackageActionsToRun |
||||
{ |
||||
ConcurrentQueue<ProcessPackageAction> actions = new ConcurrentQueue<ProcessPackageAction>(); |
||||
|
||||
public bool GetNextAction(out ProcessPackageAction action) |
||||
{ |
||||
return actions.TryDequeue(out action); |
||||
} |
||||
|
||||
public void AddAction(ProcessPackageAction action) |
||||
{ |
||||
actions.Enqueue(action); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
// 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 System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Linq; |
||||
|
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class PackageFiles |
||||
{ |
||||
IEnumerable<IPackageFile> files; |
||||
|
||||
public PackageFiles(IPackage package) |
||||
: this(package.GetFiles()) |
||||
{ |
||||
} |
||||
|
||||
public PackageFiles(IEnumerable<IPackageFile> files) |
||||
{ |
||||
this.files = files; |
||||
} |
||||
|
||||
public bool HasAnyPackageScripts() |
||||
{ |
||||
foreach (string fileName in GetFileNames()) { |
||||
if (IsPackageScriptFile(fileName)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
IEnumerable<string> GetFileNames() |
||||
{ |
||||
foreach (IPackageFile file in files) { |
||||
string fileName = Path.GetFileName(file.Path); |
||||
yield return fileName; |
||||
} |
||||
} |
||||
|
||||
public bool HasUninstallPackageScript() |
||||
{ |
||||
foreach (string fileName in GetFileNames()) { |
||||
if (IsPackageUninstallScriptFile(fileName)) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
bool IsPackageScriptFile(string fileName) |
||||
{ |
||||
return |
||||
IsPackageInitializationScriptFile(fileName) || |
||||
IsPackageInstallScriptFile(fileName) || |
||||
IsPackageUninstallScriptFile(fileName); |
||||
} |
||||
|
||||
bool IsPackageInitializationScriptFile(string fileName) |
||||
{ |
||||
return IsCaseInsensitiveMatch(fileName, "init.ps1"); |
||||
} |
||||
|
||||
bool IsPackageInstallScriptFile(string fileName) |
||||
{ |
||||
return IsCaseInsensitiveMatch(fileName, "install.ps1"); |
||||
} |
||||
|
||||
bool IsPackageUninstallScriptFile(string fileName) |
||||
{ |
||||
return IsCaseInsensitiveMatch(fileName, "uninstall.ps1"); |
||||
} |
||||
|
||||
bool IsCaseInsensitiveMatch(string a, string b) |
||||
{ |
||||
return String.Equals(a, b, StringComparison.InvariantCultureIgnoreCase); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
// 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 System.Collections.Generic; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public class PackageFilesForOperations |
||||
{ |
||||
IEnumerable<PackageOperation> operations; |
||||
|
||||
public PackageFilesForOperations(IEnumerable<PackageOperation> operations) |
||||
{ |
||||
this.operations = operations; |
||||
} |
||||
|
||||
public bool HasAnyPackageScripts() |
||||
{ |
||||
foreach (PackageFiles files in GetPackageFilesForEachOperation()) { |
||||
if (files.HasAnyPackageScripts()) { |
||||
return true; |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
IEnumerable<PackageFiles> GetPackageFilesForEachOperation() |
||||
{ |
||||
foreach (PackageOperation operation in operations) { |
||||
yield return new PackageFiles(operation.Package); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
// 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 System.Collections.Generic; |
||||
using NuGet; |
||||
|
||||
namespace ICSharpCode.PackageManagement |
||||
{ |
||||
public abstract class ProcessPackageOperationsAction : ProcessPackageAction |
||||
{ |
||||
public ProcessPackageOperationsAction( |
||||
IPackageManagementProject project, |
||||
IPackageManagementEvents packageManagementEvents) |
||||
: base(project, packageManagementEvents) |
||||
{ |
||||
} |
||||
|
||||
public IEnumerable<PackageOperation> Operations { get; set; } |
||||
|
||||
public override bool HasPackageScriptsToRun() |
||||
{ |
||||
var files = new PackageFilesForOperations(Operations); |
||||
return files.HasAnyPackageScripts(); |
||||
} |
||||
|
||||
protected override void BeforeExecute() |
||||
{ |
||||
base.BeforeExecute(); |
||||
GetPackageOperationsIfMissing(); |
||||
} |
||||
|
||||
void GetPackageOperationsIfMissing() |
||||
{ |
||||
if (Operations == null) { |
||||
Operations = GetPackageOperations(); |
||||
} |
||||
} |
||||
|
||||
protected virtual IEnumerable<PackageOperation> GetPackageOperations() |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
// 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 class ConsolePackageScriptRunner : IPackageScriptRunner |
||||
{ |
||||
IPackageManagementConsoleHost consoleHost; |
||||
PackageScriptsToRun packageScriptsToRun; |
||||
IPackageManagementWorkbench workbench; |
||||
|
||||
public ConsolePackageScriptRunner( |
||||
IPackageManagementConsoleHost consoleHost, |
||||
PackageScriptsToRun packageScriptsToRun) |
||||
: this( consoleHost, packageScriptsToRun, new PackageManagementWorkbench()) |
||||
{ |
||||
} |
||||
|
||||
public ConsolePackageScriptRunner( |
||||
IPackageManagementConsoleHost consoleHost, |
||||
PackageScriptsToRun packageScriptsToRun, |
||||
IPackageManagementWorkbench workbench) |
||||
{ |
||||
this.consoleHost = consoleHost; |
||||
this.packageScriptsToRun = packageScriptsToRun; |
||||
this.workbench = workbench; |
||||
} |
||||
|
||||
public void Run(IPackageScript script) |
||||
{ |
||||
if (script.Exists()) { |
||||
CreateConsolePadIfConsoleHostIsNotRunning(); |
||||
RunScriptThatExists(script); |
||||
} |
||||
} |
||||
|
||||
void CreateConsolePadIfConsoleHostIsNotRunning() |
||||
{ |
||||
if (!consoleHost.IsRunning) { |
||||
workbench.CreateConsolePad(); |
||||
} |
||||
} |
||||
|
||||
void RunScriptThatExists(IPackageScript script) |
||||
{ |
||||
AddNewScriptToRun(script); |
||||
InvokeRunPackageScriptsCmdlet(); |
||||
} |
||||
|
||||
void AddNewScriptToRun(IPackageScript script) |
||||
{ |
||||
packageScriptsToRun.AddScript(script); |
||||
} |
||||
|
||||
void InvokeRunPackageScriptsCmdlet() |
||||
{ |
||||
string command = "Invoke-RunPackageScripts"; |
||||
consoleHost.ExecuteCommand(command); |
||||
} |
||||
} |
||||
} |
@ -1,32 +0,0 @@
@@ -1,32 +0,0 @@
|
||||
// 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 System.Collections.Concurrent; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Scripting |
||||
{ |
||||
public class PackageScriptsToRun |
||||
{ |
||||
ConcurrentQueue<IPackageScript> scripts = new ConcurrentQueue<IPackageScript>(); |
||||
|
||||
public IPackageScript GetNextScript() |
||||
{ |
||||
IPackageScript script = null; |
||||
if (GetNextScript(out script)) { |
||||
return script; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public bool GetNextScript(out IPackageScript script) |
||||
{ |
||||
return scripts.TryDequeue(out script); |
||||
} |
||||
|
||||
public void AddScript(IPackageScript script) |
||||
{ |
||||
scripts.Enqueue(script); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,126 @@
@@ -0,0 +1,126 @@
|
||||
// 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.Design; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class ConsolePackageActionRunnerTests |
||||
{ |
||||
ConsolePackageActionRunner runner; |
||||
PackageActionsToRun actionsToRun; |
||||
FakePackageManagementConsoleHost fakeConsoleHost; |
||||
FakeScriptingConsole fakeScriptingConsole; |
||||
FakePackageManagementWorkbench fakeWorkbench; |
||||
|
||||
void CreateRunner() |
||||
{ |
||||
actionsToRun = new PackageActionsToRun(); |
||||
fakeConsoleHost = new FakePackageManagementConsoleHost(); |
||||
fakeScriptingConsole = new FakeScriptingConsole(); |
||||
fakeConsoleHost.ScriptingConsole = fakeScriptingConsole; |
||||
fakeWorkbench = new FakePackageManagementWorkbench(); |
||||
runner = new ConsolePackageActionRunner(fakeConsoleHost, actionsToRun, fakeWorkbench); |
||||
} |
||||
|
||||
FakeInstallPackageAction CreateInstallAction() |
||||
{ |
||||
var project = new FakePackageManagementProject(); |
||||
var action = new FakeInstallPackageAction(project); |
||||
action.Operations = new PackageOperation[0]; |
||||
return action; |
||||
} |
||||
|
||||
FakeInstallPackageAction RunInstallActionWithNoOperations() |
||||
{ |
||||
FakeInstallPackageAction action = CreateInstallAction(); |
||||
runner.Run(action); |
||||
return action; |
||||
} |
||||
|
||||
FakeInstallPackageAction RunInstallActionWithOneOperation() |
||||
{ |
||||
var operations = new PackageOperation[] { |
||||
new PackageOperation(new FakePackage(), PackageAction.Install) |
||||
}; |
||||
FakeInstallPackageAction action = CreateInstallAction(); |
||||
action.Operations = operations; |
||||
runner.Run(action); |
||||
return action; |
||||
} |
||||
|
||||
void ConsoleHostIsRunning() |
||||
{ |
||||
fakeConsoleHost.IsRunning = true; |
||||
} |
||||
|
||||
void ConsoleHostIsNotRunning() |
||||
{ |
||||
fakeConsoleHost.IsRunning = false; |
||||
} |
||||
|
||||
ProcessPackageAction GetNextActionToRun() |
||||
{ |
||||
ProcessPackageAction action = null; |
||||
actionsToRun.GetNextAction(out action); |
||||
return action; |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunning_ActionAddedToPackageActionsToBeRun() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
FakeInstallPackageAction expectedAction = RunInstallActionWithOneOperation(); |
||||
|
||||
ProcessPackageAction actionAdded = GetNextActionToRun(); |
||||
|
||||
Assert.AreEqual(expectedAction, actionAdded); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunning_CommandPassedToConsoleHostToProcessPackageActions() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
RunInstallActionWithOneOperation(); |
||||
|
||||
string command = fakeConsoleHost.FirstCommandExecuted; |
||||
string expectedCommand = "Invoke-ProcessPackageActions"; |
||||
|
||||
Assert.AreEqual(expectedCommand, command); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsNotRunning_ConsolePadIsCreated() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsNotRunning(); |
||||
RunInstallActionWithOneOperation(); |
||||
|
||||
bool created = fakeWorkbench.IsCreateConsolePadCalled; |
||||
|
||||
Assert.IsTrue(created); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunning_ConsolePadIsNotCreated() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
RunInstallActionWithOneOperation(); |
||||
|
||||
bool created = fakeWorkbench.IsCreateConsolePadCalled; |
||||
|
||||
Assert.IsFalse(created); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// 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; |
||||
|
||||
namespace PackageManagement.Tests.Helpers |
||||
{ |
||||
public class FakePackageActionRunner : IPackageActionRunner |
||||
{ |
||||
public ProcessPackageAction ActionPassedToRun; |
||||
|
||||
public void Run(ProcessPackageAction action) |
||||
{ |
||||
ActionPassedToRun = action; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
// 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 System.Collections.Generic; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class PackageActionRunnerTests |
||||
{ |
||||
FakePackageActionRunner fakeConsoleActionRunner; |
||||
PackageActionRunner runner; |
||||
FakeInstallPackageAction fakeAction; |
||||
|
||||
void CreateRunner() |
||||
{ |
||||
fakeConsoleActionRunner = new FakePackageActionRunner(); |
||||
runner = new PackageActionRunner(fakeConsoleActionRunner); |
||||
} |
||||
|
||||
void CreateInstallActionWithNoPowerShellScripts() |
||||
{ |
||||
var fakeProject = new FakePackageManagementProject(); |
||||
fakeAction = new FakeInstallPackageAction(fakeProject); |
||||
fakeAction.Operations = new PackageOperation[0]; |
||||
} |
||||
|
||||
void CreateInstallActionWithOnePowerShellScript() |
||||
{ |
||||
CreateInstallActionWithNoPowerShellScripts(); |
||||
|
||||
var package = new FakePackage(); |
||||
package.AddFile(@"tools\init.ps1"); |
||||
|
||||
var operation = new PackageOperation(package, PackageAction.Install); |
||||
var operations = new List<PackageOperation>(); |
||||
operations.Add(operation); |
||||
|
||||
fakeAction.Operations = operations; |
||||
} |
||||
|
||||
void Run() |
||||
{ |
||||
runner.Run(fakeAction); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_InstallActionHasNoPowerShellScripts_ActionIsExecutedDirectly() |
||||
{ |
||||
CreateRunner(); |
||||
CreateInstallActionWithNoPowerShellScripts(); |
||||
Run(); |
||||
|
||||
bool executed = fakeAction.IsExecuteCalled; |
||||
|
||||
Assert.IsTrue(executed); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_InstallActionHasOnePowerShellScript_ActionIsPassedToConsoleToRun() |
||||
{ |
||||
CreateRunner(); |
||||
CreateInstallActionWithOnePowerShellScript(); |
||||
Run(); |
||||
|
||||
ProcessPackageAction action = fakeConsoleActionRunner.ActionPassedToRun; |
||||
|
||||
Assert.AreEqual(fakeAction, action); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_InstallActionHasOnePowerShellScript_ActionIsNotExecutedDirectly() |
||||
{ |
||||
CreateRunner(); |
||||
CreateInstallActionWithOnePowerShellScript(); |
||||
Run(); |
||||
|
||||
bool executed = fakeAction.IsExecuteCalled; |
||||
|
||||
Assert.IsFalse(executed); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
// 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.Design; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class PackageActionsToRunTests |
||||
{ |
||||
PackageActionsToRun actions; |
||||
|
||||
void CreateActions() |
||||
{ |
||||
actions = new PackageActionsToRun(); |
||||
} |
||||
|
||||
InstallPackageAction AddAction() |
||||
{ |
||||
var project = new FakePackageManagementProject(); |
||||
var events = new FakePackageManagementEvents(); |
||||
var action = new InstallPackageAction(project, events); |
||||
actions.AddAction(action); |
||||
return action; |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_NewInstance_ReturnsFalse() |
||||
{ |
||||
CreateActions(); |
||||
ProcessPackageAction action = null; |
||||
bool result = actions.GetNextAction(out action); |
||||
|
||||
Assert.IsFalse(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_OneActionAdded_ReturnsActionInOutParameter() |
||||
{ |
||||
CreateActions(); |
||||
ProcessPackageAction expectedAction = AddAction(); |
||||
|
||||
ProcessPackageAction action = null; |
||||
actions.GetNextAction(out action); |
||||
|
||||
Assert.AreEqual(expectedAction, action); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_OneActionAdded_ReturnsTrue() |
||||
{ |
||||
CreateActions(); |
||||
ProcessPackageAction expectedAction = AddAction(); |
||||
|
||||
ProcessPackageAction action = null; |
||||
bool result = actions.GetNextAction(out action); |
||||
|
||||
Assert.IsTrue(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_CalledTwiceWithOneActionAdded_ReturnsNullActionInOutParameterOnSecondCall() |
||||
{ |
||||
CreateActions(); |
||||
ProcessPackageAction expectedAction = AddAction(); |
||||
ProcessPackageAction action = null; |
||||
actions.GetNextAction(out action); |
||||
actions.GetNextAction(out action); |
||||
|
||||
Assert.IsNull(action); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_CalledTwiceWithOneActionAdded_ReturnsFalseOnSecondCall() |
||||
{ |
||||
CreateActions(); |
||||
ProcessPackageAction expectedAction = AddAction(); |
||||
|
||||
ProcessPackageAction action = null; |
||||
actions.GetNextAction(out action); |
||||
bool result = actions.GetNextAction(out action); |
||||
|
||||
Assert.IsFalse(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_CalledTwiceWithTwoActionsAdded_ReturnsSecondActionAddedInOutParameter() |
||||
{ |
||||
CreateActions(); |
||||
AddAction(); |
||||
ProcessPackageAction expectedAction = AddAction(); |
||||
ProcessPackageAction action = null; |
||||
actions.GetNextAction(out action); |
||||
actions.GetNextAction(out action); |
||||
|
||||
Assert.AreEqual(expectedAction, action); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextAction_CalledTwiceWithTwoActionsAdded_ReturnsTrueOnSecondCall() |
||||
{ |
||||
CreateActions(); |
||||
AddAction(); |
||||
ProcessPackageAction expectedAction = AddAction(); |
||||
ProcessPackageAction action = null; |
||||
actions.GetNextAction(out action); |
||||
bool result = actions.GetNextAction(out action); |
||||
|
||||
Assert.IsTrue(result); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,148 @@
@@ -0,0 +1,148 @@
|
||||
// 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 System.Collections.Generic; |
||||
using ICSharpCode.PackageManagement; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using NuGet; |
||||
using NUnit.Framework; |
||||
|
||||
namespace PackageManagement.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class PackageFilesTests |
||||
{ |
||||
PackageFiles packageFiles; |
||||
|
||||
void CreatePackageFiles(FakePackage package) |
||||
{ |
||||
packageFiles = new PackageFiles(package); |
||||
} |
||||
|
||||
void CreatePackageFilesWithOneFile(string fileName) |
||||
{ |
||||
var package = new FakePackage(); |
||||
package.AddFile(fileName); |
||||
CreatePackageFiles(package); |
||||
} |
||||
|
||||
void CreatePackageFilesWithTwoFiles(string fileName1, string fileName2) |
||||
{ |
||||
var package = new FakePackage(); |
||||
package.AddFile(fileName1); |
||||
package.AddFile(fileName2); |
||||
CreatePackageFiles(package); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellInitScript_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\init.ps1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOneCSharpFile_ReturnsFalse() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"src\test.cs"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsFalse(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellInitScriptWithDifferentParentFolder_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"parentfolder\init.ps1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellInitScriptInUpperCase_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\INIT.PS1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellInstallScript_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\install.ps1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellInstallScriptInUpperCase_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\INSTALL.PS1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellUninstallScript_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\uninstall.ps1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_HasOnePowerShellUninstallScriptInUpperCase_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\UNINSTALL.PS1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasAnyPackageScripts_SecondFileIsPowerShellInitScript_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithTwoFiles(@"src\test.cs", @"tools\init.ps1"); |
||||
|
||||
bool hasScripts = packageFiles.HasAnyPackageScripts(); |
||||
|
||||
Assert.IsTrue(hasScripts); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasUninstallPackageScript_HasOnePowerShellUninstallScript_ReturnsTrue() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\uninstall.ps1"); |
||||
|
||||
bool hasScript = packageFiles.HasUninstallPackageScript(); |
||||
|
||||
Assert.IsTrue(hasScript); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasUninstallPackageScript_HasOneCSharpFile_ReturnsFalse() |
||||
{ |
||||
CreatePackageFilesWithOneFile(@"tools\test.cs"); |
||||
|
||||
bool hasScript = packageFiles.HasUninstallPackageScript(); |
||||
|
||||
Assert.IsFalse(hasScript); |
||||
} |
||||
} |
||||
} |
@ -1,152 +0,0 @@
@@ -1,152 +0,0 @@
|
||||
// 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.Scripting; |
||||
using ICSharpCode.Scripting.Tests.Utils; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.Scripting |
||||
{ |
||||
[TestFixture] |
||||
public class ConsolePackageScriptRunnerTests |
||||
{ |
||||
ConsolePackageScriptRunner runner; |
||||
PackageScriptsToRun packageScriptsToRun; |
||||
FakePackageManagementConsoleHost fakeConsoleHost; |
||||
FakeScriptingConsole fakeScriptingConsole; |
||||
FakePackageManagementWorkbench fakeWorkbench; |
||||
|
||||
void CreateRunner() |
||||
{ |
||||
packageScriptsToRun = new PackageScriptsToRun(); |
||||
fakeConsoleHost = new FakePackageManagementConsoleHost(); |
||||
fakeScriptingConsole = new FakeScriptingConsole(); |
||||
fakeConsoleHost.ScriptingConsole = fakeScriptingConsole; |
||||
fakeWorkbench = new FakePackageManagementWorkbench(); |
||||
runner = new ConsolePackageScriptRunner(fakeConsoleHost, packageScriptsToRun, fakeWorkbench); |
||||
} |
||||
|
||||
FakePackageScript RunScriptThatExists() |
||||
{ |
||||
var script = new FakePackageScript(); |
||||
script.ExistsReturnValue = true; |
||||
return RunScript(script); |
||||
} |
||||
|
||||
FakePackageScript RunScriptThatDoesNotExist() |
||||
{ |
||||
var script = new FakePackageScript(); |
||||
script.ExistsReturnValue = false; |
||||
return RunScript(script); |
||||
} |
||||
|
||||
FakePackageScript RunScript(FakePackageScript script) |
||||
{ |
||||
runner.Run(script); |
||||
return script; |
||||
} |
||||
|
||||
void ConsoleHostIsRunning() |
||||
{ |
||||
fakeConsoleHost.IsRunning = true; |
||||
} |
||||
|
||||
void ConsoleHostIsNotRunning() |
||||
{ |
||||
fakeConsoleHost.IsRunning = false; |
||||
} |
||||
|
||||
IPackageScript GetNextScriptToBeRun() |
||||
{ |
||||
return packageScriptsToRun.GetNextScript(); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunningAndScriptExists_ScriptAddedToPackageScriptsToBeRun() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
FakePackageScript expectedScript = RunScriptThatExists(); |
||||
|
||||
IPackageScript scriptAdded = GetNextScriptToBeRun(); |
||||
|
||||
Assert.AreEqual(expectedScript, scriptAdded); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunningAndScriptDoesNotExist_ScriptIsNotAddedToPackageScriptsToBeRun() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
FakePackageScript script = RunScriptThatDoesNotExist(); |
||||
script.ExistsReturnValue = false; |
||||
|
||||
IPackageScript scriptAdded = GetNextScriptToBeRun(); |
||||
|
||||
Assert.IsNull(scriptAdded); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunningAndScriptExists_CommandPassedToConsoleHostToRunPackageScripts() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
RunScriptThatExists(); |
||||
|
||||
string command = fakeConsoleHost.FirstCommandExecuted; |
||||
string expectedCommand = "Invoke-RunPackageScripts"; |
||||
|
||||
Assert.AreEqual(expectedCommand, command); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunningAndScriptDoesNotExist_CommandIsNotPassedToConsoleHostToRunPackageScripts() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
RunScriptThatDoesNotExist(); |
||||
|
||||
int count = fakeConsoleHost.CommandsExecuted.Count; |
||||
|
||||
Assert.AreEqual(0, count); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsNotRunningAndScriptExists_ConsolePadIsCreated() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsNotRunning(); |
||||
RunScriptThatExists(); |
||||
|
||||
bool created = fakeWorkbench.IsCreateConsolePadCalled; |
||||
|
||||
Assert.IsTrue(created); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsNotRunningAndScriptDoesNotExist_ConsolePadIsNotCreated() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsNotRunning(); |
||||
RunScriptThatDoesNotExist(); |
||||
|
||||
bool created = fakeWorkbench.IsCreateConsolePadCalled; |
||||
|
||||
Assert.IsFalse(created); |
||||
} |
||||
|
||||
[Test] |
||||
public void Run_ConsoleHostIsRunningAndScriptExists_ConsolePadIsNotCreated() |
||||
{ |
||||
CreateRunner(); |
||||
ConsoleHostIsRunning(); |
||||
RunScriptThatExists(); |
||||
|
||||
bool created = fakeWorkbench.IsCreateConsolePadCalled; |
||||
|
||||
Assert.IsFalse(created); |
||||
} |
||||
} |
||||
} |
@ -1,156 +0,0 @@
@@ -1,156 +0,0 @@
|
||||
// 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.Scripting; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Tests.Scripting |
||||
{ |
||||
[TestFixture] |
||||
public class PackageScriptsToRunTests |
||||
{ |
||||
PackageScriptsToRun scriptsToRun; |
||||
|
||||
void CreateScriptsToBeRun() |
||||
{ |
||||
scriptsToRun = new PackageScriptsToRun(); |
||||
} |
||||
|
||||
FakePackageScript AddScript() |
||||
{ |
||||
var script = new FakePackageScript(); |
||||
scriptsToRun.AddScript(script); |
||||
return script; |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_NewInstance_ReturnsNull() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
IPackageScript script = scriptsToRun.GetNextScript(); |
||||
|
||||
Assert.IsNull(script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_NewInstance_ReturnsFalse() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
IPackageScript script = null; |
||||
bool result = scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.IsFalse(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_OneScriptAdded_ReturnsScript() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
|
||||
IPackageScript script = scriptsToRun.GetNextScript(); |
||||
|
||||
Assert.AreEqual(expectedScript, script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_OneScriptAdded_ReturnsScriptInOutParameter() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
|
||||
IPackageScript script = null; |
||||
scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.AreEqual(expectedScript, script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_OneScriptAdded_ReturnsTrue() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
|
||||
IPackageScript script = null; |
||||
bool result = scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.IsTrue(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_CalledTwiceWithOneScriptAdded_ReturnsNullOnSecondCall() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
scriptsToRun.GetNextScript(); |
||||
IPackageScript script = scriptsToRun.GetNextScript(); |
||||
|
||||
Assert.IsNull(script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_CalledTwiceWithOneScriptAdded_ReturnsNullScriptInOutParameterOnSecondCall() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
scriptsToRun.GetNextScript(); |
||||
IPackageScript script = null; |
||||
scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.IsNull(script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_CalledTwiceWithOneScriptAdded_ReturnsFalseOnSecondCall() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
scriptsToRun.GetNextScript(); |
||||
|
||||
IPackageScript script = null; |
||||
bool result = scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.IsFalse(result); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_CalledTwiceWithTwoScriptsAdded_ReturnsSecondScriptAdded() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
AddScript(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
scriptsToRun.GetNextScript(); |
||||
IPackageScript script = scriptsToRun.GetNextScript(); |
||||
|
||||
Assert.AreEqual(expectedScript, script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_CalledTwiceWithTwoScriptsAdded_ReturnsSecondScriptAddedInOutParameter() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
AddScript(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
scriptsToRun.GetNextScript(); |
||||
IPackageScript script = null; |
||||
scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.AreEqual(expectedScript, script); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetNextScript_CalledTwiceWithTwoScriptsAdded_ReturnsTrueOnSecondCall() |
||||
{ |
||||
CreateScriptsToBeRun(); |
||||
AddScript(); |
||||
FakePackageScript expectedScript = AddScript(); |
||||
scriptsToRun.GetNextScript(); |
||||
IPackageScript script = null; |
||||
bool result = scriptsToRun.GetNextScript(out script); |
||||
|
||||
Assert.IsTrue(result); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue