From 2c02ca56ced2fca7d6235858c73e0faab840f754 Mon Sep 17 00:00:00 2001 From: Leaf Shi <132890443+LeafShi1@users.noreply.github.com> Date: Wed, 24 Jul 2024 04:42:52 +0800 Subject: [PATCH] Add unit tests for ButtonBaseDesigner (#11690) * Add unit tests for ButtonBaseDesigner --- .../UnitTests/ButtonBaseDesignerTests.cs | 56 +++++++++++++++++++ 1 file changed, 56 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..1ba2893fbd3 --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/ButtonBaseDesignerTests.cs @@ -0,0 +1,56 @@ +// 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.Collections; + +namespace System.Windows.Forms.Design.Tests; + +public sealed class ButtonBaseDesignerTests +{ + [Fact] + public void ButtonBaseDesigner_Constructor_Initialize_AutoResizeHandles() + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + + buttonBaseDesigner.AutoResizeHandles.Should().Be(true); + } + + public static TheoryData?> IDictionary_TheoryData => new() + { + null, + new Dictionary() + }; + + [Theory] + [MemberData(nameof(IDictionary_TheoryData))] + public void ButtonBaseDesigner_InitializeNewComponent_WithDefaultButton(IDictionary? defaultValues) + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + using Button button = new(); + buttonBaseDesigner.Initialize(button); + + buttonBaseDesigner.InitializeNewComponent((IDictionary?)defaultValues); + Assert.False(button.IsHandleCreated); + } + + [Theory] + [MemberData(nameof(IDictionary_TheoryData))] + public void ButtonBaseDesigner_InitializeNewComponent_NotInitialized(IDictionary? defaultValues) + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + Action action = () => buttonBaseDesigner.InitializeNewComponent((IDictionary?)defaultValues); + action.Should().Throw(); + } + + [Fact] + public void ButtonBaseDesigner_SnapLinesWithDefaultButton_ShouldReturnExpectedCount() + { + using ButtonBaseDesigner buttonBaseDesigner = new(); + using Button button = new(); + buttonBaseDesigner.Initialize(button); + + buttonBaseDesigner.SnapLines.Count.Should().Be(9); + } +}