From 964122a3697d36ffe76f8713124d96c8f9b6e475 Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Tue, 12 Nov 2024 09:56:04 +0800 Subject: [PATCH 1/3] Add code coverage for DataGridViewCellStyleConverter --- .../DataGridViewCellStyleConverterTests.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs new file mode 100644 index 00000000000..02b8b624709 --- /dev/null +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs @@ -0,0 +1,53 @@ +// 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.ComponentModel.Design.Serialization; +using System.Globalization; + +namespace System.Windows.Forms.Tests; + +public class DataGridViewCellStyleConverterTests : IDisposable +{ + private DataGridViewCellStyleConverter _converter; + private DataGridViewCellStyle _style; + + public DataGridViewCellStyleConverterTests() + { + _converter = new(); + _style = new(); + } + + public void Dispose() + { + _converter = null!; + _style = null!; + } + + [WinFormsFact] + public void CanConvertTo_InstanceDescriptor_ReturnsTrue() + { + _converter.CanConvertTo(null, typeof(InstanceDescriptor)).Should().BeTrue(); + } + + [WinFormsFact] + public void CanConvertTo_OtherType_ReturnsFalse() + { + _converter.CanConvertTo(null, typeof(int)).Should().BeFalse(); + } + + [WinFormsFact] + public void ConvertTo_InstanceDescriptor_ReturnsInstanceDescriptor() + { + _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(InstanceDescriptor)).Should().NotBeNull(); + _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(InstanceDescriptor)).Should().BeOfType(); + } + + [WinFormsFact] + public void ConvertTo_UnsupportedType_ThrowsNotSupportedException() + { + Action action = () => _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(int)); + action.Should().Throw(); + } +} From fae4c352ae631511d5f7d8226d1c0560e4ba65b3 Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Thu, 14 Nov 2024 10:51:39 +0800 Subject: [PATCH 2/3] Handle FeedBacks --- .../DataGridViewCellStyleConverterTests.cs | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs index 02b8b624709..519d2545c19 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs @@ -8,10 +8,10 @@ namespace System.Windows.Forms.Tests; -public class DataGridViewCellStyleConverterTests : IDisposable +public class DataGridViewCellStyleConverterTests { - private DataGridViewCellStyleConverter _converter; - private DataGridViewCellStyle _style; + private readonly DataGridViewCellStyleConverter _converter; + private readonly DataGridViewCellStyle _style; public DataGridViewCellStyleConverterTests() { @@ -19,29 +19,26 @@ public DataGridViewCellStyleConverterTests() _style = new(); } - public void Dispose() - { - _converter = null!; - _style = null!; - } - [WinFormsFact] public void CanConvertTo_InstanceDescriptor_ReturnsTrue() { - _converter.CanConvertTo(null, typeof(InstanceDescriptor)).Should().BeTrue(); + bool canConvertTo = _converter.CanConvertTo(null, typeof(InstanceDescriptor)); + canConvertTo.Should().BeTrue(); } [WinFormsFact] public void CanConvertTo_OtherType_ReturnsFalse() { - _converter.CanConvertTo(null, typeof(int)).Should().BeFalse(); + bool canConvertTo = _converter.CanConvertTo(null, typeof(int)); + canConvertTo.Should().BeFalse(); } [WinFormsFact] public void ConvertTo_InstanceDescriptor_ReturnsInstanceDescriptor() { - _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(InstanceDescriptor)).Should().NotBeNull(); - _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(InstanceDescriptor)).Should().BeOfType(); + object? convertTo = _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(InstanceDescriptor)); + convertTo.Should().NotBeNull(); + convertTo.Should().BeOfType(); } [WinFormsFact] From a6ba0e55b55ef8da217a36c3823549d48a165d92 Mon Sep 17 00:00:00 2001 From: "Zheng Li (Beyondsoft Corporation)" Date: Fri, 15 Nov 2024 09:17:46 +0800 Subject: [PATCH 3/3] Handle FeedBacks --- .../Windows/Forms/DataGridViewCellStyleConverterTests.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs index 519d2545c19..199298ab72d 100644 --- a/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellStyleConverterTests.cs @@ -22,15 +22,13 @@ public DataGridViewCellStyleConverterTests() [WinFormsFact] public void CanConvertTo_InstanceDescriptor_ReturnsTrue() { - bool canConvertTo = _converter.CanConvertTo(null, typeof(InstanceDescriptor)); - canConvertTo.Should().BeTrue(); + _converter.CanConvertTo(null, typeof(InstanceDescriptor)).Should().BeTrue(); } [WinFormsFact] public void CanConvertTo_OtherType_ReturnsFalse() { - bool canConvertTo = _converter.CanConvertTo(null, typeof(int)); - canConvertTo.Should().BeFalse(); + _converter.CanConvertTo(null, typeof(int)).Should().BeFalse(); } [WinFormsFact]