Browse Source

Create cmdlet to update the PowerShell working directory.

pull/15/head
Matt Ward 15 years ago
parent
commit
dad6cd4f77
  1. 1
      src/AddIns/Misc/PackageManagement/Cmdlets/Project/PackageManagement.Cmdlets.csproj
  2. 16
      src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/InvokeInitializePackagesCmdlet.cs
  3. 55
      src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/InvokeUpdateWorkingDirectoryCmdlet.cs
  4. 54
      src/AddIns/Misc/PackageManagement/Cmdlets/Test/Helpers/TestableInvokeUpdateWorkingDirectoryCmdlet.cs
  5. 2
      src/AddIns/Misc/PackageManagement/Cmdlets/Test/PackageManagement.Cmdlets.Tests.csproj
  6. 7
      src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/InvokeInitializePackagesCmdletTests.cs
  7. 58
      src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/InvokeUpdateWorkingDirectoryCmdletTests.cs

1
src/AddIns/Misc/PackageManagement/Cmdlets/Project/PackageManagement.Cmdlets.csproj

@ -49,6 +49,7 @@
<Compile Include="Src\ICmdletTerminatingError.cs" /> <Compile Include="Src\ICmdletTerminatingError.cs" />
<Compile Include="Src\InstallPackageCmdlet.cs" /> <Compile Include="Src\InstallPackageCmdlet.cs" />
<Compile Include="Src\InvokeInitializePackagesCmdlet.cs" /> <Compile Include="Src\InvokeInitializePackagesCmdlet.cs" />
<Compile Include="Src\InvokeUpdateWorkingDirectoryCmdlet.cs" />
<Compile Include="Src\ITerminatingCmdlet.cs" /> <Compile Include="Src\ITerminatingCmdlet.cs" />
<Compile Include="Src\OpenProjects.cs" /> <Compile Include="Src\OpenProjects.cs" />
<Compile Include="Src\PackageManagementCmdlet.cs" /> <Compile Include="Src\PackageManagementCmdlet.cs" />

16
src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/InvokeInitializePackagesCmdlet.cs

@ -42,19 +42,7 @@ namespace ICSharpCode.PackageManagement.Cmdlets
void UpdateWorkingDirectory() void UpdateWorkingDirectory()
{ {
string directory = GetWorkingDirectory(); string command = "Invoke-UpdateWorkingDirectory";
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); InvokeScript(command);
} }
@ -63,7 +51,7 @@ namespace ICSharpCode.PackageManagement.Cmdlets
IPackageInitializationScripts scripts = GetPackageInitializationScripts(); IPackageInitializationScripts scripts = GetPackageInitializationScripts();
if (scripts.Any()) { if (scripts.Any()) {
scripts.Run(); scripts.Run();
} }
} }
IPackageInitializationScripts GetPackageInitializationScripts() IPackageInitializationScripts GetPackageInitializationScripts()

55
src/AddIns/Misc/PackageManagement/Cmdlets/Project/Src/InvokeUpdateWorkingDirectoryCmdlet.cs

@ -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);
}
}
}

54
src/AddIns/Misc/PackageManagement/Cmdlets/Test/Helpers/TestableInvokeUpdateWorkingDirectoryCmdlet.cs

@ -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;
}
}
}

2
src/AddIns/Misc/PackageManagement/Cmdlets/Test/PackageManagement.Cmdlets.Tests.csproj

@ -50,6 +50,7 @@
<Compile Include="Helpers\TestableGetProjectCmdlet.cs" /> <Compile Include="Helpers\TestableGetProjectCmdlet.cs" />
<Compile Include="Helpers\TestableInstallPackageCmdlet.cs" /> <Compile Include="Helpers\TestableInstallPackageCmdlet.cs" />
<Compile Include="Helpers\TestableInvokeInitializePackagesCmdlet.cs" /> <Compile Include="Helpers\TestableInvokeInitializePackagesCmdlet.cs" />
<Compile Include="Helpers\TestableInvokeUpdateWorkingDirectoryCmdlet.cs" />
<Compile Include="Helpers\TestablePackageManagementCmdlet.cs" /> <Compile Include="Helpers\TestablePackageManagementCmdlet.cs" />
<Compile Include="Helpers\TestableUninstallPackageCmdlet.cs" /> <Compile Include="Helpers\TestableUninstallPackageCmdlet.cs" />
<Compile Include="Helpers\TestableUpdatePackageCmdlet.cs" /> <Compile Include="Helpers\TestableUpdatePackageCmdlet.cs" />
@ -59,6 +60,7 @@
<Compile Include="Src\InvokeInitializePackagesCmdletTests.cs" /> <Compile Include="Src\InvokeInitializePackagesCmdletTests.cs" />
<Compile Include="Src\InstallPackageCmdletTests.cs" /> <Compile Include="Src\InstallPackageCmdletTests.cs" />
<Compile Include="Src\CmdletTestsBase.cs" /> <Compile Include="Src\CmdletTestsBase.cs" />
<Compile Include="Src\InvokeUpdateWorkingDirectoryCmdletTests.cs" />
<Compile Include="Src\PackageManagementCmdletTests.cs" /> <Compile Include="Src\PackageManagementCmdletTests.cs" />
<Compile Include="Src\UninstallPackageCmdletTests.cs" /> <Compile Include="Src\UninstallPackageCmdletTests.cs" />
<Compile Include="Src\UpdatePackageCmdletTests.cs" /> <Compile Include="Src\UpdatePackageCmdletTests.cs" />

7
src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/InvokeInitializePackagesCmdletTests.cs

@ -91,16 +91,15 @@ namespace PackageManagement.Cmdlets.Tests
} }
[Test] [Test]
public void ProcessRecord_SolutionHasPackageInitializationScripts_PowerShellWorkingDirectoryIsSetToSolutionDirectory() public void ProcessRecord_SolutionHasPackageInitializationScripts_PowerShellWorkingDirectoryIsUpdated()
{ {
CreateCmdlet(); CreateCmdlet();
SolutionHasPackageInitializationScripts(); fakeProjectService.OpenSolution = null;
fakeProjectService.OpenSolution.FileName = @"d:\projects\MySolution\MySolution.sln";
RunCmdlet(); RunCmdlet();
string commandExecuted = cmdlet.ScriptPassedToInvokeScript; string commandExecuted = cmdlet.ScriptPassedToInvokeScript;
string expectedCommandExecuted = @"Set-Location 'd:\projects\MySolution'"; string expectedCommandExecuted = @"Invoke-UpdateWorkingDirectory";
Assert.AreEqual(expectedCommandExecuted, commandExecuted); Assert.AreEqual(expectedCommandExecuted, commandExecuted);
} }

58
src/AddIns/Misc/PackageManagement/Cmdlets/Test/Src/InvokeUpdateWorkingDirectoryCmdletTests.cs

@ -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…
Cancel
Save