~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/PackageManagement/Test/Src/Scripting/PowerShellHostUserInterfaceTests.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
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;
 
11
 
 
12
namespace PackageManagement.Tests.Scripting
 
13
{
 
14
        [TestFixture]
 
15
        public class PowerShellHostUserInterfaceTests
 
16
        {
 
17
                PowerShellHostUserInterface hostUI;
 
18
                FakeScriptingConsole scriptingConsole;
 
19
                
 
20
                void CreateHostUserInterface()
 
21
                {
 
22
                        scriptingConsole = new FakeScriptingConsole();
 
23
                        hostUI = new PowerShellHostUserInterface(scriptingConsole);
 
24
                }
 
25
                
 
26
                [Test]
 
27
                public void WriteWarningLine_ShowWarningMessage_MessageWrittenToConsole()
 
28
                {
 
29
                        CreateHostUserInterface();
 
30
                        hostUI.WriteWarningLine("Test");
 
31
                        
 
32
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
 
33
                }
 
34
                
 
35
                [Test]
 
36
                public void WriteWarningLine_ShowWarningMessage_ScriptingStyleIsWarning()
 
37
                {
 
38
                        CreateHostUserInterface();
 
39
                        hostUI.WriteWarningLine("Test");
 
40
                        
 
41
                        Assert.AreEqual(ScriptingStyle.Warning, scriptingConsole.ScriptingStylePassedToWriteLine);
 
42
                }
 
43
                
 
44
                [Test]
 
45
                public void WriteVerboseLine_ShowVerboseMessage_MessageWrittenToConsole()
 
46
                {
 
47
                        CreateHostUserInterface();
 
48
                        hostUI.WriteVerboseLine("Test");
 
49
                        
 
50
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
 
51
                }
 
52
                
 
53
                [Test]
 
54
                public void WriteVerboseLine_ShowVerboseMessage_ScriptingStyleIsOut()
 
55
                {
 
56
                        CreateHostUserInterface();
 
57
                        hostUI.WriteVerboseLine("Test");
 
58
                        
 
59
                        Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine);
 
60
                }
 
61
                
 
62
                [Test]
 
63
                public void WriteLine_ShowMessage_MessageWrittenToConsole()
 
64
                {
 
65
                        CreateHostUserInterface();
 
66
                        hostUI.WriteLine("Test");
 
67
                        
 
68
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
 
69
                }
 
70
                
 
71
                [Test]
 
72
                public void WriteLine_ShowMessage_ScriptingStyleIsOut()
 
73
                {
 
74
                        CreateHostUserInterface();
 
75
                        hostUI.WriteLine("Test");
 
76
                        
 
77
                        Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine);
 
78
                }
 
79
                
 
80
                [Test]
 
81
                public void WriteErrorLine_ShowErrorMessage_MessageWrittenToConsole()
 
82
                {
 
83
                        CreateHostUserInterface();
 
84
                        hostUI.WriteErrorLine("Test");
 
85
                        
 
86
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
 
87
                }
 
88
                
 
89
                [Test]
 
90
                public void WriteErrorLine_ShowErrorMessage_ScriptingStyleIsError()
 
91
                {
 
92
                        CreateHostUserInterface();
 
93
                        hostUI.WriteErrorLine("Test");
 
94
                        
 
95
                        Assert.AreEqual(ScriptingStyle.Error, scriptingConsole.ScriptingStylePassedToWriteLine);
 
96
                }
 
97
                
 
98
                [Test]
 
99
                public void WriteDebugLine_ShowMessage_MessageWrittenToConsole()
 
100
                {
 
101
                        CreateHostUserInterface();
 
102
                        hostUI.WriteDebugLine("Test");
 
103
                        
 
104
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWriteLine);
 
105
                }
 
106
                
 
107
                [Test]
 
108
                public void WriteDebugLine_ShowMessage_ScriptingStyleIsOut()
 
109
                {
 
110
                        CreateHostUserInterface();
 
111
                        hostUI.WriteDebugLine("Test");
 
112
                        
 
113
                        Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWriteLine);
 
114
                }
 
115
                
 
116
                [Test]
 
117
                public void Write_ShowMessage_MessageWrittenToConsole()
 
118
                {
 
119
                        CreateHostUserInterface();
 
120
                        hostUI.Write("Test");
 
121
                        
 
122
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWrite);
 
123
                }
 
124
                
 
125
                [Test]
 
126
                public void Write_ShowMessage_ScriptingStyleIsOut()
 
127
                {
 
128
                        CreateHostUserInterface();
 
129
                        hostUI.Write("Test");
 
130
                        
 
131
                        Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWrite);
 
132
                }
 
133
                
 
134
                [Test]
 
135
                public void Write_ConsoleColorsSpecified_MessageWrittenToConsole()
 
136
                {
 
137
                        CreateHostUserInterface();
 
138
                        hostUI.Write(ConsoleColor.Black, ConsoleColor.Red, "Test");
 
139
                        
 
140
                        Assert.AreEqual("Test", scriptingConsole.TextPassedToWrite);
 
141
                }
 
142
                
 
143
                [Test]
 
144
                public void Write_ConsoleColorsSpecified_ScriptingStyleIsOut()
 
145
                {
 
146
                        CreateHostUserInterface();
 
147
                        hostUI.Write(ConsoleColor.Black, ConsoleColor.Red, "Test");
 
148
                        
 
149
                        Assert.AreEqual(ScriptingStyle.Out, scriptingConsole.ScriptingStylePassedToWrite);
 
150
                }
 
151
                
 
152
                [Test]
 
153
                public void PromptForChoice_NoChoices_ReturnsMinusOne()
 
154
                {
 
155
                        CreateHostUserInterface();
 
156
                        var choices = new Collection<ChoiceDescription>();
 
157
                        int result = hostUI.PromptForChoice("caption", "message", choices, 2);
 
158
                        
 
159
                        Assert.AreEqual(-1, result);
 
160
                }
 
161
                
 
162
                [Test]
 
163
                public void RawUIBufferSize_ScriptingConsoleHas90MaximumVisibleColumns_ReturnsSizeWithWidthOf90()
 
164
                {
 
165
                        CreateHostUserInterface();
 
166
                        scriptingConsole.MaximumVisibleColumns = 90;
 
167
                        
 
168
                        Size actualSize = hostUI.RawUI.BufferSize;
 
169
                        
 
170
                        Size expectedSize = new Size() {
 
171
                                Width = 90,
 
172
                                Height = 0
 
173
                        };
 
174
                        
 
175
                        Assert.AreEqual(expectedSize, actualSize);
 
176
                }
 
177
                
 
178
                [Test]
 
179
                public void RawUIBufferSize_ScriptingConsoleHas79MaxVisibleColumns_ReturnsSizeWithMinimumWidthOf80()
 
180
                {
 
181
                        CreateHostUserInterface();
 
182
                        scriptingConsole.MaximumVisibleColumns = 79;
 
183
                        
 
184
                        Size actualSize = hostUI.RawUI.BufferSize;
 
185
                        
 
186
                        Size expectedSize = new Size() {
 
187
                                Width = 80,
 
188
                                Height = 0
 
189
                        };
 
190
                        
 
191
                        Assert.AreEqual(expectedSize, actualSize);
 
192
                }
 
193
                
 
194
                [Test]
 
195
                public void RawUIForegroundColor_SetForegroundColor_DoesNotThrowException()
 
196
                {
 
197
                        CreateHostUserInterface();
 
198
                        Assert.DoesNotThrow(() => hostUI.RawUI.ForegroundColor = ConsoleColor.Black);
 
199
                }
 
200
                
 
201
                [Test]
 
202
                public void RawUIForegroundColor_GetForegroundColor_ReturnsNoConsoleColor()
 
203
                {
 
204
                        CreateHostUserInterface();
 
205
                        ConsoleColor color = hostUI.RawUI.ForegroundColor;
 
206
                        ConsoleColor expectedColor = PowerShellHostRawUserInterface.NoConsoleColor;
 
207
                        
 
208
                        Assert.AreEqual(expectedColor, color);
 
209
                }
 
210
                
 
211
                [Test]
 
212
                public void RawUIForegroundColor_SetBackgroundColor_DoesNotThrowException()
 
213
                {
 
214
                        CreateHostUserInterface();
 
215
                        Assert.DoesNotThrow(() => hostUI.RawUI.BackgroundColor = ConsoleColor.Black);
 
216
                }
 
217
                
 
218
                [Test]
 
219
                public void RawUIForegroundColor_GetBackgroundColor_ReturnsNoColor()
 
220
                {
 
221
                        CreateHostUserInterface();
 
222
                        ConsoleColor color = hostUI.RawUI.BackgroundColor;
 
223
                        ConsoleColor expectedColor = PowerShellHostRawUserInterface.NoConsoleColor;
 
224
                        
 
225
                        Assert.AreEqual(expectedColor, color);
 
226
                }
 
227
        }
 
228
}