5 changed files with 96 additions and 0 deletions
@ -0,0 +1,33 @@ |
|||||||
|
// 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 ResetPowerShellWorkingDirectoryOnSolutionClosed |
||||||
|
{ |
||||||
|
IPackageManagementConsoleHost consoleHost; |
||||||
|
|
||||||
|
public ResetPowerShellWorkingDirectoryOnSolutionClosed( |
||||||
|
IPackageManagementProjectService projectService, |
||||||
|
IPackageManagementConsoleHost consoleHost) |
||||||
|
{ |
||||||
|
this.consoleHost = consoleHost; |
||||||
|
projectService.SolutionClosed += SolutionClosed; |
||||||
|
} |
||||||
|
|
||||||
|
void SolutionClosed(object sender, EventArgs e) |
||||||
|
{ |
||||||
|
if (consoleHost.IsRunning) { |
||||||
|
UpdateWorkingDirectory(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void UpdateWorkingDirectory() |
||||||
|
{ |
||||||
|
string command = "Invoke-UpdateWorkingDirectory"; |
||||||
|
consoleHost.ScriptingConsole.SendLine(command); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,59 @@ |
|||||||
|
// 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.Scripting.Tests.Utils; |
||||||
|
using NUnit.Framework; |
||||||
|
using PackageManagement.Tests.Helpers; |
||||||
|
|
||||||
|
namespace PackageManagement.Tests.Scripting |
||||||
|
{ |
||||||
|
[TestFixture] |
||||||
|
public class ResetPowerShellWorkingDirectoryOnSolutionClosedTests |
||||||
|
{ |
||||||
|
FakePackageManagementProjectService fakeProjectService; |
||||||
|
FakePackageManagementConsoleHost fakeConsoleHost; |
||||||
|
FakeScriptingConsole fakeScriptingConsole; |
||||||
|
ResetPowerShellWorkingDirectoryOnSolutionClosed reset; |
||||||
|
|
||||||
|
void CreateReset() |
||||||
|
{ |
||||||
|
fakeProjectService = new FakePackageManagementProjectService(); |
||||||
|
fakeConsoleHost = new FakePackageManagementConsoleHost(); |
||||||
|
fakeScriptingConsole = new FakeScriptingConsole(); |
||||||
|
fakeConsoleHost.ScriptingConsole = fakeScriptingConsole; |
||||||
|
reset = new ResetPowerShellWorkingDirectoryOnSolutionClosed(fakeProjectService, fakeConsoleHost); |
||||||
|
} |
||||||
|
|
||||||
|
bool IsWorkingDirectoryUpdated() |
||||||
|
{ |
||||||
|
return fakeScriptingConsole.AllTextPassedToSendLine.Contains("Invoke-UpdateWorkingDirectory"); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Instance_SolutionClosedWhenConsoleHostIsRunning_WorkingDirectoryIsUpdated() |
||||||
|
{ |
||||||
|
CreateReset(); |
||||||
|
fakeConsoleHost.IsRunning = true; |
||||||
|
fakeProjectService.FireSolutionClosedEvent(); |
||||||
|
|
||||||
|
bool workingDirectoryUpdated = IsWorkingDirectoryUpdated(); |
||||||
|
|
||||||
|
Assert.IsTrue(workingDirectoryUpdated); |
||||||
|
} |
||||||
|
|
||||||
|
[Test] |
||||||
|
public void Instance_SolutionClosedWhenConsoleHostIsNotRunning_WorkingDirectoryIsNotUpdated() |
||||||
|
{ |
||||||
|
CreateReset(); |
||||||
|
fakeConsoleHost.IsRunning = false; |
||||||
|
fakeProjectService.FireSolutionClosedEvent(); |
||||||
|
|
||||||
|
bool workingDirectoryUpdated = IsWorkingDirectoryUpdated(); |
||||||
|
|
||||||
|
Assert.IsFalse(workingDirectoryUpdated); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue