Browse Source

Fix exceptions thrown when PowerShell script writes to host.

pull/15/head
Matt Ward 15 years ago
parent
commit
9e2d9ff8b0
  1. 9
      src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PowerShellHostRawUserInterface.cs
  2. 34
      src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PowerShellHostUserInterfaceTests.cs

9
src/AddIns/Misc/PackageManagement/Project/Src/Scripting/PowerShellHostRawUserInterface.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.PackageManagement.Scripting
IScriptingConsole scriptingConsole; IScriptingConsole scriptingConsole;
public const int MinimumColumns = 80; public const int MinimumColumns = 80;
public static readonly ConsoleColor NoConsoleColor = (ConsoleColor)(-1);
public PowerShellHostRawUserInterface(IScriptingConsole scriptingConsole) public PowerShellHostRawUserInterface(IScriptingConsole scriptingConsole)
{ {
@ -85,8 +86,8 @@ namespace ICSharpCode.PackageManagement.Scripting
} }
public override ConsoleColor ForegroundColor { public override ConsoleColor ForegroundColor {
get { throw new NotImplementedException(); } get { return NoConsoleColor; }
set { throw new NotImplementedException(); } set { }
} }
public override void FlushInputBuffer() public override void FlushInputBuffer()
@ -105,8 +106,8 @@ namespace ICSharpCode.PackageManagement.Scripting
} }
public override ConsoleColor BackgroundColor { public override ConsoleColor BackgroundColor {
get { throw new NotImplementedException(); } get { return NoConsoleColor; }
set { throw new NotImplementedException(); } set { }
} }
} }
} }

34
src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PowerShellHostUserInterfaceTests.cs

@ -190,5 +190,39 @@ namespace PackageManagement.Tests.Scripting
Assert.AreEqual(expectedSize, actualSize); Assert.AreEqual(expectedSize, actualSize);
} }
[Test]
public void RawUIForegroundColor_SetForegroundColor_DoesNotThrowException()
{
CreateHostUserInterface();
Assert.DoesNotThrow(() => hostUI.RawUI.ForegroundColor = ConsoleColor.Black);
}
[Test]
public void RawUIForegroundColor_GetForegroundColor_ReturnsNoConsoleColor()
{
CreateHostUserInterface();
ConsoleColor color = hostUI.RawUI.ForegroundColor;
ConsoleColor expectedColor = PowerShellHostRawUserInterface.NoConsoleColor;
Assert.AreEqual(expectedColor, color);
}
[Test]
public void RawUIForegroundColor_SetBackgroundColor_DoesNotThrowException()
{
CreateHostUserInterface();
Assert.DoesNotThrow(() => hostUI.RawUI.BackgroundColor = ConsoleColor.Black);
}
[Test]
public void RawUIForegroundColor_GetBackgroundColor_ReturnsNoColor()
{
CreateHostUserInterface();
ConsoleColor color = hostUI.RawUI.BackgroundColor;
ConsoleColor expectedColor = PowerShellHostRawUserInterface.NoConsoleColor;
Assert.AreEqual(expectedColor, color);
}
} }
} }

Loading…
Cancel
Save