Skip to content

Commit 8f4c5b8

Browse files
committed
Add tests for DesignBindingPicker
1 parent 4c32f29 commit 8f4c5b8

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+
[Fact]
31+
public void Ctor_InitializesControlsAndProperties()
32+
{
33+
// Check control hierarchy
34+
var controls = _picker.Controls;
35+
controls.Contains(_treeViewCtrl).Should().BeTrue();
36+
controls.Contains(_addNewPanel).Should().BeTrue();
37+
controls.Contains(_helpTextPanel).Should().BeTrue();
38+
39+
// Check some property values
40+
Assert.Equal(SystemColors.Control, _picker.BackColor);
41+
Assert.Equal(SR.DesignBindingPickerAccessibleName, _picker.AccessibleName);
42+
Assert.Equal(_treeViewCtrl, _picker.ActiveControl);
43+
}
44+
45+
[Fact]
46+
public void AddNewPanel_ContainsExpectedControls()
47+
{
48+
_addNewPanel.Controls.Contains(_addNewCtrl).Should().BeTrue();
49+
ContainsType<PictureBox>(_addNewPanel.Controls).Should().BeTrue();
50+
ContainsType<Label>(_addNewPanel.Controls).Should().BeTrue();
51+
}
52+
53+
[Fact]
54+
public void HelpTextPanel_ContainsExpectedControls()
55+
{
56+
_helpTextPanel.Controls.Contains(_helpTextCtrl).Should().BeTrue();
57+
ContainsType<Label>(_helpTextPanel.Controls).Should().BeTrue();
58+
}
59+
60+
// Add the following extension method to replace the missing 'ContainsType' functionality.
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)