7 changed files with 175 additions and 18 deletions
@ -0,0 +1,55 @@ |
|||||||
|
// 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, "UpdateWorkingDirectory", DefaultParameterSetName = ParameterAttribute.AllParameterSets)] |
||||||
|
public class InvokeUpdateWorkingDirectoryCmdlet : PackageManagementCmdlet |
||||||
|
{ |
||||||
|
IPackageManagementProjectService projectService; |
||||||
|
|
||||||
|
public InvokeUpdateWorkingDirectoryCmdlet() |
||||||
|
: this( |
||||||
|
PackageManagementServices.ProjectService, |
||||||
|
PackageManagementServices.ConsoleHost, |
||||||
|
null) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public InvokeUpdateWorkingDirectoryCmdlet( |
||||||
|
IPackageManagementProjectService projectService, |
||||||
|
IPackageManagementConsoleHost consoleHost, |
||||||
|
ICmdletTerminatingError terminatingError) |
||||||
|
: base(consoleHost, terminatingError) |
||||||
|
{ |
||||||
|
this.projectService = projectService; |
||||||
|
} |
||||||
|
|
||||||
|
protected override void ProcessRecord() |
||||||
|
{ |
||||||
|
UpdateWorkingDirectory(); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateWorkingDirectory() |
||||||
|
{ |
||||||
|
string directory = GetWorkingDirectory(); |
||||||
|
UpdateWorkingDirectory(directory); |
||||||
|
} |
||||||
|
|
||||||
|
string GetWorkingDirectory() |
||||||
|
{ |
||||||
|
var workingDirectory = new PowerShellWorkingDirectory(projectService); |
||||||
|
return workingDirectory.GetWorkingDirectory(); |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateWorkingDirectory(string directory) |
||||||
|
{ |
||||||
|
string command = String.Format("Set-Location '{0}'", directory); |
||||||
|
InvokeScript(command); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
// 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 TestableInvokeUpdateWorkingDirectoryCmdlet : InvokeUpdateWorkingDirectoryCmdlet |
||||||
|
{ |
||||||
|
public FakeCmdletTerminatingError FakeCmdletTerminatingError; |
||||||
|
public FakePackageManagementConsoleHost FakePackageManagementConsoleHost; |
||||||
|
public FakePackageManagementProjectService FakeProjectService; |
||||||
|
public Solution Solution; |
||||||
|
|
||||||
|
public TestableInvokeUpdateWorkingDirectoryCmdlet() |
||||||
|
: this( |
||||||
|
new FakePackageManagementProjectService(), |
||||||
|
new FakePackageManagementConsoleHost(), |
||||||
|
new FakeCmdletTerminatingError()) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public TestableInvokeUpdateWorkingDirectoryCmdlet( |
||||||
|
FakePackageManagementProjectService projectService, |
||||||
|
FakePackageManagementConsoleHost consoleHost, |
||||||
|
FakeCmdletTerminatingError cmdletTerminatingError) |
||||||
|
: base(projectService, consoleHost, cmdletTerminatingError) |
||||||
|
{ |
||||||
|
this.FakeProjectService = projectService; |
||||||
|
this.FakePackageManagementConsoleHost = consoleHost; |
||||||
|
this.FakeCmdletTerminatingError = cmdletTerminatingError; |
||||||
|
|
||||||
|
Solution = new Solution(); |
||||||
|
Solution.FileName = @"d:\projects\MyProject\MyProject.sln"; |
||||||
|
projectService.OpenSolution = Solution; |
||||||
|
} |
||||||
|
|
||||||
|
public void CallProcessRecord() |
||||||
|
{ |
||||||
|
base.ProcessRecord(); |
||||||
|
} |
||||||
|
|
||||||
|
public string ScriptPassedToInvokeScript; |
||||||
|
|
||||||
|
public override void InvokeScript(string script) |
||||||
|
{ |
||||||
|
ScriptPassedToInvokeScript = script; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,58 @@ |
|||||||
|
// 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 NUnit.Framework; |
||||||
|
using PackageManagement.Cmdlets.Tests.Helpers; |
||||||
|
|
||||||
|
namespace PackageManagement.Cmdlets.Tests |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class InvokeUpdateWorkingDirectoryCmdletTests |
||||||
|
{ |
||||||
|
TestableInvokeUpdateWorkingDirectoryCmdlet cmdlet; |
||||||
|
FakeCmdletTerminatingError fakeTerminatingError; |
||||||
|
FakePackageManagementProjectService fakeProjectService; |
||||||
|
|
||||||
|
void CreateCmdlet() |
||||||
|
{ |
||||||
|
cmdlet = new TestableInvokeUpdateWorkingDirectoryCmdlet(); |
||||||
|
fakeProjectService = cmdlet.FakeProjectService; |
||||||
|
fakeTerminatingError = cmdlet.FakeCmdletTerminatingError; |
||||||
|
} |
||||||
|
|
||||||
|
void RunCmdlet() |
||||||
|
{ |
||||||
|
cmdlet.CallProcessRecord(); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ProcessRecord_SolutionIsOpen_PowerShellWorkingDirectoryIsSetToSolutionDirectory() |
||||||
|
{ |
||||||
|
CreateCmdlet(); |
||||||
|
fakeProjectService.OpenSolution.FileName = @"d:\projects\MySolution\MySolution.sln"; |
||||||
|
RunCmdlet(); |
||||||
|
|
||||||
|
string commandExecuted = cmdlet.ScriptPassedToInvokeScript; |
||||||
|
|
||||||
|
string expectedCommandExecuted = @"Set-Location 'd:\projects\MySolution'"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCommandExecuted, commandExecuted); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void ProcessRecord_SolutionIsNotOpen_PowerShellWorkingDirectoryIsSetUserProfileFolder() |
||||||
|
{ |
||||||
|
CreateCmdlet(); |
||||||
|
fakeProjectService.OpenSolution = null; |
||||||
|
RunCmdlet(); |
||||||
|
|
||||||
|
string commandExecuted = cmdlet.ScriptPassedToInvokeScript; |
||||||
|
|
||||||
|
string expectedCommandExecuted = @"Set-Location '$env:USERPROFILE'"; |
||||||
|
|
||||||
|
Assert.AreEqual(expectedCommandExecuted, commandExecuted); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue