|
| 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.ComponentModel.Design; |
| 5 | +using System.Drawing; |
| 6 | + |
| 7 | +namespace System.Windows.Forms.Design.Tests; |
| 8 | + |
| 9 | +public class ListViewDesignerTests : IDisposable |
| 10 | +{ |
| 11 | + private readonly ListViewDesigner _listViewDesigner; |
| 12 | + private readonly ListView _listView; |
| 13 | + |
| 14 | + public ListViewDesignerTests() |
| 15 | + { |
| 16 | + _listViewDesigner = new(); |
| 17 | + _listView = new(); |
| 18 | + _listViewDesigner.Initialize(_listView); |
| 19 | + } |
| 20 | + |
| 21 | + public void Dispose() |
| 22 | + { |
| 23 | + _listViewDesigner.Dispose(); |
| 24 | + _listView.Dispose(); |
| 25 | + } |
| 26 | + |
| 27 | + [WinFormsFact] |
| 28 | + public void ListViewDesigner_AssociatedComponentsTest() |
| 29 | + { |
| 30 | + _listView.Columns.Add("123"); |
| 31 | + _listView.Columns.Add("abc"); |
| 32 | + |
| 33 | + _listViewDesigner.AssociatedComponents.Count.Should().Be(2); |
| 34 | + } |
| 35 | + |
| 36 | + [WinFormsFact] |
| 37 | + public void ListViewDesigner_GetHitTest_ReturnsFalse_WhenViewIsNotDetails() |
| 38 | + { |
| 39 | + _listView.View = View.LargeIcon; |
| 40 | + |
| 41 | + bool result = _listViewDesigner.TestAccessor().Dynamic.GetHitTest(new Point(10, 10)); |
| 42 | + |
| 43 | + result.Should().BeFalse(); |
| 44 | + } |
| 45 | + |
| 46 | + [WinFormsFact] |
| 47 | + public void ListViewDesigner_GetHitTest_ReturnsFalse_WhenPointIsNotOnHeader() |
| 48 | + { |
| 49 | + _listView.View = View.Details; |
| 50 | + _listView.Columns.Add("Column1"); |
| 51 | + |
| 52 | + bool result = _listViewDesigner.TestAccessor().Dynamic.GetHitTest(new Point(10, 10)); |
| 53 | + |
| 54 | + result.Should().BeFalse(); |
| 55 | + } |
| 56 | + |
| 57 | + [WinFormsFact] |
| 58 | + public void ListViewDesigner_GetHitTest_ReturnsFalse_WhenHeaderHandleIsNull() |
| 59 | + { |
| 60 | + _listView.View = View.Details; |
| 61 | + _listView.Columns.Add("Column1"); |
| 62 | + |
| 63 | + Point point = new(10, 5); |
| 64 | + bool result = _listViewDesigner.TestAccessor().Dynamic.GetHitTest(point); |
| 65 | + |
| 66 | + result.Should().BeFalse(); |
| 67 | + } |
| 68 | + |
| 69 | + [WinFormsFact] |
| 70 | + public void ListViewDesigner_GetHitTest_ReturnsFalse_WhenPointIsOutsideControl() |
| 71 | + { |
| 72 | + _listView.View = View.Details; |
| 73 | + _listView.Columns.Add("Column1"); |
| 74 | + |
| 75 | + Point outsidePoint = new(-10, -10); |
| 76 | + bool result = _listViewDesigner.TestAccessor().Dynamic.GetHitTest(outsidePoint); |
| 77 | + |
| 78 | + result.Should().BeFalse(); |
| 79 | + } |
| 80 | + |
| 81 | + [WinFormsFact] |
| 82 | + public void ListViewDesigner_Initialize_SetsOwnerDrawToFalse() => |
| 83 | + _listView.OwnerDraw.Should().BeFalse(); |
| 84 | + |
| 85 | + [WinFormsFact] |
| 86 | + public void ListViewDesigner_Initialize_SetsUseCompatibleStateImageBehaviorToFalse() => |
| 87 | + _listView.UseCompatibleStateImageBehavior.Should().BeFalse(); |
| 88 | + |
| 89 | + [WinFormsFact] |
| 90 | + public void ListViewDesigner_Initialize_HooksChildHandles_WhenViewIsDetails() |
| 91 | + { |
| 92 | + _listView.View = View.Details; |
| 93 | + |
| 94 | + _listViewDesigner.Should().BeOfType<ListViewDesigner>(); |
| 95 | + } |
| 96 | + |
| 97 | + [WinFormsFact] |
| 98 | + public void ListViewDesigner_Initialize_DoesNotHookChildHandles_WhenViewIsNotDetails() |
| 99 | + { |
| 100 | + _listView.View = View.LargeIcon; |
| 101 | + |
| 102 | + _listViewDesigner.Should().BeOfType<ListViewDesigner>(); |
| 103 | + } |
| 104 | + |
| 105 | + [WinFormsFact] |
| 106 | + public void ListViewDesigner_ActionLists_ReturnsNonNullCollection() |
| 107 | + { |
| 108 | + DesignerActionListCollection actionLists = _listViewDesigner.ActionLists; |
| 109 | + |
| 110 | + actionLists.Should().BeOfType<DesignerActionListCollection>(); |
| 111 | + actionLists[0].Should().BeOfType<ListViewActionList>(); |
| 112 | + } |
| 113 | + |
| 114 | + [WinFormsFact] |
| 115 | + public void ListViewDesigner_ActionLists_ReturnsSameInstanceOnSubsequentCalls() |
| 116 | + { |
| 117 | + DesignerActionListCollection firstCall = _listViewDesigner.ActionLists; |
| 118 | + DesignerActionListCollection secondCall = _listViewDesigner.ActionLists; |
| 119 | + |
| 120 | + firstCall.Should().BeSameAs(secondCall); |
| 121 | + } |
| 122 | + |
| 123 | + [WinFormsFact] |
| 124 | + public void ListViewDesigner_ActionLists_ThreadSafeInitialization() |
| 125 | + { |
| 126 | + DesignerActionListCollection[] results = new DesignerActionListCollection[2]; |
| 127 | + Parallel.Invoke( |
| 128 | + () => results[0] = _listViewDesigner.ActionLists, |
| 129 | + () => results[1] = _listViewDesigner.ActionLists |
| 130 | + ); |
| 131 | + |
| 132 | + results[0].Should().BeSameAs(results[1]); |
| 133 | + } |
| 134 | +} |
0 commit comments