Skip to content

Commit 4303ed8

Browse files
authored
Add test for design binding picker (#13536)
<!-- Please read CONTRIBUTING.md before submitting a pull request --> Related #10773 ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/13536)
2 parents 233a074 + 48bcc26 commit 4303ed8

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
using System.Drawing;
5+
using static System.Windows.Forms.Design.DesignBindingPicker;
6+
7+
namespace System.Windows.Forms.Design.Tests;
8+
9+
public class DesignBindingPickerTests : IDisposable
10+
{
11+
private readonly DesignBindingPicker _picker;
12+
private readonly BindingPickerTree _treeViewCtrl;
13+
private readonly BindingPickerLink _addNewCtrl;
14+
private readonly Panel _addNewPanel;
15+
private readonly HelpTextLabel _helpTextCtrl;
16+
private readonly Panel _helpTextPanel;
17+
18+
public DesignBindingPickerTests()
19+
{
20+
_picker = new DesignBindingPicker();
21+
_treeViewCtrl = _picker.TestAccessor().Dynamic._treeViewCtrl;
22+
_addNewCtrl = _picker.TestAccessor().Dynamic._addNewCtrl;
23+
_addNewPanel = _picker.TestAccessor().Dynamic._addNewPanel;
24+
_helpTextCtrl = _picker.TestAccessor().Dynamic._helpTextCtrl;
25+
_helpTextPanel = _picker.TestAccessor().Dynamic._helpTextPanel;
26+
}
27+
28+
public void Dispose() => _picker.Dispose();
29+
30+
[WinFormsFact]
31+
public void Ctor_InitializesControlsAndProperties()
32+
{
33+
// Check control hierarchy.
34+
var controls = _picker.Controls;
35+
36+
controls.Contains(_treeViewCtrl).Should().BeTrue();
37+
controls.Contains(_addNewPanel).Should().BeTrue();
38+
controls.Contains(_helpTextPanel).Should().BeTrue();
39+
40+
// Check some property values.
41+
Assert.Equal(SystemColors.Control, _picker.BackColor);
42+
Assert.Equal(SR.DesignBindingPickerAccessibleName, _picker.AccessibleName);
43+
Assert.Equal(_treeViewCtrl, _picker.ActiveControl);
44+
}
45+
46+
[WinFormsFact]
47+
public void AddNewPanel_ContainsExpectedControls()
48+
{
49+
_addNewPanel.Controls.Contains(_addNewCtrl).Should().BeTrue();
50+
ContainsType<PictureBox>(_addNewPanel.Controls).Should().BeTrue();
51+
ContainsType<Label>(_addNewPanel.Controls).Should().BeTrue();
52+
}
53+
54+
[WinFormsFact]
55+
public void HelpTextPanel_ContainsExpectedControls()
56+
{
57+
_helpTextPanel.Controls.Contains(_helpTextCtrl).Should().BeTrue();
58+
ContainsType<Label>(_helpTextPanel.Controls).Should().BeTrue();
59+
}
60+
61+
private static bool ContainsType<T>(Control.ControlCollection collection)
62+
{
63+
foreach (var item in collection)
64+
{
65+
if (item is T)
66+
return true;
67+
}
68+
69+
return false;
70+
}
71+
}

0 commit comments

Comments
 (0)