1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.ObjectModel;
6
using System.Management.Automation.Host;
7
using ICSharpCode.PackageManagement.Scripting;
8
using ICSharpCode.Scripting;
9
using ICSharpCode.Scripting.Tests.Utils;
10
using NUnit.Framework;
12
namespace PackageManagement.Tests.Scripting
15
public class PowerShellHostUserInterfaceTests
17
PowerShellHostUserInterface hostUI;
18
FakeScriptingConsole scriptingConsole;
20
void CreateHostUserInterface()
22
scriptingConsole = new FakeScriptingConsole();
23
hostUI = new PowerShellHostUserInterface(scriptingConsole);
27
public void WriteWarningLine_ShowWarningMessage_MessageWrittenToConsole()
29
CreateHostUserInterface();
30
hostUI.WriteWarningLine("Test");
32
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
36
public void WriteWarningLine_ShowWarningMessage_ScriptingStyleIsWarning()
38
CreateHostUserInterface();
39
hostUI.WriteWarningLine("Test");
41
Assert.AreEqual(ScriptingStyle.Warning, scriptingConsole.ScriptingStylePassedToWriteLine);
45
public void WriteVerboseLine_ShowVerboseMessage_MessageWrittenToConsole()
47
CreateHostUserInterface();
48
hostUI.WriteVerboseLine("Test");
50
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
54
public void WriteVerboseLine_ShowVerboseMessage_ScriptingStyleIsOut()
56
CreateHostUserInterface();
57
hostUI.WriteVerboseLine("Test");
59
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine);
63
public void WriteLine_ShowMessage_MessageWrittenToConsole()
65
CreateHostUserInterface();
66
hostUI.WriteLine("Test");
68
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
72
public void WriteLine_ShowMessage_ScriptingStyleIsOut()
74
CreateHostUserInterface();
75
hostUI.WriteLine("Test");
77
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine);
81
public void WriteErrorLine_ShowErrorMessage_MessageWrittenToConsole()
83
CreateHostUserInterface();
84
hostUI.WriteErrorLine("Test");
86
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
90
public void WriteErrorLine_ShowErrorMessage_ScriptingStyleIsError()
92
CreateHostUserInterface();
93
hostUI.WriteErrorLine("Test");
95
Assert.AreEqual(ScriptingStyle.Error, scriptingConsole.ScriptingStylePassedToWriteLine);
99
public void WriteDebugLine_ShowMessage_MessageWrittenToConsole()
101
CreateHostUserInterface();
102
hostUI.WriteDebugLine("Test");
104
Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
108
public void WriteDebugLine_ShowMessage_ScriptingStyleIsOut()
110
CreateHostUserInterface();
111
hostUI.WriteDebugLine("Test");
113
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine);
117
public void Write_ShowMessage_MessageWrittenToConsole()
119
CreateHostUserInterface();
120
hostUI.Write("Test");
122
Assert.AreEqual("Test", scriptingConsole.TextPassedToWrite);
126
public void Write_ShowMessage_ScriptingStyleIsOut()
128
CreateHostUserInterface();
129
hostUI.Write("Test");
131
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWrite);
135
public void Write_ConsoleColorsSpecified_MessageWrittenToConsole()
137
CreateHostUserInterface();
138
hostUI.Write(ConsoleColor.Black, ConsoleColor.Red, "Test");
140
Assert.AreEqual("Test", scriptingConsole.TextPassedToWrite);
144
public void Write_ConsoleColorsSpecified_ScriptingStyleIsOut()
146
CreateHostUserInterface();
147
hostUI.Write(ConsoleColor.Black, ConsoleColor.Red, "Test");
149
Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWrite);
153
public void PromptForChoice_NoChoices_ReturnsMinusOne()
155
CreateHostUserInterface();
156
var choices = new Collection<ChoiceDescription>();
157
int result = hostUI.PromptForChoice("caption", "message", choices, 2);
159
Assert.AreEqual(-1, result);
163
public void RawUIBufferSize_ScriptingConsoleHas90MaximumVisibleColumns_ReturnsSizeWithWidthOf90()
165
CreateHostUserInterface();
166
scriptingConsole.MaximumVisibleColumns = 90;
168
Size actualSize = hostUI.RawUI.BufferSize;
170
Size expectedSize = new Size() {
175
Assert.AreEqual(expectedSize, actualSize);
179
public void RawUIBufferSize_ScriptingConsoleHas79MaxVisibleColumns_ReturnsSizeWithMinimumWidthOf80()
181
CreateHostUserInterface();
182
scriptingConsole.MaximumVisibleColumns = 79;
184
Size actualSize = hostUI.RawUI.BufferSize;
186
Size expectedSize = new Size() {
191
Assert.AreEqual(expectedSize, actualSize);
195
public void RawUIForegroundColor_SetForegroundColor_DoesNotThrowException()
197
CreateHostUserInterface();
198
Assert.DoesNotThrow(() => hostUI.RawUI.ForegroundColor = ConsoleColor.Black);
202
public void RawUIForegroundColor_GetForegroundColor_ReturnsNoConsoleColor()
204
CreateHostUserInterface();
205
ConsoleColor color = hostUI.RawUI.ForegroundColor;
206
ConsoleColor expectedColor = PowerShellHostRawUserInterface.NoConsoleColor;
208
Assert.AreEqual(expectedColor, color);
212
public void RawUIForegroundColor_SetBackgroundColor_DoesNotThrowException()
214
CreateHostUserInterface();
215
Assert.DoesNotThrow(() => hostUI.RawUI.BackgroundColor = ConsoleColor.Black);
219
public void RawUIForegroundColor_GetBackgroundColor_ReturnsNoColor()
221
CreateHostUserInterface();
222
ConsoleColor color = hostUI.RawUI.BackgroundColor;
223
ConsoleColor expectedColor = PowerShellHostRawUserInterface.NoConsoleColor;
225
Assert.AreEqual(expectedColor, color);