From a3648d177b90b6e9db9261de6497e4947b5b2909 Mon Sep 17 00:00:00 2001 From: "Leaf Shi (BEYONDSOFT CONSULTING INC)" Date: Wed, 17 Jul 2024 16:34:59 +0800 Subject: [PATCH] Add unit tests for ButtonBaseDesigner --- .../UnitTests/ButtonBaseDesignerTests.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/ButtonBaseDesignerTests.cs diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/ButtonBaseDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/ButtonBaseDesignerTests.cs new file mode 100644 index 00000000000..f766908794c --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/ButtonBaseDesignerTests.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections; + +namespace System.Windows.Forms.Design.Tests; + +public class ButtonBaseDesignerTests +{ + [Fact] + public void ButtonBaseDesigner_Constructor_Initialize_AutoResizeHandles() + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + bool autoResizeHandles = buttonBaseDesigner.AutoResizeHandles; + + buttonBaseDesigner.Should().NotBeNull(); + autoResizeHandles.Should().Be(true); + } + + public static IEnumerable IDictionary_TestData() + { + yield return new object[] { null }; + yield return new object[] { new Dictionary() }; + } + + [Theory] + [MemberData(nameof(IDictionary_TestData))] + public void ButtonBaseDesigner_InitializeNewComponent_WithDefaultButton(IDictionary defaultValues) + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + using Button button = new(); + buttonBaseDesigner.Initialize(button); + + buttonBaseDesigner.InitializeNewComponent(defaultValues); + } + + [Theory] + [MemberData(nameof(IDictionary_TestData))] + public void ButtonBaseDesigner_InitializeNewComponent_NotInitialized(IDictionary defaultValues) + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + Assert.Throws(() => buttonBaseDesigner.InitializeNewComponent(defaultValues)); + } + + [Fact] + public void ButtonBaseDesigner_SnapLinesWithDefaultButton_ShouldReturnExpectedCount() + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + using Button button = new(); + buttonBaseDesigner.Initialize(button); + + buttonBaseDesigner.SnapLines.Count.Should().Be(9); + } +}