-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelsTests.cs
More file actions
266 lines (232 loc) · 6.59 KB
/
ModelsTests.cs
File metadata and controls
266 lines (232 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// Copyright (c) ktsu.dev
// All rights reserved.
// Licensed under the MIT license.
namespace ktsu.TUI.Test;
using System.Drawing;
using ktsu.TUI.Core.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// Tests for TUI Core Models
/// </summary>
[TestClass]
public sealed class ModelsTests
{
/// <summary>
/// Tests Position constructor and properties
/// </summary>
[TestMethod]
public void PositionConstructorSetsProperties()
{
// Arrange & Act
Position position = new(10, 20);
// Assert
Assert.AreEqual(10, position.X);
Assert.AreEqual(20, position.Y);
}
/// <summary>
/// Tests Position equality
/// </summary>
[TestMethod]
public void PositionEqualityWorksCorrectly()
{
// Arrange
Position position1 = new(10, 20);
Position position2 = new(10, 20);
Position position3 = new(15, 25);
// Act & Assert
Assert.AreEqual(position1, position2);
Assert.AreNotEqual(position1, position3);
Assert.IsTrue(position1 == position2, "Position equality operator should return true for equal positions");
Assert.IsTrue(position1 != position3, "Position inequality operator should return true for different positions");
}
/// <summary>
/// Tests Position Offset method
/// </summary>
[TestMethod]
public void PositionOffsetReturnsNewPosition()
{
// Arrange
Position position = new(10, 20);
// Act
Position offsetPosition = position.Offset(5, 3);
// Assert
Assert.AreEqual(15, offsetPosition.X);
Assert.AreEqual(23, offsetPosition.Y);
// Original position should be unchanged
Assert.AreEqual(10, position.X);
Assert.AreEqual(20, position.Y);
}
/// <summary>
/// Tests Dimensions constructor and properties
/// </summary>
[TestMethod]
public void DimensionsConstructorSetsProperties()
{
// Arrange & Act
Dimensions dimensions = new(100, 50);
// Assert
Assert.AreEqual(100, dimensions.Width);
Assert.AreEqual(50, dimensions.Height);
}
/// <summary>
/// Tests Dimensions Empty property
/// </summary>
[TestMethod]
public void DimensionsEmptyReturnsZeroDimensions()
{
// Act
Dimensions empty = Dimensions.Empty;
// Assert
Assert.AreEqual(0, empty.Width);
Assert.AreEqual(0, empty.Height);
}
/// <summary>
/// Tests Dimensions IsEmpty property
/// </summary>
[TestMethod]
public void DimensionsIsEmptyDetectsEmptyCorrectly()
{
// Arrange
Dimensions empty = new(0, 0);
Dimensions notEmpty = new(10, 5);
// Assert
Assert.IsTrue(empty.IsEmpty, "Dimensions with zero width and height should be empty");
Assert.IsFalse(notEmpty.IsEmpty, "Dimensions with non-zero width and height should not be empty");
}
/// <summary>
/// Tests TextStyle default constructor
/// </summary>
[TestMethod]
public void TextStyleDefaultConstructorSetsDefaults()
{
// Act
TextStyle style = new();
// Assert
Assert.IsFalse(style.IsBold, "Default TextStyle should not be bold");
Assert.IsFalse(style.IsItalic, "Default TextStyle should not be italic");
Assert.IsFalse(style.IsUnderline, "Default TextStyle should not be underlined");
Assert.IsFalse(style.IsStrikethrough, "Default TextStyle should not be strikethrough");
Assert.IsNull(style.Foreground);
Assert.IsNull(style.Background);
}
/// <summary>
/// Tests TextStyle with all properties set
/// </summary>
[TestMethod]
public void TextStyleAllPropertiesSetCorrectly()
{
// Arrange & Act
TextStyle style = new()
{
IsBold = true,
IsItalic = true,
IsUnderline = true,
IsStrikethrough = true,
Foreground = "red",
Background = "blue"
};
// Assert
Assert.IsTrue(style.IsBold, "TextStyle IsBold should be true when set");
Assert.IsTrue(style.IsItalic, "TextStyle IsItalic should be true when set");
Assert.IsTrue(style.IsUnderline, "TextStyle IsUnderline should be true when set");
Assert.IsTrue(style.IsStrikethrough, "TextStyle IsStrikethrough should be true when set");
// Color.FromName("red") returns Color.Red, which has Name = "Red"
Assert.AreEqual("Red", style.Foreground);
Assert.AreEqual("Blue", style.Background);
}
/// <summary>
/// Tests TextStyle with color values
/// </summary>
[TestMethod]
public void TextStyleColorPropertiesWorkWithColorValues()
{
// Arrange
Color foregroundColor = Color.Red;
Color backgroundColor = Color.Blue;
// Act
TextStyle style = new()
{
ForegroundColor = foregroundColor,
BackgroundColor = backgroundColor
};
// Assert
Assert.AreEqual(foregroundColor, style.ForegroundColor);
Assert.AreEqual(backgroundColor, style.BackgroundColor);
}
/// <summary>
/// Tests Padding uniform constructor
/// </summary>
[TestMethod]
public void PaddingUniformConstructorSetsAllSides()
{
// Act
Padding padding = Padding.Uniform(5);
// Assert
Assert.AreEqual(5, padding.Left);
Assert.AreEqual(5, padding.Top);
Assert.AreEqual(5, padding.Right);
Assert.AreEqual(5, padding.Bottom);
}
/// <summary>
/// Tests Padding individual sides constructor
/// </summary>
[TestMethod]
public void PaddingIndividualSidesConstructorSetsSides()
{
// Act
Padding padding = new(1, 2, 3, 4);
// Assert
Assert.AreEqual(1, padding.Left);
Assert.AreEqual(2, padding.Top);
Assert.AreEqual(3, padding.Right);
Assert.AreEqual(4, padding.Bottom);
}
/// <summary>
/// Tests InputResult creation methods
/// </summary>
[TestMethod]
public void InputResultCreationMethodsWorkCorrectly()
{
// Act
InputResult exitInput = InputResult.Exit();
InputResult keyInput = InputResult.FromKey(ConsoleKey.Enter, InputModifiers.None);
// Assert
Assert.IsTrue(exitInput.IsExit, "InputResult.Exit() should return an input with IsExit set to true");
Assert.AreEqual(InputType.Keyboard, keyInput.Type);
Assert.AreEqual(ConsoleKey.Enter, keyInput.Key);
Assert.AreEqual(InputModifiers.None, keyInput.Modifiers);
}
/// <summary>
/// Tests InputModifiers enum values
/// </summary>
[TestMethod]
public void InputModifiersEnumValuesAreValid()
{
// Test each enum value
ConsoleModifiers[] modifiers = [InputModifiers.None, InputModifiers.Shift, InputModifiers.Control, InputModifiers.Alt];
foreach (ConsoleModifiers modifier in modifiers)
{
// Act
InputResult input = InputResult.FromKey(ConsoleKey.A, modifier);
// Assert
Assert.AreEqual(modifier, input.Modifiers);
}
}
/// <summary>
/// Tests InputType enum values
/// </summary>
[TestMethod]
public void InputTypeEnumValuesAreValid()
{
// Test each enum value
InputType[] inputTypes = [InputType.None, InputType.Keyboard, InputType.Mouse];
foreach (InputType inputType in inputTypes)
{
// Arrange
InputResult input = new()
{ Type = inputType };
// Act & Assert
Assert.AreEqual(inputType, input.Type);
}
}
}