From 27297b5d1a54a49cff7a0adafdc1c92a977b9455 Mon Sep 17 00:00:00 2001 From: Olina-Zhang Date: Tue, 23 Jul 2024 07:58:07 +0000 Subject: [PATCH 1/3] Add unit tests for FlowPanelDesigner --- .../Forms/Design/FlowPanelDesignerTests.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs new file mode 100644 index 00000000000..474ecbac52d --- /dev/null +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs @@ -0,0 +1,59 @@ +// 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 Moq; +using System.ComponentModel; +using System.ComponentModel.Design; +using System.Windows.Forms.Design.Behavior; + +namespace System.Windows.Forms.Design.Tests; + +public sealed class FlowPanelDesignerTests +{ + private (Panel panel, FlowPanelDesigner designer) SetupDesignerWithPanel() + { + var mockHost = new Mock(); + var mockContainer = new Mock(); + mockHost.Setup(host => host.Container).Returns(mockContainer.Object); + + Panel panel = new(); + mockContainer.Object.Add(panel); + + FlowPanelDesigner designer = new(); + designer.Initialize(panel); + + return (panel, designer); + } + + [Fact] + public void ParticipatesWithSnapLines_ShouldAlwaysReturnFalse() + { + var (_, designer) = SetupDesignerWithPanel(); + + designer.ParticipatesWithSnapLines.Should().BeFalse(); + } + + [Fact] + public void SnapLines_ShouldNotContainPaddingSnapLines() + { + var (_, designer) = SetupDesignerWithPanel(); + + var snapLines = designer.SnapLines as IList; + + snapLines.Should().NotBeNull(); + snapLines.Should().NotContain(line => line.Filter is object && line.Filter.Contains(SnapLine.Padding)); + } + + [Fact] + public void SnapLines_ShouldReturnNonPaddingSnapLines() + { + var (_, designer) = SetupDesignerWithPanel(); + + var snapLines = designer.SnapLines as IList; + + snapLines.Should().NotBeNull(); + snapLines.Should().Contain(line => line.Filter == null || !line.Filter.Contains(SnapLine.Padding)); + } +} From 8f87f3349753fe8ee106756241a8f84fea93d396 Mon Sep 17 00:00:00 2001 From: Olina-Zhang Date: Wed, 24 Jul 2024 08:16:48 +0000 Subject: [PATCH 2/3] update --- .../System/Windows/Forms/Design/FlowPanelDesignerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs index 474ecbac52d..673ee9b9581 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs @@ -14,8 +14,8 @@ public sealed class FlowPanelDesignerTests { private (Panel panel, FlowPanelDesigner designer) SetupDesignerWithPanel() { - var mockHost = new Mock(); - var mockContainer = new Mock(); + Mock mockHost = new(); + Mock mockContainer = new(); mockHost.Setup(host => host.Container).Returns(mockContainer.Object); Panel panel = new(); From f6a63148749a069715a6165e8d6b772086984fc4 Mon Sep 17 00:00:00 2001 From: Olina-Zhang Date: Thu, 1 Aug 2024 08:07:50 +0000 Subject: [PATCH 3/3] Remove panel returning --- .../Windows/Forms/Design/FlowPanelDesignerTests.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs index 673ee9b9581..c4b29c65f18 100644 --- a/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs +++ b/src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FlowPanelDesignerTests.cs @@ -12,7 +12,7 @@ namespace System.Windows.Forms.Design.Tests; public sealed class FlowPanelDesignerTests { - private (Panel panel, FlowPanelDesigner designer) SetupDesignerWithPanel() + private FlowPanelDesigner SetupDesignerWithPanel() { Mock mockHost = new(); Mock mockContainer = new(); @@ -24,13 +24,13 @@ public sealed class FlowPanelDesignerTests FlowPanelDesigner designer = new(); designer.Initialize(panel); - return (panel, designer); + return (designer); } [Fact] public void ParticipatesWithSnapLines_ShouldAlwaysReturnFalse() { - var (_, designer) = SetupDesignerWithPanel(); + var designer = SetupDesignerWithPanel(); designer.ParticipatesWithSnapLines.Should().BeFalse(); } @@ -38,7 +38,7 @@ public void ParticipatesWithSnapLines_ShouldAlwaysReturnFalse() [Fact] public void SnapLines_ShouldNotContainPaddingSnapLines() { - var (_, designer) = SetupDesignerWithPanel(); + var designer = SetupDesignerWithPanel(); var snapLines = designer.SnapLines as IList; @@ -49,7 +49,7 @@ public void SnapLines_ShouldNotContainPaddingSnapLines() [Fact] public void SnapLines_ShouldReturnNonPaddingSnapLines() { - var (_, designer) = SetupDesignerWithPanel(); + var designer = SetupDesignerWithPanel(); var snapLines = designer.SnapLines as IList;