14 changed files with 265 additions and 17 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; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.PackageManagement.Cmdlets |
||||
{ |
||||
[Cmdlet(VerbsLifecycle.Invoke, "InitializePackages", DefaultParameterSetName = ParameterAttribute.AllParameterSets)] |
||||
public class InvokeInitializePackagesCmdlet : PackageManagementCmdlet |
||||
{ |
||||
IPackageManagementProjectService projectService; |
||||
IPackageInitializationScriptsFactory scriptsFactory; |
||||
|
||||
public InvokeInitializePackagesCmdlet() |
||||
: this( |
||||
PackageManagementServices.ProjectService, |
||||
new PackageInitializationScriptsFactory(PackageManagementServices.ConsoleHost), |
||||
PackageManagementServices.ConsoleHost, |
||||
null) |
||||
{ |
||||
} |
||||
|
||||
public InvokeInitializePackagesCmdlet( |
||||
IPackageManagementProjectService projectService, |
||||
IPackageInitializationScriptsFactory scriptsFactory, |
||||
IPackageManagementConsoleHost consoleHost, |
||||
ICmdletTerminatingError terminatingError) |
||||
: base(consoleHost, terminatingError) |
||||
{ |
||||
this.projectService = projectService; |
||||
this.scriptsFactory = scriptsFactory; |
||||
} |
||||
|
||||
protected override void ProcessRecord() |
||||
{ |
||||
RunPackageInitializationScripts(); |
||||
} |
||||
|
||||
void RunPackageInitializationScripts() |
||||
{ |
||||
IPackageInitializationScripts scripts = GetPackageInitializationScripts(); |
||||
if (scripts.Any()) { |
||||
scripts.Run(); |
||||
} |
||||
} |
||||
|
||||
IPackageInitializationScripts GetPackageInitializationScripts() |
||||
{ |
||||
Solution solution = projectService.OpenSolution; |
||||
return scriptsFactory.CreatePackageInitializationScripts(solution, this); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// 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.Cmdlets; |
||||
using ICSharpCode.PackageManagement.Design; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Cmdlets.Tests.Helpers |
||||
{ |
||||
public class TestableInvokeInitializePackagesCmdlet : InvokeInitializePackagesCmdlet |
||||
{ |
||||
public FakeCmdletTerminatingError FakeCmdletTerminatingError; |
||||
public FakePackageManagementConsoleHost FakePackageManagementConsoleHost; |
||||
public FakePackageManagementProjectService FakeProjectService; |
||||
public FakePackageInitializationScriptsFactory FakeScriptsFactory; |
||||
public Solution Solution; |
||||
|
||||
public TestableInvokeInitializePackagesCmdlet() |
||||
: this( |
||||
new FakePackageManagementProjectService(), |
||||
new FakePackageInitializationScriptsFactory(), |
||||
new FakePackageManagementConsoleHost(), |
||||
new FakeCmdletTerminatingError()) |
||||
{ |
||||
} |
||||
|
||||
public TestableInvokeInitializePackagesCmdlet( |
||||
FakePackageManagementProjectService projectService, |
||||
FakePackageInitializationScriptsFactory scriptsFactory, |
||||
FakePackageManagementConsoleHost consoleHost, |
||||
FakeCmdletTerminatingError cmdletTerminatingError) |
||||
: base(projectService, scriptsFactory, consoleHost, cmdletTerminatingError) |
||||
{ |
||||
this.FakeProjectService = projectService; |
||||
this.FakeScriptsFactory = scriptsFactory; |
||||
this.FakePackageManagementConsoleHost = consoleHost; |
||||
this.FakeCmdletTerminatingError = cmdletTerminatingError; |
||||
|
||||
Solution = new Solution(); |
||||
Solution.FileName = @"d:\projects\MyProject\MyProject.sln"; |
||||
projectService.OpenSolution = Solution; |
||||
} |
||||
|
||||
public void CallProcessRecord() |
||||
{ |
||||
base.ProcessRecord(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
// 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.Design; |
||||
using ICSharpCode.PackageManagement.Scripting; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using PackageManagement.Cmdlets.Tests.Helpers; |
||||
using PackageManagement.Tests.Helpers; |
||||
|
||||
namespace PackageManagement.Cmdlets.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class InvokeInitializePackagesCmdletTests |
||||
{ |
||||
TestableInvokeInitializePackagesCmdlet cmdlet; |
||||
FakeCmdletTerminatingError fakeTerminatingError; |
||||
FakePackageManagementProjectService fakeProjectService; |
||||
FakePackageInitializationScriptsFactory scriptsFactory; |
||||
|
||||
void CreateCmdlet() |
||||
{ |
||||
cmdlet = new TestableInvokeInitializePackagesCmdlet(); |
||||
fakeProjectService = cmdlet.FakeProjectService; |
||||
fakeTerminatingError = cmdlet.FakeCmdletTerminatingError; |
||||
scriptsFactory = cmdlet.FakeScriptsFactory; |
||||
} |
||||
|
||||
void RunCmdlet() |
||||
{ |
||||
cmdlet.CallProcessRecord(); |
||||
} |
||||
|
||||
void SolutionHasPackageInitializationScripts() |
||||
{ |
||||
scriptsFactory.FakePackageInitializationScripts.AnyReturnValue = true; |
||||
} |
||||
|
||||
void SolutionHasNoPackageInitializationScripts() |
||||
{ |
||||
scriptsFactory.FakePackageInitializationScripts.AnyReturnValue = false; |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_SolutionHasPackageInitializationScripts_PackageInitializationScriptsAreRun() |
||||
{ |
||||
CreateCmdlet(); |
||||
SolutionHasPackageInitializationScripts(); |
||||
RunCmdlet(); |
||||
|
||||
bool run = scriptsFactory.FakePackageInitializationScripts.IsRunCalled; |
||||
|
||||
Assert.IsTrue(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_SolutionHasNoPackageInitializationScripts_PackageInitializationScriptsAreNotRun() |
||||
{ |
||||
CreateCmdlet(); |
||||
SolutionHasNoPackageInitializationScripts(); |
||||
RunCmdlet(); |
||||
|
||||
bool run = scriptsFactory.FakePackageInitializationScripts.IsRunCalled; |
||||
|
||||
Assert.IsFalse(run); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_SolutionIsOpen_SolutionUsedToCreatePackageInitializationScripts() |
||||
{ |
||||
CreateCmdlet(); |
||||
RunCmdlet(); |
||||
|
||||
Solution expectedSolution = fakeProjectService.OpenSolution; |
||||
Solution actualSolution = scriptsFactory.SolutionPassedToCreatePackageInitializationScripts; |
||||
|
||||
Assert.AreEqual(expectedSolution, actualSolution); |
||||
} |
||||
|
||||
[Test] |
||||
public void ProcessRecord_SolutionHasPackageInitializationScripts_PackageScriptSessionIsCmdlet() |
||||
{ |
||||
CreateCmdlet(); |
||||
SolutionHasPackageInitializationScripts(); |
||||
RunCmdlet(); |
||||
|
||||
IPackageScriptSession session = scriptsFactory.ScriptSessionPassedToCreatePackageInitializationScripts; |
||||
|
||||
Assert.AreEqual(cmdlet, session); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue