Skip to content

Commit 4055829

Browse files
authored
Add unit test for ListControlUnboundActionList (#12770)
Related #10773 Proposed changes Add unit test ListControlUnboundActionListTests.cs for public properties and methods of the ListControlUnboundActionList. Enable nullability in ListControlUnboundActionListTests.cs.
1 parent 3b8e1a6 commit 4055829

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 enable
5+
6+
using System.ComponentModel;
7+
using System.ComponentModel.Design;
8+
using Moq;
9+
10+
namespace System.Windows.Forms.Design.Tests;
11+
12+
public sealed class ListControlUnboundActionListTests : IDisposable
13+
{
14+
private readonly ComponentDesigner _designer;
15+
private readonly Mock<IComponent> _componentMock;
16+
private readonly ListControlUnboundActionList _actionList;
17+
18+
public ListControlUnboundActionListTests()
19+
{
20+
_designer = new();
21+
_componentMock = new();
22+
_designer.Initialize(_componentMock.Object);
23+
_actionList = new(_designer);
24+
}
25+
26+
public void Dispose() => _designer.Dispose();
27+
28+
[Fact]
29+
public void Constructor_ShouldInitializeDesigner() => _actionList.Should().NotBeNull();
30+
31+
[Fact]
32+
public void GetSortedActionItems_ShouldReturnCorrectItems()
33+
{
34+
DesignerActionItemCollection items = _actionList.GetSortedActionItems();
35+
36+
items.Should().NotBeNull();
37+
items.Count.Should().Be(1);
38+
items[0].Should().BeOfType<DesignerActionMethodItem>();
39+
DesignerActionMethodItem methodItem = (DesignerActionMethodItem)items[0];
40+
methodItem.DisplayName.Should().Be(SR.ListControlUnboundActionListEditItemsDisplayName);
41+
methodItem.Category.Should().Be(SR.ItemsCategoryName);
42+
methodItem.Description.Should().Be(SR.ListControlUnboundActionListEditItemsDescription);
43+
}
44+
45+
[Fact]
46+
public void InvokeItemsDialog_ShouldThrowException()
47+
{
48+
Action action = _actionList.InvokeItemsDialog;
49+
action.Should().Throw<Exception>();
50+
}
51+
}

0 commit comments

Comments
 (0)