Skip to content

Commit 4ab58b0

Browse files
authored
Add test coverage for DateTimePicker (#11033)
* Add unit test cases for DateTimePicker * Updated test cases
1 parent 7de21be commit 4ab58b0

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DateTimePickerTests.cs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,143 @@ public void DateTimePicker_Format_SetInvalid_ThrowsInvalidEnumArgumentException(
161161
Assert.Throws<InvalidEnumArgumentException>("value", () => control.Format = value);
162162
}
163163

164+
[WinFormsFact]
165+
public void DateTimePicker_CalendarTitleBackColor_GetSet_ReturnsExpected()
166+
{
167+
using DateTimePicker control = new();
168+
var expectedColor = Color.Red;
169+
170+
control.CalendarTitleBackColor = expectedColor;
171+
172+
control.CalendarTitleBackColor.Should().Be(expectedColor);
173+
}
174+
175+
[WinFormsTheory]
176+
[InlineData(null)]
177+
[InlineData("")]
178+
[InlineData("invalid color")]
179+
public void DateTimePicker_CalendarTitleBackColor_SetInvalid_ThrowsArgumentException(string value)
180+
{
181+
using DateTimePicker control = new();
182+
Action act = () => control.CalendarTitleBackColor = ColorTranslator.FromHtml(value);
183+
act.Should().Throw<ArgumentException>();
184+
}
185+
186+
[WinFormsFact]
187+
public void DateTimePicker_CalendarForeColor_GetSet_ReturnsExpected()
188+
{
189+
using DateTimePicker control = new();
190+
var expectedColor = Color.Red;
191+
192+
control.CalendarForeColor = expectedColor;
193+
194+
control.CalendarForeColor.Should().Be(expectedColor);
195+
}
196+
197+
[WinFormsTheory]
198+
[InlineData(null)]
199+
[InlineData("")]
200+
[InlineData("invalid color")]
201+
public void DateTimePicker_CalendarForeColor_SetInvalid_ThrowsArgumentException(string value)
202+
{
203+
using DateTimePicker control = new();
204+
Action act = () => control.CalendarForeColor = ColorTranslator.FromHtml(value);
205+
act.Should().Throw<ArgumentException>();
206+
}
207+
208+
[WinFormsFact]
209+
public void DateTimePicker_CalendarTitleForeColor_GetSet_ReturnsExpected()
210+
{
211+
using DateTimePicker control = new();
212+
var expectedColor = Color.Red;
213+
214+
control.CalendarTitleForeColor = expectedColor;
215+
216+
control.CalendarTitleForeColor.Should().Be(expectedColor);
217+
}
218+
219+
[WinFormsTheory]
220+
[InlineData(null)]
221+
[InlineData("")]
222+
[InlineData("invalid color")]
223+
public void DateTimePicker_CalendarTitleForeColor_SetInvalid_ThrowsArgumentException(string value)
224+
{
225+
using DateTimePicker control = new();
226+
Action act = () => control.CalendarTitleForeColor = ColorTranslator.FromHtml(value);
227+
act.Should().Throw<ArgumentException>();
228+
}
229+
230+
[WinFormsFact]
231+
public void DateTimePicker_CalendarTrailingForeColor_GetSet_ReturnsExpected()
232+
{
233+
using DateTimePicker control = new();
234+
var expectedColor = Color.Red;
235+
236+
control.CalendarTrailingForeColor = expectedColor;
237+
238+
control.CalendarTrailingForeColor.Should().Be(expectedColor);
239+
}
240+
241+
[WinFormsTheory]
242+
[InlineData(null)]
243+
[InlineData("")]
244+
[InlineData("invalid color")]
245+
public void DateTimePicker_CalendarTrailingForeColor_SetInvalid_ThrowsArgumentException(string value)
246+
{
247+
using DateTimePicker control = new();
248+
Action act = () => control.CalendarTrailingForeColor = ColorTranslator.FromHtml(value);
249+
act.Should().Throw<ArgumentException>();
250+
}
251+
252+
[WinFormsFact]
253+
public void DateTimePicker_CalendarMonthBackground_GetSet_ReturnsExpected()
254+
{
255+
using DateTimePicker control = new();
256+
var expectedColor = Color.Red;
257+
258+
control.CalendarMonthBackground = expectedColor;
259+
260+
control.CalendarMonthBackground.Should().Be(expectedColor);
261+
}
262+
263+
[WinFormsTheory]
264+
[InlineData(null)]
265+
[InlineData("")]
266+
[InlineData("invalid color")]
267+
public void DateTimePicker_CalendarMonthBackground_SetInvalid_ThrowsArgumentException(string value)
268+
{
269+
using DateTimePicker control = new();
270+
Action act = () => control.CalendarMonthBackground = ColorTranslator.FromHtml(value);
271+
act.Should().Throw<ArgumentException>();
272+
}
273+
274+
[WinFormsFact]
275+
public void DateTimePicker_BackColorChangedEvent_Raised_Success()
276+
{
277+
using DateTimePicker control = new();
278+
bool eventWasRaised = false;
279+
280+
control.BackColorChanged += (sender, args) => eventWasRaised = true;
281+
control.BackColor = Color.Red;
282+
283+
eventWasRaised.Should().BeTrue();
284+
}
285+
286+
[WinFormsFact]
287+
public void DateTimePicker_BackgroundImageChangedEvent_Raised_Success()
288+
{
289+
using DateTimePicker control = new();
290+
bool eventWasRaised = false;
291+
292+
control.BackgroundImageChanged += (sender, args) => eventWasRaised = true;
293+
using (Bitmap bmp = new Bitmap(10, 10))
294+
{
295+
control.BackgroundImage = bmp;
296+
}
297+
298+
eventWasRaised.Should().BeTrue();
299+
}
300+
164301
[WinFormsTheory]
165302
[InlineData(ControlStyles.ContainerControl, false)]
166303
[InlineData(ControlStyles.UserPaint, false)]

0 commit comments

Comments
 (0)