From b5c5f8fb500fd960eee6a509fcb41ec23aa89f61 Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" Date: Wed, 16 Jul 2025 02:03:53 +0000 Subject: [PATCH] =?UTF-8?q?[winforms]=20Source=20update=2017857aa=20?= =?UTF-8?q?=E2=86=92=206dd129e=20Diff:=20https://github.com/dotnet/winform?= =?UTF-8?q?s/compare/17857aa725c3d0860f3aff0178d3b14817eb2266..6dd129e422c?= =?UTF-8?q?9b14dc835e669688247386bef2f95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: https://github.com/dotnet/winforms/commit/17857aa725c3d0860f3aff0178d3b14817eb2266 To: https://github.com/dotnet/winforms/commit/6dd129e422c9b14dc835e669688247386bef2f95 [[ commit created by automation ]] --- src/source-manifest.json | 28 +- src/winforms/eng/Version.Details.xml | 98 ++--- src/winforms/eng/Versions.props | 46 +- src/winforms/global.json | 8 +- .../DataGridView/DataGridViewLinkCell.cs | 14 +- .../Forms/Controls/Labels/LinkUtilities.cs | 12 +- .../Windows/Forms/LinkUtilitiesTests.cs | 19 +- ...View.CheckedListViewItemCollectionTests.cs | 412 +++++++++++++++++- 8 files changed, 513 insertions(+), 124 deletions(-) diff --git a/src/source-manifest.json b/src/source-manifest.json index d2259db2d88..456b566aed0 100644 --- a/src/source-manifest.json +++ b/src/source-manifest.json @@ -7,10 +7,10 @@ "commitSha": "4e526204e83e615efe8eb5743be7fbccfa4e492a" }, { - "barId": 275017, + "barId": 275166, "path": "aspnetcore", "remoteUri": "https://github.com/dotnet/aspnetcore", - "commitSha": "f905bebf6206d90192c66e84993963f2f8a506c4" + "commitSha": "170f046b314bbbc67f6771b6eb7c2ed50859e633" }, { "barId": 273742, @@ -67,16 +67,16 @@ "commitSha": "772ee13d2bafaa1414d90dbfbd77e0941115ef19" }, { - "barId": 274804, + "barId": 275165, "path": "razor", "remoteUri": "https://github.com/dotnet/razor", - "commitSha": "ce330d020d1686e80f5ed4aec2e66f12c4f505b5" + "commitSha": "88d10f21004784390b5e220607bd4fa6ebfe1301" }, { - "barId": 274992, + "barId": 275167, "path": "roslyn", "remoteUri": "https://github.com/dotnet/roslyn", - "commitSha": "d3571ef089ef13c74ea786dce8ef615916a097cd" + "commitSha": "c1794aa58db74f27cd6bc7afc1b1d72b713f393b" }, { "barId": 273951, @@ -85,10 +85,10 @@ "commitSha": "714a51c57430dab50b67e5b468016288f5f7b0bd" }, { - "barId": 275054, + "barId": 275159, "path": "runtime", "remoteUri": "https://github.com/dotnet/runtime", - "commitSha": "9c0555e89d91149226cfade4a395e02b8d9401ff" + "commitSha": "ede442a9233fb67b2af40709a7d23418e0e491e5" }, { "barId": 273704, @@ -103,10 +103,10 @@ "commitSha": "1414d33c86e760d6635a838a45da0308ff3d53c9" }, { - "barId": 274616, + "barId": 275117, "path": "source-build-reference-packages", "remoteUri": "https://github.com/dotnet/source-build-reference-packages", - "commitSha": "11101af56c18eef9085b501a474640cd0d7ccc24" + "commitSha": "9f13ec67aeca9a84458549b440c1b0e33df71b44" }, { "barId": 274866, @@ -121,10 +121,10 @@ "commitSha": "66c6797a1e9a9346d5f6de3f9edaecad6e4350d0" }, { - "barId": 274065, + "barId": 275177, "path": "templating", "remoteUri": "https://github.com/dotnet/templating", - "commitSha": "57150459685ad38272234d96c17036c2cd2f3b96" + "commitSha": "43d52c423e7ed37cf59a01629f9bace5c6bf6f96" }, { "barId": 272429, @@ -139,10 +139,10 @@ "commitSha": "7890fbb7f086ae12b11ca85499b18f460c9090dd" }, { - "barId": 274987, + "barId": 275281, "path": "winforms", "remoteUri": "https://github.com/dotnet/winforms", - "commitSha": "d5b62a713f569a578805301a2bc77e7dfe60b36d" + "commitSha": "6dd129e422c9b14dc835e669688247386bef2f95" }, { "barId": 274919, diff --git a/src/winforms/eng/Version.Details.xml b/src/winforms/eng/Version.Details.xml index a5b4f3a7479..b6532e2949e 100644 --- a/src/winforms/eng/Version.Details.xml +++ b/src/winforms/eng/Version.Details.xml @@ -6,106 +6,106 @@ Note: if the Uri is a new place, you will need to add a subscription from that p And you can check these with "darc get-dependencies target-repo "winforms" --> - + - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 - + https://github.com/dotnet/dotnet - 86117ef4343bab700dab871c416e55b22848cd52 + 3c34a3f0178f5a637d21c3f0ba5a4ee86ab8e976 diff --git a/src/winforms/eng/Versions.props b/src/winforms/eng/Versions.props index fb0e9816687..215d3204b77 100644 --- a/src/winforms/eng/Versions.props +++ b/src/winforms/eng/Versions.props @@ -10,30 +10,30 @@ $(MajorVersion).$(MinorVersion).$(PatchVersion) false release - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 5.0.0-preview.7.20320.5 - 10.0.0-preview.7.25360.101 + 10.0.0-preview.7.25364.102 6.1.0-preview.1.24511.1 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 10.0.0-preview.5.25227.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 - 10.0.0-preview.7.25360.101 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 + 10.0.0-preview.7.25364.102 @@ -46,16 +46,16 @@ - 10.0.0-beta.25360.101 - 10.0.0-beta.25360.101 - 10.0.0-beta.25360.101 + 10.0.0-beta.25364.102 + 10.0.0-beta.25364.102 + 10.0.0-beta.25364.102 17.4.0-preview-20220707-01 - - 3.0.0-pre.25 + + 3.0.0 3.1.0 3.0.6-alpha diff --git a/src/winforms/global.json b/src/winforms/global.json index 1b308b40e0c..a274e977be5 100644 --- a/src/winforms/global.json +++ b/src/winforms/global.json @@ -21,11 +21,11 @@ } }, "msbuild-sdks": { - "Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25360.101", - "Microsoft.DotNet.CMake.Sdk": "10.0.0-beta.25360.101", - "Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.25360.101", + "Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.25364.102", + "Microsoft.DotNet.CMake.Sdk": "10.0.0-beta.25364.102", + "Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.25364.102", "FIX-85B6-MERGE-9C38-CONFLICT": "1.0.0", - "Microsoft.NET.Sdk.IL": "10.0.0-preview.7.25360.101" + "Microsoft.NET.Sdk.IL": "10.0.0-preview.7.25364.102" }, "native-tools": { "cmake": "latest" diff --git a/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs b/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs index a964cedc7ab..89195caa137 100644 --- a/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs +++ b/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/DataGridView/DataGridViewLinkCell.cs @@ -949,7 +949,7 @@ private Rectangle PaintPrivate( Font? getHoverFont = null; bool isActive = (LinkState & LinkState.Active) == LinkState.Active; - LinkUtilities.EnsureLinkFonts(cellStyle.Font!, LinkBehavior, ref getLinkFont, ref getHoverFont, isActive); + LinkUtilities.EnsureLinkFonts(cellStyle.Font!, LinkBehavior, ref getLinkFont, ref getHoverFont); using Font linkFont = getLinkFont; using Font hoverFont = getHoverFont; @@ -1028,6 +1028,18 @@ private Rectangle PaintPrivate( valBounds, linkColor, flags); + + // add a visiting effect. + if (isActive) + { + TextRenderer.DrawText( + g, + formattedValueStr, + LinkState == LinkState.Hover ? hoverFont : linkFont, + new Rectangle(valBounds.X + 1, valBounds.Y, valBounds.Width, valBounds.Height), + linkColor, + flags); + } } } else if (cellCurrent && diff --git a/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs b/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs index 6d1511a0e0c..259e485424b 100644 --- a/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs +++ b/src/winforms/src/System.Windows.Forms/System/Windows/Forms/Controls/Labels/LinkUtilities.cs @@ -163,8 +163,7 @@ public static void EnsureLinkFonts( Font baseFont, LinkBehavior link, [AllowNull] ref Font linkFont, - [AllowNull] ref Font hoverLinkFont, - bool isActive = false) + [AllowNull] ref Font hoverLinkFont) { if (linkFont is not null && hoverLinkFont is not null) { @@ -210,15 +209,6 @@ public static void EnsureLinkFonts( style &= ~FontStyle.Underline; } - if (isActive) - { - style |= FontStyle.Bold; - } - else - { - style &= ~FontStyle.Bold; - } - hoverLinkFont = new Font(f, style); linkFont = hoverLinkFont; } diff --git a/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/LinkUtilitiesTests.cs b/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/LinkUtilitiesTests.cs index 2cdd2cc65b9..3b7d8d098b6 100644 --- a/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/LinkUtilitiesTests.cs +++ b/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/LinkUtilitiesTests.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Drawing; @@ -44,21 +44,4 @@ public void LinkUtilities_EnsureLinkFonts_CreatesExpectedFonts(LinkBehavior beha linkFont.Should().BeOfType(); hoverLinkFont.Should().BeOfType(); } - - [WinFormsTheory] - [InlineData(LinkBehavior.AlwaysUnderline)] - [InlineData(LinkBehavior.HoverUnderline)] - [InlineData(LinkBehavior.NeverUnderline)] - public void LinkUtilities_EnsureLinkFonts_CreatesExpectedFonts_WithActive(LinkBehavior behavior) - { - using Font baseFont = new("Arial", 12); - Font? linkFont = null; - Font? hoverLinkFont = null; - - Action act = () => LinkUtilities.EnsureLinkFonts(baseFont, behavior, ref linkFont, ref hoverLinkFont, isActive: true); - - act.Should().NotThrow(); - linkFont.Should().BeOfType(); - hoverLinkFont.Should().BeOfType(); - } } diff --git a/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/ListView.CheckedListViewItemCollectionTests.cs b/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/ListView.CheckedListViewItemCollectionTests.cs index 443838bdb9b..1742a9e71eb 100644 --- a/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/ListView.CheckedListViewItemCollectionTests.cs +++ b/src/winforms/src/test/unit/System.Windows.Forms/System/Windows/Forms/ListView.CheckedListViewItemCollectionTests.cs @@ -1,15 +1,419 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -#nullable disable +using System.Collections; namespace System.Windows.Forms.Tests; -public class ListView_CheckedListViewItemCollectionTests +public class ListView_CheckedListViewItemCollectionTests : IDisposable { + private readonly ListView _listView; + private readonly ListView.CheckedListViewItemCollection _collection; + + public ListView_CheckedListViewItemCollectionTests() + { + _listView = new ListView(); + _collection = new ListView.CheckedListViewItemCollection(_listView); + } + + public void Dispose() => _listView.Dispose(); + + [WinFormsFact] + public void CheckedListViewItemCollection_Ctor_OwnerIsNull_ThrowsArgumentNullException() => + Assert.Throws("owner", () => new ListView.CheckedListViewItemCollection(null!)); + + [WinFormsFact] + public void Count_ReturnsCheckedItemCount_WhenNotVirtualMode() + { + _listView.CheckBoxes = true; + _listView.Items.AddRange([ + new ListViewItem { Checked = true }, + new ListViewItem { Checked = false }, + new ListViewItem { Checked = true } + ]); + + _collection.Count.Should().Be(2); + } + + [WinFormsFact] + public void Count_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.CheckBoxes = true; + _listView.VirtualMode = true; + + Action act = () => { int _ = _collection.Count; }; + + act.Should().Throw(); + } + + [WinFormsFact] + public void Indexer_ReturnsCheckedItem_ByIndex() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Name = "a", Checked = false }; + ListViewItem item2 = new() { Name = "b", Checked = true }; + ListViewItem item3 = new() { Name = "c", Checked = true }; + _listView.Items.AddRange([item1, item2, item3]); + + _collection[0].Should().Be(item2); + _collection[1].Should().Be(item3); + } + + [WinFormsFact] + public void Indexer_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.CheckBoxes = true; + _listView.VirtualMode = true; + + Action act = () => { var _ = _collection[0]; }; + + act.Should().Throw(); + } + + [WinFormsFact] + public void IList_Indexer_Get_ReturnsCheckedItem() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Checked = false }; + ListViewItem item2 = new() { Checked = true }; + _listView.Items.AddRange([item1, item2]); + IList iList = _collection; + + iList[0].Should().Be(item2); + } + + [WinFormsFact] + public void IList_Indexer_Set_ThrowsNotSupportedException() + { + IList iList = _collection; + + Action act = () => iList[0] = new ListViewItem(); + + act.Should().Throw(); + } + + [WinFormsFact] + public void StringIndexer_ReturnsCheckedItem_ByKey() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Name = "foo", Checked = true }; + ListViewItem item2 = new() { Name = "bar", Checked = true }; + _listView.Items.AddRange([item1, item2]); + + _collection["foo"].Should().Be(item1); + _collection["bar"].Should().Be(item2); + } + + [WinFormsFact] + public void StringIndexer_ReturnsNull_ForNullOrEmptyKey() + { + _listView.CheckBoxes = true; + + _collection[null].Should().BeNull(); + _collection[string.Empty].Should().BeNull(); + } + + [WinFormsFact] + public void StringIndexer_ReturnsNull_IfKeyNotFound() + { + _listView.CheckBoxes = true; + ListViewItem item = new() { Name = "foo", Checked = true }; + _listView.Items.Add(item); + + _collection["bar"].Should().BeNull(); + } + + [WinFormsFact] + public void StringIndexer_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.CheckBoxes = true; + _listView.VirtualMode = true; + + Action act = () => { var _ = _collection["foo"]; }; + + act.Should().Throw(); + } + + [WinFormsFact] + public void ICollection_SyncRoot_ReturnsSelf() + { + ListView.CheckedListViewItemCollection syncRoot = (ListView.CheckedListViewItemCollection)((ICollection)_collection).SyncRoot; + + syncRoot.Should().BeSameAs(_collection); + } + + [WinFormsFact] + public void ICollection_IsSynchronized_IsFalse() + { + bool isSynchronized = ((ICollection)_collection).IsSynchronized; + + isSynchronized.Should().BeFalse(); + } + + [WinFormsFact] + public void IList_IsFixedSize_IsTrue() + { + bool isFixedSize = ((IList)_collection).IsFixedSize; + + isFixedSize.Should().BeTrue(); + } + + [WinFormsFact] + public void IsReadOnly_IsTrue() + { + _collection.IsReadOnly.Should().BeTrue(); + } + + [WinFormsTheory] + [InlineData(true, true, true)] // Checked and owned + [InlineData(false, true, false)] // Not checked but owned + [InlineData(true, false, false)] // Checked but not owned + public void Contains_ReturnsExpected_BasedOnCheckedAndOwnership(bool isChecked, bool isOwned, bool expected) + { + using ListView listView2 = new(); + _listView.CheckBoxes = true; + listView2.CheckBoxes = true; + + ListViewItem item = new() { Checked = isChecked }; + if (isOwned) + { + _listView.Items.Add(item); + } + else + { + listView2.Items.Add(item); + } + + _collection.Contains(item).Should().Be(expected); + } + + [WinFormsFact] + public void Contains_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + ListViewItem item = new(); + + Action act = () => _collection.Contains(item); + + act.Should().Throw(); + } + + [WinFormsFact] + public void IList_Contains_ReturnsTrue_IfListViewItemIsCheckedAndOwned() + { + _listView.CheckBoxes = true; + ListViewItem item = new() { Checked = true }; + _listView.Items.Add(item); + IList iList = _collection; + + iList.Contains(item).Should().BeTrue(); + } + + [WinFormsFact] + public void IList_Contains_ReturnsFalse_IfNotListViewItem() + { + IList iList = _collection; + + iList.Contains("not an item").Should().BeFalse(); + } + + [WinFormsFact] + public void IList_Contains_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + IList iList = _collection; + + Action act = () => iList.Contains(new ListViewItem()); + + act.Should().Throw(); + } + + [WinFormsTheory] + [InlineData("foo", true)] + [InlineData("bar", false)] + [InlineData(null, false)] + [InlineData("", false)] + public void ContainsKey_ReturnsExpected(string? key, bool expected) + { + _listView.CheckBoxes = true; + ListViewItem item = new() { Name = "foo", Checked = true }; + _listView.Items.Add(item); + + _collection.ContainsKey(key).Should().Be(expected); + } + + [WinFormsFact] + public void ContainsKey_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + + Action act = () => _collection.ContainsKey("foo"); + + act.Should().Throw(); + } + + [WinFormsFact] + public void IndexOf_ReturnsIndex_IfItemIsCheckedAndOwned() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Checked = true }; + ListViewItem item2 = new() { Checked = true }; + _listView.Items.AddRange([item1, item2]); + + _collection.IndexOf(item2).Should().Be(1); + } + + [WinFormsFact] + public void IndexOf_ReturnsMinusOne_IfItemIsNotChecked() + { + _listView.CheckBoxes = true; + ListViewItem item = new() { Checked = false }; + _listView.Items.Add(item); + + _collection.IndexOf(item).Should().Be(-1); + } + + [WinFormsFact] + public void IndexOf_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + + Action act = () => _collection.IndexOf(new ListViewItem()); + + act.Should().Throw(); + } + + [WinFormsFact] + public void IndexOfKey_ReturnsIndex_IfKeyExists() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Name = "foo", Checked = true }; + ListViewItem item2 = new() { Name = "bar", Checked = true }; + _listView.Items.AddRange([item1, item2]); + + _collection.IndexOfKey("bar").Should().Be(1); + } + + [WinFormsFact] + public void IndexOfKey_ReturnsMinusOne_IfKeyIsNullOrEmpty() + { + _listView.CheckBoxes = true; + + _collection.IndexOfKey(null).Should().Be(-1); + _collection.IndexOfKey(string.Empty).Should().Be(-1); + } + [WinFormsFact] - public void CheckedListViewItemCollection_Ctor_OwnerIsNull_ThrowsArgumentNullException() + public void IndexOfKey_ThrowsInvalidOperationException_WhenVirtualMode() { - Assert.Throws("owner", () => { new ListView.CheckedListViewItemCollection(null); }); + _listView.VirtualMode = true; + + Action act = () => _collection.IndexOfKey("foo"); + + act.Should().Throw(); + } + + [WinFormsFact] + public void IList_IndexOf_ReturnsIndex_IfListViewItemIsCheckedAndOwned() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Checked = true }; + ListViewItem item2 = new() { Checked = true }; + _listView.Items.AddRange([item1, item2]); + IList iList = _collection; + + iList.IndexOf(item2).Should().Be(1); + } + + [WinFormsFact] + public void IList_IndexOf_ReturnsMinusOne_IfNotListViewItem() + { + IList iList = _collection; + + iList.IndexOf("not an item").Should().Be(-1); + } + + [WinFormsFact] + public void IList_IndexOf_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + IList iList = _collection; + + Action act = () => iList.IndexOf(new ListViewItem()); + + act.Should().Throw(); + } + + [WinFormsTheory] + [InlineData("Add")] + [InlineData("Clear")] + [InlineData("Insert")] + [InlineData("Remove")] + [InlineData("RemoveAt")] + public void IList_Methods_ThrowNotSupportedException(string methodName) + { + IList iList = _collection; + + Action act = methodName switch + { + "Add" => () => iList.Add(new ListViewItem()), + "Clear" => iList.Clear, + "Insert" => () => iList.Insert(0, new ListViewItem()), + "Remove" => () => iList.Remove(new ListViewItem()), + "RemoveAt" => () => iList.RemoveAt(0), + _ => throw new ArgumentException($"Invalid method name: {methodName}", nameof(methodName)) + }; + + act.Should().Throw(); + } + + [WinFormsFact] + public void CopyTo_CopiesCheckedItems() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Checked = true }; + ListViewItem item2 = new() { Checked = false }; + ListViewItem item3 = new() { Checked = true }; + _listView.Items.AddRange([item1, item2, item3]); + ListViewItem[] array = new ListViewItem[2]; + + _collection.CopyTo(array, 0); + + array.Should().Equal(item1, item3); + } + + [WinFormsFact] + public void CopyTo_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + ListViewItem[] array = new ListViewItem[1]; + + Action act = () => _collection.CopyTo(array, 0); + + act.Should().Throw(); + } + + [WinFormsFact] + public void GetEnumerator_EnumeratesCheckedItems() + { + _listView.CheckBoxes = true; + ListViewItem item1 = new() { Checked = true }; + ListViewItem item2 = new() { Checked = false }; + ListViewItem item3 = new() { Checked = true }; + _listView.Items.AddRange([item1, item2, item3]); + + ListViewItem[] items = _collection.Cast().ToArray(); + + items.Should().Equal(item1, item3); + } + + [WinFormsFact] + public void GetEnumerator_ThrowsInvalidOperationException_WhenVirtualMode() + { + _listView.VirtualMode = true; + + Action act = () => _collection.GetEnumerator(); + + act.Should().Throw(); } } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy