Browse Source

Fix exceptions thrown when PowerShell script writes to host.

pull/15/head
Matt Ward 14 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 @@ -12,6 +12,7 @@ namespace ICSharpCode.PackageManagement.Scripting
IScriptingConsole scriptingConsole;
public const int MinimumColumns = 80;
public static readonly ConsoleColor NoConsoleColor = (ConsoleColor)(-1);
public PowerShellHostRawUserInterface(IScriptingConsole scriptingConsole)
{
@ -85,8 +86,8 @@ namespace ICSharpCode.PackageManagement.Scripting @@ -85,8 +86,8 @@ namespace ICSharpCode.PackageManagement.Scripting
}
public override ConsoleColor ForegroundColor {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
get { return NoConsoleColor; }
set { }
}
public override void FlushInputBuffer()
@ -105,8 +106,8 @@ namespace ICSharpCode.PackageManagement.Scripting @@ -105,8 +106,8 @@ namespace ICSharpCode.PackageManagement.Scripting
}
public override ConsoleColor BackgroundColor {
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
get { return NoConsoleColor; }
set { }
}
}
}

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

@ -190,5 +190,39 @@ namespace PackageManagement.Tests.Scripting @@ -190,5 +190,39 @@ namespace PackageManagement.Tests.Scripting
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