Skip to content

Commit 6cf92d3

Browse files
Amy-Li03Amy Li (BEYONDSOFT CONSULTING INC)
andauthored
Add unit test for CheckBoxPopupAdapter (#13755)
* add unittest for checkBoxPopupAdapter * little update --------- Co-authored-by: Amy Li (BEYONDSOFT CONSULTING INC) <[email protected]>
1 parent dc3d956 commit 6cf92d3

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#nullable disable
5+
6+
using System.Drawing;
7+
using System.Windows.Forms.ButtonInternal;
8+
using static System.Windows.Forms.ButtonInternal.ButtonBaseAdapter;
9+
10+
namespace System.Windows.Forms.Tests;
11+
12+
public class CheckBoxPopupAdapterTests : AbstractButtonBaseTests
13+
{
14+
[WinFormsTheory]
15+
[InlineData(CheckState.Unchecked)]
16+
[InlineData(CheckState.Checked)]
17+
[InlineData(CheckState.Indeterminate)]
18+
public void PaintUp_DoesNotThrow_ForAllCheckStates(CheckState state)
19+
{
20+
using CheckBox checkBox = new();
21+
CheckBoxPopupAdapter adapter = new(checkBox);
22+
using Bitmap bitmap = new(checkBox.Width, checkBox.Height);
23+
using Graphics graphics = Graphics.FromImage(bitmap);
24+
PaintEventArgs e = new(graphics, checkBox.ClientRectangle);
25+
26+
Action action = () => adapter.PaintUp(e, state);
27+
28+
action.Should().NotThrow();
29+
}
30+
31+
[WinFormsTheory]
32+
[InlineData(CheckState.Unchecked)]
33+
[InlineData(CheckState.Checked)]
34+
[InlineData(CheckState.Indeterminate)]
35+
public void PaintOver_DoesNotThrow_ForAllCheckStates(CheckState state)
36+
{
37+
using CheckBox checkBox = new();
38+
checkBox.Text = "Test";
39+
CheckBoxPopupAdapter adapter = new(checkBox);
40+
using Bitmap bitmap = new(checkBox.Width, checkBox.Height);
41+
using Graphics graphics = Graphics.FromImage(bitmap);
42+
PaintEventArgs e = new(graphics, checkBox.ClientRectangle);
43+
44+
Action action = () => adapter.PaintOver(e, state);
45+
46+
action.Should().NotThrow();
47+
}
48+
49+
[WinFormsTheory]
50+
[InlineData(CheckState.Unchecked)]
51+
[InlineData(CheckState.Checked)]
52+
[InlineData(CheckState.Indeterminate)]
53+
public void PaintDown_DoesNotThrow_ForAllCheckStates(CheckState state)
54+
{
55+
using CheckBox checkBox = new();
56+
checkBox.Text = "Test";
57+
CheckBoxPopupAdapter adapter = new(checkBox);
58+
using Bitmap bitmap = new(checkBox.Width, checkBox.Height);
59+
using Graphics graphics = Graphics.FromImage(bitmap);
60+
PaintEventArgs e = new(graphics, checkBox.ClientRectangle);
61+
62+
Action action = () => adapter.PaintDown(e, state);
63+
64+
action.Should().NotThrow();
65+
}
66+
67+
[WinFormsFact]
68+
public void Layout_DoesNotThrow_WhenInvokedViaTestAccessor()
69+
{
70+
using CheckBox checkBox = new();
71+
CheckBoxPopupAdapter adapter = new(checkBox);
72+
using Bitmap bitmap = new(checkBox.Width, checkBox.Height);
73+
using Graphics graphics = Graphics.FromImage(bitmap);
74+
PaintEventArgs e = new(graphics, checkBox.ClientRectangle);
75+
76+
Action action = () => adapter.TestAccessor().Dynamic.Layout(e);
77+
78+
action.Should().NotThrow();
79+
}
80+
81+
[WinFormsFact]
82+
public void CreateButtonAdapter_DoesNotThrow_WhenInvokedViaTestAccessor()
83+
{
84+
using CheckBox checkBox = new();
85+
CheckBoxPopupAdapter adapter = new(checkBox);
86+
87+
Action action = () => adapter.TestAccessor().Dynamic.CreateButtonAdapter();
88+
89+
action.Should().NotThrow();
90+
}
91+
92+
[WinFormsTheory]
93+
[InlineData(true, 11, 50, 20, 2, false, "First Test", true, ContentAlignment.MiddleLeft, RightToLeft.No)]
94+
[InlineData(false, 15, 100, 40, 4, true, "Sec Test", false, ContentAlignment.TopRight, RightToLeft.Yes)]
95+
public void PaintPopupLayout_Static_Properties_AreSet(
96+
bool show3D,
97+
int checkSize,
98+
int width,
99+
int height,
100+
int paddingValue,
101+
bool isDefault,
102+
string text,
103+
bool enabled,
104+
ContentAlignment textAlign,
105+
RightToLeft rtl)
106+
{
107+
Rectangle clientRect = new(0, 0, width, height);
108+
Padding padding = new(paddingValue);
109+
using Font font = SystemFonts.DefaultFont;
110+
111+
LayoutOptions layout = CheckBoxPopupAdapter.PaintPopupLayout(
112+
show3D,
113+
checkSize,
114+
clientRect,
115+
padding,
116+
isDefault,
117+
font,
118+
text,
119+
enabled,
120+
textAlign,
121+
rtl);
122+
123+
layout.Should().NotBeNull();
124+
layout.CheckSize.Should().BeGreaterThan(0);
125+
layout.ShadowedText.Should().BeFalse();
126+
}
127+
128+
protected override ButtonBase CreateButton() => new CheckBox();
129+
}

0 commit comments

Comments
 (0)