From b9cf1007d36932fa679c13d23a6db69ce5a57b3b Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Wed, 18 Sep 2024 11:00:56 +0800 Subject: [PATCH 1/4] Add code coverage for ToolStripLabe.cd file --- .../Windows/Forms/ToolStripLabelTests.cs | 330 ++++++++++++++++++ 1 file changed, 330 insertions(+) create mode 100644 src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs new file mode 100644 index 00000000000..69328e17208 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs @@ -0,0 +1,330 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable enable + +using System.Drawing; + +namespace System.Windows.Forms.Tests; + +public class ToolStripLabelTests : IDisposable +{ + private readonly ToolStripLabel _toolStripLabel; + + public ToolStripLabelTests() + { + _toolStripLabel = new(); + } + + public void Dispose() => _toolStripLabel.Dispose(); + + [WinFormsFact] + public void ToolStripLabel_ConstructorWithImage_SetsImage() + { + using Bitmap image = new(10, 10); + _toolStripLabel.Image = image; + _toolStripLabel.Text = null; + + _toolStripLabel.Image.Should().Be(image); + _toolStripLabel.Text.Should().BeNull(); + _toolStripLabel.IsLink.Should().BeFalse(); + } + + [WinFormsFact] + public void ToolStripLabel_ConstructorWithTextAndImage_SetsTextAndImage() + { + using Bitmap image = new(10, 10); + string text = "Test Label"; + _toolStripLabel.Text = text; + _toolStripLabel.Image = image; + + _toolStripLabel.Text.Should().Be(text); + _toolStripLabel.Image.Should().Be(image); + _toolStripLabel.IsLink.Should().BeFalse(); + } + + [WinFormsFact] + public void ToolStripLabel_ConstructorWithTextImageAndIsLink_SetsTextImageAndIsLink() + { + using Bitmap image = new(10, 10); + string text = "Test Label"; + bool isLink = true; + _toolStripLabel.Text = text; + _toolStripLabel.Image = image; + _toolStripLabel.IsLink = isLink; + + _toolStripLabel.Text.Should().Be(text); + _toolStripLabel.Image.Should().Be(image); + _toolStripLabel.IsLink.Should().Be(isLink); + } + + [WinFormsFact] + public void ToolStripLabel_ConstructorWithTextImageIsLinkAndOnClick_SetsTextImageIsLinkAndOnClick() + { + using Bitmap image = new(10, 10); + string text = "Test Label"; + bool isLink = true; + bool eventHandlerCalled = false; + EventHandler onClick = (sender, e) => eventHandlerCalled = true; + + _toolStripLabel.Text = text; + _toolStripLabel.Image = image; + _toolStripLabel.IsLink = isLink; + _toolStripLabel.Click += onClick; + + _toolStripLabel.Text.Should().Be(text); + _toolStripLabel.Image.Should().Be(image); + _toolStripLabel.IsLink.Should().Be(isLink); + + _toolStripLabel.PerformClick(); + eventHandlerCalled.Should().BeTrue(); + } + + [WinFormsFact] + public void ToolStripLabel_ActiveLinkColor_DefaultValue() + { + var defaultColor = _toolStripLabel.TestAccessor().Dynamic.IEActiveLinkColor; + + _toolStripLabel.ActiveLinkColor.Should().Be(defaultColor); + } + + [WinFormsFact] + public void ToolStripLabel_ActiveLinkColor_SetAndGet() + { + Color expectedColor = Color.Red; + _toolStripLabel.ActiveLinkColor = expectedColor; + + _toolStripLabel.ActiveLinkColor.Should().Be(expectedColor); + } + + [WinFormsFact] + public void ToolStripLabel_LinkBehavior_DefaultValue() + { + _toolStripLabel.LinkBehavior.Should().Be(LinkBehavior.SystemDefault); + } + + [WinFormsTheory] + [InlineData(LinkBehavior.AlwaysUnderline)] + [InlineData(LinkBehavior.HoverUnderline)] + [InlineData(LinkBehavior.NeverUnderline)] + public void ToolStripLabel_LinkBehavior_SetAndGet(LinkBehavior behavior) + { + _toolStripLabel.LinkBehavior = behavior; + _toolStripLabel.LinkBehavior.Should().Be(behavior); + } + + [WinFormsFact] + public void ToolStripLabel_LinkVisited_DefaultValue() + { + _toolStripLabel.LinkVisited.Should().BeFalse(); + } + + [WinFormsFact] + public void ToolStripLabel_LinkVisited_SetAndGet() + { + _toolStripLabel.LinkVisited = true; + _toolStripLabel.LinkVisited.Should().BeTrue(); + } + + [WinFormsFact] + public void ToolStripLabel_VisitedLinkColor_SetAndGet() + { + Color expectedColor = Color.Green; + _toolStripLabel.VisitedLinkColor = expectedColor; + + _toolStripLabel.VisitedLinkColor.Should().Be(expectedColor); + } + + [WinFormsFact] + public void ToolStripLabel_VisitedLinkColor_DefaultValue() + { + var accessor = _toolStripLabel.TestAccessor().Dynamic; + Color defaultColor = accessor.IEVisitedLinkColor; + + _toolStripLabel.VisitedLinkColor.Should().Be(defaultColor); + } + + [WinFormsFact] + public void ToolStripLabel_LinkColor_SetAndGet() + { + Color expectedColor = Color.Blue; + _toolStripLabel.LinkColor = expectedColor; + + _toolStripLabel.LinkColor.Should().Be(expectedColor); + } + + [WinFormsFact] + public void ToolStripLabel_InvalidateLinkFonts_DisposesFonts() + { + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor._linkFont = new Font("Arial", 10); + accessor._hoverLinkFont = new Font("Arial", 10, FontStyle.Underline); + + accessor.InvalidateLinkFonts(); + + ((Font)accessor._linkFont).Should().BeNull(); + ((Font)accessor._hoverLinkFont).Should().BeNull(); + } + + [WinFormsFact] + public void ToolStripLabel_OnFontChanged_InvokesInvalidateLinkFonts() + { + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor._linkFont = new Font("Arial", 10); + accessor._hoverLinkFont = new Font("Arial", 10, FontStyle.Underline); + + _toolStripLabel.Font = new Font("Times New Roman", 12); + + ((Font)accessor._linkFont).Should().BeNull(); + ((Font)accessor._hoverLinkFont).Should().BeNull(); + } + + [WinFormsFact] + public void ToolStripLabel_OnMouseEnter_ChangesCursorToHand_WhenIsLink() + { + _toolStripLabel.IsLink = true; + ToolStrip toolStrip = new(); + toolStrip.Items.Add(_toolStripLabel); + toolStrip.Cursor = Cursors.Default; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor.OnMouseEnter(EventArgs.Empty); + + toolStrip.Cursor.Should().Be(Cursors.Default); + } + + [WinFormsFact] + public void ToolStripLabel_OnMouseEnter_DoesNotChangeCursor_WhenNotIsLink() + { + _toolStripLabel.IsLink = false; + ToolStrip toolStrip = new(); + toolStrip.Items.Add(_toolStripLabel); + toolStrip.Cursor = Cursors.Default; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor.OnMouseEnter(EventArgs.Empty); + + toolStrip.Cursor.Should().Be(Cursors.Default); + } + + [WinFormsFact] + public void ToolStripLabel_OnMouseLeave_ResetsCursor_WhenIsLink() + { + _toolStripLabel.IsLink = true; + ToolStrip toolStrip = new(); + toolStrip.Items.Add(_toolStripLabel); + toolStrip.Cursor = Cursors.Hand; + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor._lastCursor = Cursors.Default; + + accessor.OnMouseLeave(EventArgs.Empty); + + toolStrip.Cursor.Should().Be(Cursors.Hand); + } + + [WinFormsFact] + public void ToolStripLabel_OnMouseLeave_DoesNotChangeCursor_WhenNotIsLink() + { + _toolStripLabel.IsLink = false; + ToolStrip toolStrip = new(); + toolStrip.Items.Add(_toolStripLabel); + toolStrip.Cursor = Cursors.Hand; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor.OnMouseLeave(EventArgs.Empty); + + toolStrip.Cursor.Should().Be(Cursors.Hand); + } + + [WinFormsFact] + public void ToolStripLabel_ResetActiveLinkColor_SetsActiveLinkColorToDefault() + { + _toolStripLabel.ActiveLinkColor = Color.Red; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor.ResetActiveLinkColor(); + + Color defaultColor = accessor.IEActiveLinkColor; + + _toolStripLabel.ActiveLinkColor.Should().Be(defaultColor); + } + + [WinFormsFact] + public void ToolStripLabel_ResetLinkColor_SetsLinkColorToDefault() + { + _toolStripLabel.LinkColor = Color.Blue; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + accessor.ResetLinkColor(); + + Color defaultColor = accessor.IELinkColor; + + _toolStripLabel.LinkColor.Should().Be(defaultColor); + } + + [WinFormsFact] + public void ToolStripLabel_ShouldSerializeActiveLinkColor_ReturnsTrue_WhenActiveLinkColorIsNotEmpty() + { + _toolStripLabel.ActiveLinkColor = Color.Red; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + bool result = accessor.ShouldSerializeActiveLinkColor(); + + result.Should().BeTrue(); + } + + [WinFormsFact] + public void ToolStripLabel_ShouldSerializeActiveLinkColor_ReturnsFalse_WhenActiveLinkColorIsEmpty() + { + _toolStripLabel.ActiveLinkColor = Color.Empty; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + bool result = accessor.ShouldSerializeActiveLinkColor(); + + result.Should().BeFalse(); + } + + [WinFormsFact] + public void ToolStripLabel_ShouldSerializeLinkColor_ReturnsTrue_WhenLinkColorIsNotEmpty() + { + _toolStripLabel.LinkColor = Color.Blue; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + bool result = accessor.ShouldSerializeLinkColor(); + + result.Should().BeTrue(); + } + + [WinFormsFact] + public void ToolStripLabel_ShouldSerializeLinkColor_ReturnsFalse_WhenLinkColorIsEmpty() + { + _toolStripLabel.LinkColor = Color.Empty; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + bool result = accessor.ShouldSerializeLinkColor(); + + result.Should().BeFalse(); + } + + [WinFormsFact] + public void ToolStripLabel_ShouldSerializeVisitedLinkColor_ReturnsTrue_WhenVisitedLinkColorIsNotEmpty() + { + _toolStripLabel.VisitedLinkColor = Color.Green; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + bool result = accessor.ShouldSerializeVisitedLinkColor(); + + result.Should().BeTrue(); + } + + [WinFormsFact] + public void ToolStripLabel_ShouldSerializeVisitedLinkColor_ReturnsFalse_WhenVisitedLinkColorIsEmpty() + { + _toolStripLabel.VisitedLinkColor = Color.Empty; + + var accessor = _toolStripLabel.TestAccessor().Dynamic; + bool result = accessor.ShouldSerializeVisitedLinkColor(); + + result.Should().BeFalse(); + } +} From bc426dbf39f4ac49c219aa9e0f734a91a6b580e1 Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Thu, 19 Sep 2024 16:37:29 +0800 Subject: [PATCH 2/4] Handle FeedBacks --- .../Windows/Forms/ToolStripLabelTests.cs | 159 +++++------------- 1 file changed, 40 insertions(+), 119 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs index 69328e17208..0e4489490a6 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs @@ -9,14 +9,28 @@ namespace System.Windows.Forms.Tests; public class ToolStripLabelTests : IDisposable { - private readonly ToolStripLabel _toolStripLabel; + private readonly ToolStripLabel _toolStripLabel = new(); - public ToolStripLabelTests() + public void Dispose() => _toolStripLabel.Dispose(); + + [WinFormsFact] + public void ToolStripLabel_DefaultConstructor_SetsDefaults() { - _toolStripLabel = new(); + _toolStripLabel.Text.Should().BeEmpty(); + _toolStripLabel.Image.Should().BeNull(); + _toolStripLabel.IsLink.Should().BeFalse(); } - public void Dispose() => _toolStripLabel.Dispose(); + [WinFormsFact] + public void ToolStripLabel_ConstructorWithText_SetsText() + { + string text = "Test Label"; + _toolStripLabel.Text = text; + + _toolStripLabel.Text.Should().Be(text); + _toolStripLabel.Image.Should().BeNull(); + _toolStripLabel.IsLink.Should().BeFalse(); + } [WinFormsFact] public void ToolStripLabel_ConstructorWithImage_SetsImage() @@ -179,63 +193,6 @@ public void ToolStripLabel_OnFontChanged_InvokesInvalidateLinkFonts() ((Font)accessor._hoverLinkFont).Should().BeNull(); } - [WinFormsFact] - public void ToolStripLabel_OnMouseEnter_ChangesCursorToHand_WhenIsLink() - { - _toolStripLabel.IsLink = true; - ToolStrip toolStrip = new(); - toolStrip.Items.Add(_toolStripLabel); - toolStrip.Cursor = Cursors.Default; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - accessor.OnMouseEnter(EventArgs.Empty); - - toolStrip.Cursor.Should().Be(Cursors.Default); - } - - [WinFormsFact] - public void ToolStripLabel_OnMouseEnter_DoesNotChangeCursor_WhenNotIsLink() - { - _toolStripLabel.IsLink = false; - ToolStrip toolStrip = new(); - toolStrip.Items.Add(_toolStripLabel); - toolStrip.Cursor = Cursors.Default; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - accessor.OnMouseEnter(EventArgs.Empty); - - toolStrip.Cursor.Should().Be(Cursors.Default); - } - - [WinFormsFact] - public void ToolStripLabel_OnMouseLeave_ResetsCursor_WhenIsLink() - { - _toolStripLabel.IsLink = true; - ToolStrip toolStrip = new(); - toolStrip.Items.Add(_toolStripLabel); - toolStrip.Cursor = Cursors.Hand; - var accessor = _toolStripLabel.TestAccessor().Dynamic; - accessor._lastCursor = Cursors.Default; - - accessor.OnMouseLeave(EventArgs.Empty); - - toolStrip.Cursor.Should().Be(Cursors.Hand); - } - - [WinFormsFact] - public void ToolStripLabel_OnMouseLeave_DoesNotChangeCursor_WhenNotIsLink() - { - _toolStripLabel.IsLink = false; - ToolStrip toolStrip = new(); - toolStrip.Items.Add(_toolStripLabel); - toolStrip.Cursor = Cursors.Hand; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - accessor.OnMouseLeave(EventArgs.Empty); - - toolStrip.Cursor.Should().Be(Cursors.Hand); - } - [WinFormsFact] public void ToolStripLabel_ResetActiveLinkColor_SetsActiveLinkColorToDefault() { @@ -262,69 +219,33 @@ public void ToolStripLabel_ResetLinkColor_SetsLinkColorToDefault() _toolStripLabel.LinkColor.Should().Be(defaultColor); } - [WinFormsFact] - public void ToolStripLabel_ShouldSerializeActiveLinkColor_ReturnsTrue_WhenActiveLinkColorIsNotEmpty() - { - _toolStripLabel.ActiveLinkColor = Color.Red; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - bool result = accessor.ShouldSerializeActiveLinkColor(); - - result.Should().BeTrue(); - } - - [WinFormsFact] - public void ToolStripLabel_ShouldSerializeActiveLinkColor_ReturnsFalse_WhenActiveLinkColorIsEmpty() - { - _toolStripLabel.ActiveLinkColor = Color.Empty; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - bool result = accessor.ShouldSerializeActiveLinkColor(); - - result.Should().BeFalse(); - } - - [WinFormsFact] - public void ToolStripLabel_ShouldSerializeLinkColor_ReturnsTrue_WhenLinkColorIsNotEmpty() - { - _toolStripLabel.LinkColor = Color.Blue; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - bool result = accessor.ShouldSerializeLinkColor(); - - result.Should().BeTrue(); - } - - [WinFormsFact] - public void ToolStripLabel_ShouldSerializeLinkColor_ReturnsFalse_WhenLinkColorIsEmpty() + public static TheoryData ShouldSerializeColorData => + new() { - _toolStripLabel.LinkColor = Color.Empty; + { nameof(ToolStripLabel.ActiveLinkColor), Color.Red, true }, + { nameof(ToolStripLabel.ActiveLinkColor), Color.Empty, false }, + { nameof(ToolStripLabel.LinkColor), Color.Blue, true }, + { nameof(ToolStripLabel.LinkColor), Color.Empty, false }, + { nameof(ToolStripLabel.VisitedLinkColor), Color.Green, true }, + { nameof(ToolStripLabel.VisitedLinkColor), Color.Empty, false } + }; - var accessor = _toolStripLabel.TestAccessor().Dynamic; - bool result = accessor.ShouldSerializeLinkColor(); - - result.Should().BeFalse(); - } - - [WinFormsFact] - public void ToolStripLabel_ShouldSerializeVisitedLinkColor_ReturnsTrue_WhenVisitedLinkColorIsNotEmpty() + [WinFormsTheory] + [MemberData(nameof(ShouldSerializeColorData))] + public void ToolStripLabel_ShouldSerializeColor_ReturnsExpected(string propertyName, Color color, bool expected) { - _toolStripLabel.VisitedLinkColor = Color.Green; + var property = typeof(ToolStripLabel).GetProperty(propertyName); + property!.SetValue(_toolStripLabel, color); var accessor = _toolStripLabel.TestAccessor().Dynamic; - bool result = accessor.ShouldSerializeVisitedLinkColor(); + bool result = propertyName switch + { + nameof(ToolStripLabel.ActiveLinkColor) => accessor.ShouldSerializeActiveLinkColor(), + nameof(ToolStripLabel.LinkColor) => accessor.ShouldSerializeLinkColor(), + nameof(ToolStripLabel.VisitedLinkColor) => accessor.ShouldSerializeVisitedLinkColor(), + _ => throw new ArgumentException("Invalid property name", nameof(propertyName)) + }; - result.Should().BeTrue(); + result.Should().Be(expected); } - - [WinFormsFact] - public void ToolStripLabel_ShouldSerializeVisitedLinkColor_ReturnsFalse_WhenVisitedLinkColorIsEmpty() - { - _toolStripLabel.VisitedLinkColor = Color.Empty; - - var accessor = _toolStripLabel.TestAccessor().Dynamic; - bool result = accessor.ShouldSerializeVisitedLinkColor(); - - result.Should().BeFalse(); - } } From 8c23324aefc84d770e31950ab4c5529b87d1088b Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Fri, 20 Sep 2024 15:08:31 +0800 Subject: [PATCH 3/4] Handle FeedBacks --- .../Windows/Forms/ToolStripLabelTests.cs | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs index 0e4489490a6..df759f85265 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs @@ -10,38 +10,40 @@ namespace System.Windows.Forms.Tests; public class ToolStripLabelTests : IDisposable { private readonly ToolStripLabel _toolStripLabel = new(); - public void Dispose() => _toolStripLabel.Dispose(); [WinFormsFact] public void ToolStripLabel_DefaultConstructor_SetsDefaults() { - _toolStripLabel.Text.Should().BeEmpty(); - _toolStripLabel.Image.Should().BeNull(); - _toolStripLabel.IsLink.Should().BeFalse(); + ToolStripLabel toolStripLabel = new(); + + toolStripLabel.Text.Should().BeEmpty(); + toolStripLabel.Image.Should().BeNull(); + toolStripLabel.IsLink.Should().BeFalse(); } [WinFormsFact] public void ToolStripLabel_ConstructorWithText_SetsText() { string text = "Test Label"; - _toolStripLabel.Text = text; - _toolStripLabel.Text.Should().Be(text); - _toolStripLabel.Image.Should().BeNull(); - _toolStripLabel.IsLink.Should().BeFalse(); + ToolStripLabel toolStripLabel = new(text); + + toolStripLabel.Text.Should().Be(text); + toolStripLabel.Image.Should().BeNull(); + toolStripLabel.IsLink.Should().BeFalse(); } [WinFormsFact] public void ToolStripLabel_ConstructorWithImage_SetsImage() { using Bitmap image = new(10, 10); - _toolStripLabel.Image = image; - _toolStripLabel.Text = null; - _toolStripLabel.Image.Should().Be(image); - _toolStripLabel.Text.Should().BeNull(); - _toolStripLabel.IsLink.Should().BeFalse(); + ToolStripLabel toolStripLabel = new(image); + + toolStripLabel.Image.Should().Be(image); + toolStripLabel.Text.Should().BeNull(); + toolStripLabel.IsLink.Should().BeFalse(); } [WinFormsFact] @@ -49,12 +51,12 @@ public void ToolStripLabel_ConstructorWithTextAndImage_SetsTextAndImage() { using Bitmap image = new(10, 10); string text = "Test Label"; - _toolStripLabel.Text = text; - _toolStripLabel.Image = image; - _toolStripLabel.Text.Should().Be(text); - _toolStripLabel.Image.Should().Be(image); - _toolStripLabel.IsLink.Should().BeFalse(); + ToolStripLabel toolStripLabel = new(text, image); + + toolStripLabel.Text.Should().Be(text); + toolStripLabel.Image.Should().Be(image); + toolStripLabel.IsLink.Should().BeFalse(); } [WinFormsFact] @@ -63,13 +65,12 @@ public void ToolStripLabel_ConstructorWithTextImageAndIsLink_SetsTextImageAndIsL using Bitmap image = new(10, 10); string text = "Test Label"; bool isLink = true; - _toolStripLabel.Text = text; - _toolStripLabel.Image = image; - _toolStripLabel.IsLink = isLink; - _toolStripLabel.Text.Should().Be(text); - _toolStripLabel.Image.Should().Be(image); - _toolStripLabel.IsLink.Should().Be(isLink); + ToolStripLabel toolStripLabel = new(text, image, isLink); + + toolStripLabel.Text.Should().Be(text); + toolStripLabel.Image.Should().Be(image); + toolStripLabel.IsLink.Should().Be(isLink); } [WinFormsFact] @@ -81,16 +82,13 @@ public void ToolStripLabel_ConstructorWithTextImageIsLinkAndOnClick_SetsTextImag bool eventHandlerCalled = false; EventHandler onClick = (sender, e) => eventHandlerCalled = true; - _toolStripLabel.Text = text; - _toolStripLabel.Image = image; - _toolStripLabel.IsLink = isLink; - _toolStripLabel.Click += onClick; + ToolStripLabel toolStripLabel = new(text, image, isLink, onClick); - _toolStripLabel.Text.Should().Be(text); - _toolStripLabel.Image.Should().Be(image); - _toolStripLabel.IsLink.Should().Be(isLink); + toolStripLabel.Text.Should().Be(text); + toolStripLabel.Image.Should().Be(image); + toolStripLabel.IsLink.Should().Be(isLink); - _toolStripLabel.PerformClick(); + toolStripLabel.PerformClick(); eventHandlerCalled.Should().BeTrue(); } From 18af4ce2cca6803a247f70da4668a7bb79130b34 Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Tue, 24 Sep 2024 09:19:56 +0800 Subject: [PATCH 4/4] Handle FeedBacks --- .../System/Windows/Forms/ToolStripLabelTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs index df759f85265..cfb3c223eb2 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/ToolStripLabelTests.cs @@ -15,7 +15,7 @@ public class ToolStripLabelTests : IDisposable [WinFormsFact] public void ToolStripLabel_DefaultConstructor_SetsDefaults() { - ToolStripLabel toolStripLabel = new(); + using ToolStripLabel toolStripLabel = new(); toolStripLabel.Text.Should().BeEmpty(); toolStripLabel.Image.Should().BeNull(); @@ -27,7 +27,7 @@ public void ToolStripLabel_ConstructorWithText_SetsText() { string text = "Test Label"; - ToolStripLabel toolStripLabel = new(text); + using ToolStripLabel toolStripLabel = new(text); toolStripLabel.Text.Should().Be(text); toolStripLabel.Image.Should().BeNull(); @@ -39,7 +39,7 @@ public void ToolStripLabel_ConstructorWithImage_SetsImage() { using Bitmap image = new(10, 10); - ToolStripLabel toolStripLabel = new(image); + using ToolStripLabel toolStripLabel = new(image); toolStripLabel.Image.Should().Be(image); toolStripLabel.Text.Should().BeNull(); @@ -52,7 +52,7 @@ public void ToolStripLabel_ConstructorWithTextAndImage_SetsTextAndImage() using Bitmap image = new(10, 10); string text = "Test Label"; - ToolStripLabel toolStripLabel = new(text, image); + using ToolStripLabel toolStripLabel = new(text, image); toolStripLabel.Text.Should().Be(text); toolStripLabel.Image.Should().Be(image); @@ -66,7 +66,7 @@ public void ToolStripLabel_ConstructorWithTextImageAndIsLink_SetsTextImageAndIsL string text = "Test Label"; bool isLink = true; - ToolStripLabel toolStripLabel = new(text, image, isLink); + using ToolStripLabel toolStripLabel = new(text, image, isLink); toolStripLabel.Text.Should().Be(text); toolStripLabel.Image.Should().Be(image); @@ -82,7 +82,7 @@ public void ToolStripLabel_ConstructorWithTextImageIsLinkAndOnClick_SetsTextImag bool eventHandlerCalled = false; EventHandler onClick = (sender, e) => eventHandlerCalled = true; - ToolStripLabel toolStripLabel = new(text, image, isLink, onClick); + using ToolStripLabel toolStripLabel = new(text, image, isLink, onClick); toolStripLabel.Text.Should().Be(text); toolStripLabel.Image.Should().Be(image);