From 770cada254e96b151dcc312e6025f8d7ebb8dd20 Mon Sep 17 00:00:00 2001 From: v-melonwang Date: Wed, 15 May 2024 07:47:11 +0000 Subject: [PATCH 1/5] Add test coverage for MaskedTextBox --- .../tests/UnitTests/MaskedTextBoxTests.cs | 205 +++++++++++++++++- 1 file changed, 204 insertions(+), 1 deletion(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs index 3a3b0f1a8be..3096d7bdb08 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs @@ -2,12 +2,25 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.ComponentModel; +using System.Drawing; using System.Globalization; namespace System.Windows.Forms.Tests; -public class MaskedTextBoxTests +public class MaskedTextBoxTests : IDisposable { + private readonly MaskedTextBox _maskedTextBox; + + public MaskedTextBoxTests() + { + _maskedTextBox = new(); + } + + public void Dispose() + { + _maskedTextBox.Dispose(); + } + [WinFormsFact] public void MaskedTextBox_Constructor() { @@ -28,6 +41,16 @@ public void MaskedTextBox_Constructor() mtb.ValidatingType.Should().BeNull(); mtb.TextAlign.Should().Be(HorizontalAlignment.Left); mtb.FormatProvider.Should().Be(null); + mtb.ResetOnPrompt.Should().BeTrue(); + mtb.ValidatingType.Should().BeNull(); + mtb.PromptChar.Should().Be('_'); + mtb.GetLineFromCharIndex(2).Should().Be(0); + mtb.GetFirstCharIndexFromLine(100).Should().Be(0); + mtb.GetFirstCharIndexOfCurrentLine().Should().Be(0); + mtb.PasswordChar.Should().Be('\0'); + mtb.RejectInputOnFirstFailure.Should().BeFalse(); + mtb.Text.Should().Be(string.Empty); + mtb.UseSystemPasswordChar.Should().BeFalse(); mtb.IsHandleCreated.Should().BeFalse(); } @@ -670,4 +693,184 @@ public void MaskedTextBox_TextAlignChangedEvent_AddRemove_Success() control.TextAlign = HorizontalAlignment.Right; callCount.Should().Be(1); } + + [WinFormsTheory] + [BoolData] + public void MaskedTextBox_RejectInputOnFirstFailure_GetSet_ReturnsExpected(bool value) + { + _maskedTextBox.RejectInputOnFirstFailure = value; + _maskedTextBox.RejectInputOnFirstFailure.Should().Be(value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + + _maskedTextBox.RejectInputOnFirstFailure = value; + _maskedTextBox.RejectInputOnFirstFailure.Should().Be(value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + + _maskedTextBox.RejectInputOnFirstFailure = !value; + _maskedTextBox.RejectInputOnFirstFailure.Should().Be(!value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + } + + [WinFormsTheory] + [BoolData] + public void MaskedTextBox_ResetOnPrompt_GetSet_ReturnsExpected(bool value) + { + _maskedTextBox.ResetOnPrompt = value; + _maskedTextBox.ResetOnPrompt.Should().Be(value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + + _maskedTextBox.ResetOnPrompt = value; + _maskedTextBox.ResetOnPrompt.Should().Be(value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + + _maskedTextBox.ResetOnPrompt = !value; + _maskedTextBox.ResetOnPrompt.Should().Be(!value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + } + + [WinFormsTheory] + [InlineData(typeof(int))] + [InlineData(typeof(string))] + [InlineData(null)] + public void MaskedTextBox_ValidatingType_Set_GetReturnsExpected(Type value) + { + _maskedTextBox.ValidatingType = value; + _maskedTextBox.ValidatingType.Should().Be(value); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + } + + [WinFormsFact] + public void MaskedTextBox_TypeValidationCompletedEvent_AddRemove_Success() + { + int callCount = 0; + TypeValidationEventHandler handler = (sender, e) => + { + sender.Should().Be(_maskedTextBox); + e.Should().NotBeNull(); + callCount++; + }; + + _maskedTextBox.ValidatingType = typeof(int); + _maskedTextBox.TypeValidationCompleted += handler; + _maskedTextBox.ValidateText(); + callCount.Should().Be(1); + + _maskedTextBox.TypeValidationCompleted -= handler; + _maskedTextBox.ValidateText(); + callCount.Should().Be(1); + } + + [WinFormsTheory] + [InlineData('A', 'B')] + [InlineData('1', '2')] + [InlineData('%', '&')] + public void MaskedTextBox_PromptChar_Set_GetReturnsExpected(char originalValue, char value) + { + _maskedTextBox.PromptChar = originalValue; + _maskedTextBox.PromptChar.Should().Be(originalValue); + + _maskedTextBox.PromptChar = value; + _maskedTextBox.PromptChar.Should().Be(value); + + _maskedTextBox.Handle.Should().NotBe(IntPtr.Zero); + _maskedTextBox.PromptChar = originalValue; + _maskedTextBox.PromptChar.Should().Be(originalValue); + + Action act = () => _maskedTextBox.PromptChar = '\0'; + act.Should().Throw(); + + _maskedTextBox.PasswordChar = '*'; + Action act2 = () => _maskedTextBox.PromptChar = '*'; + act2.Should().Throw(); + } + + [WinFormsFact] + public void MaskedTextBox_GetCharFromPosition_ReturnsExpected() + { + _maskedTextBox.Text = "Hello, World!"; + _maskedTextBox.CreateControl(); + + Point position = _maskedTextBox.GetPositionFromCharIndex(4); + char result = _maskedTextBox.GetCharFromPosition(position); + + result.Should().Be('o'); + } + + [WinFormsFact] + public void MaskedTextBox_GetCharIndexFromPosition_ReturnsExpected() + { + _maskedTextBox.Text = "Hello, World!"; + _maskedTextBox.CreateControl(); + + Point position = _maskedTextBox.GetPositionFromCharIndex(4); + int result = _maskedTextBox.GetCharIndexFromPosition(position); + + result.Should().Be(4); + } + + [WinFormsFact] + public void MaskedTextBox_GetPositionFromCharIndex_ReturnsExpected() + { + _maskedTextBox.Text = "Hello, World!"; + _maskedTextBox.CreateControl(); + + Point result = _maskedTextBox.GetPositionFromCharIndex(4); + + result.Should().NotBe(Point.Empty); + } + + [WinFormsFact] + public void MaskedTextBox_ValidateText_ReturnsExpected() + { + _maskedTextBox.ValidatingType = typeof(int); + _maskedTextBox.Text = "12345"; + _maskedTextBox.CreateControl(); + + object result = _maskedTextBox.ValidateText(); + + result.Should().NotBeNull(); + } + + [WinFormsTheory] + [InlineData('A', 'B')] + [InlineData('1', '2')] + [InlineData('%', '&')] + public void MaskedTextBox_PasswordChar_Set_GetReturnsExpected(char originalValue, char value) + { + _maskedTextBox.PasswordChar = originalValue; + _maskedTextBox.PasswordChar.Should().Be(originalValue); + + // Set different. + _maskedTextBox.PasswordChar = value; + _maskedTextBox.PasswordChar.Should().Be(value); + } + + [WinFormsFact] + public void MaskedTextBox_PasswordChar_SetInvalid_ThrowsArgumentException() + { + Action act = () => _maskedTextBox.PasswordChar = '\t'; + act.Should().Throw(); + } + + [WinFormsFact] + public void MaskedTextBox_PasswordChar_SetSameAsPromptChar_ThrowsInvalidOperationException() + { + _maskedTextBox.PromptChar = 'A'; + Action act = () => _maskedTextBox.PasswordChar = 'A'; + act.Should().Throw(); + } + + [WinFormsFact] + public void MaskedTextBox_PasswordChar_SetWithUseSystemPasswordChar_UpdatesMaskedTextProvider() + { + _maskedTextBox.Mask = "00000"; + _maskedTextBox.UseSystemPasswordChar = true; + _maskedTextBox.PasswordChar = 'A'; + + if (_maskedTextBox.MaskedTextProvider is not null) + { + _maskedTextBox.PasswordChar.Should().Be('●'); + _maskedTextBox.MaskedTextProvider.PasswordChar.Should().Be('●'); + } + } } From d742242f959b4e15403c200623acd198c7982a18 Mon Sep 17 00:00:00 2001 From: v-melonwang Date: Thu, 16 May 2024 09:54:54 +0000 Subject: [PATCH 2/5] Handle feedback --- .../tests/UnitTests/MaskedTextBoxTests.cs | 186 +++++++----------- 1 file changed, 68 insertions(+), 118 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs index 3096d7bdb08..33224839bc8 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Drawing; using System.Globalization; +using System.Reflection; namespace System.Windows.Forms.Tests; @@ -696,51 +697,48 @@ public void MaskedTextBox_TextAlignChangedEvent_AddRemove_Success() [WinFormsTheory] [BoolData] - public void MaskedTextBox_RejectInputOnFirstFailure_GetSet_ReturnsExpected(bool value) + public void MaskedTextBox_BooleanProperty_GetSet_ReturnsExpected(bool value) { - _maskedTextBox.RejectInputOnFirstFailure = value; - _maskedTextBox.RejectInputOnFirstFailure.Should().Be(value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); - - _maskedTextBox.RejectInputOnFirstFailure = value; - _maskedTextBox.RejectInputOnFirstFailure.Should().Be(value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); - - _maskedTextBox.RejectInputOnFirstFailure = !value; - _maskedTextBox.RejectInputOnFirstFailure.Should().Be(!value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); + TestProperty(_maskedTextBox, nameof(MaskedTextBox.RejectInputOnFirstFailure), value); + TestProperty(_maskedTextBox, nameof(MaskedTextBox.ResetOnPrompt), value); } - [WinFormsTheory] - [BoolData] - public void MaskedTextBox_ResetOnPrompt_GetSet_ReturnsExpected(bool value) + private void TestProperty(MaskedTextBox maskedTextBox, string propertyName, bool value) { - _maskedTextBox.ResetOnPrompt = value; - _maskedTextBox.ResetOnPrompt.Should().Be(value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); + PropertyInfo property = typeof(MaskedTextBox).GetProperty(propertyName); - _maskedTextBox.ResetOnPrompt = value; - _maskedTextBox.ResetOnPrompt.Should().Be(value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); + property.SetValue(maskedTextBox, value); + property.GetValue(maskedTextBox).Should().Be(value); + maskedTextBox.IsHandleCreated.Should().BeFalse(); - _maskedTextBox.ResetOnPrompt = !value; - _maskedTextBox.ResetOnPrompt.Should().Be(!value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); + property.SetValue(maskedTextBox, !value); + property.GetValue(maskedTextBox).Should().Be(!value); + maskedTextBox.IsHandleCreated.Should().BeFalse(); } - [WinFormsTheory] - [InlineData(typeof(int))] - [InlineData(typeof(string))] - [InlineData(null)] - public void MaskedTextBox_ValidatingType_Set_GetReturnsExpected(Type value) + [WinFormsFact] + public void MaskedTextBox_GetCharAndPosition_ReturnsExpected() { - _maskedTextBox.ValidatingType = value; - _maskedTextBox.ValidatingType.Should().Be(value); - _maskedTextBox.IsHandleCreated.Should().BeFalse(); + _maskedTextBox.Text = "Hello, World!"; + _maskedTextBox.CreateControl(); + + // Test GetPositionFromCharIndex + Point position = _maskedTextBox.GetPositionFromCharIndex(4); + position.Should().NotBe(Point.Empty); + + // Test GetCharFromPosition + char resultChar = _maskedTextBox.GetCharFromPosition(position); + resultChar.Should().Be('o'); + + // Test GetCharIndexFromPosition + int resultIndex = _maskedTextBox.GetCharIndexFromPosition(position); + resultIndex.Should().Be(4); } - [WinFormsFact] - public void MaskedTextBox_TypeValidationCompletedEvent_AddRemove_Success() + [WinFormsTheory] + [InlineData(typeof(int), "12345")] + [InlineData(typeof(string), "Hello")] + public void MaskedTextBox_ValidatingTypeAndValidateText_ReturnsExpected(Type validatingType, string text) { int callCount = 0; TypeValidationEventHandler handler = (sender, e) => @@ -750,9 +748,16 @@ public void MaskedTextBox_TypeValidationCompletedEvent_AddRemove_Success() callCount++; }; - _maskedTextBox.ValidatingType = typeof(int); + _maskedTextBox.ValidatingType = validatingType; + _maskedTextBox.ValidatingType.Should().Be(validatingType); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); + + _maskedTextBox.Text = text; + _maskedTextBox.CreateControl(); + _maskedTextBox.TypeValidationCompleted += handler; - _maskedTextBox.ValidateText(); + object result = _maskedTextBox.ValidateText(); + result.Should().NotBeNull(); callCount.Should().Be(1); _maskedTextBox.TypeValidationCompleted -= handler; @@ -761,95 +766,40 @@ public void MaskedTextBox_TypeValidationCompletedEvent_AddRemove_Success() } [WinFormsTheory] - [InlineData('A', 'B')] - [InlineData('1', '2')] - [InlineData('%', '&')] - public void MaskedTextBox_PromptChar_Set_GetReturnsExpected(char originalValue, char value) - { - _maskedTextBox.PromptChar = originalValue; - _maskedTextBox.PromptChar.Should().Be(originalValue); - - _maskedTextBox.PromptChar = value; - _maskedTextBox.PromptChar.Should().Be(value); - - _maskedTextBox.Handle.Should().NotBe(IntPtr.Zero); - _maskedTextBox.PromptChar = originalValue; - _maskedTextBox.PromptChar.Should().Be(originalValue); - - Action act = () => _maskedTextBox.PromptChar = '\0'; - act.Should().Throw(); - - _maskedTextBox.PasswordChar = '*'; - Action act2 = () => _maskedTextBox.PromptChar = '*'; - act2.Should().Throw(); - } - - [WinFormsFact] - public void MaskedTextBox_GetCharFromPosition_ReturnsExpected() - { - _maskedTextBox.Text = "Hello, World!"; - _maskedTextBox.CreateControl(); - - Point position = _maskedTextBox.GetPositionFromCharIndex(4); - char result = _maskedTextBox.GetCharFromPosition(position); - - result.Should().Be('o'); - } - - [WinFormsFact] - public void MaskedTextBox_GetCharIndexFromPosition_ReturnsExpected() - { - _maskedTextBox.Text = "Hello, World!"; - _maskedTextBox.CreateControl(); - - Point position = _maskedTextBox.GetPositionFromCharIndex(4); - int result = _maskedTextBox.GetCharIndexFromPosition(position); - - result.Should().Be(4); - } - - [WinFormsFact] - public void MaskedTextBox_GetPositionFromCharIndex_ReturnsExpected() - { - _maskedTextBox.Text = "Hello, World!"; - _maskedTextBox.CreateControl(); - - Point result = _maskedTextBox.GetPositionFromCharIndex(4); - - result.Should().NotBe(Point.Empty); - } - - [WinFormsFact] - public void MaskedTextBox_ValidateText_ReturnsExpected() - { - _maskedTextBox.ValidatingType = typeof(int); - _maskedTextBox.Text = "12345"; - _maskedTextBox.CreateControl(); - - object result = _maskedTextBox.ValidateText(); - - result.Should().NotBeNull(); - } + [InlineData('A', 'B', true)] + [InlineData('1', '2', true)] + [InlineData('%', '&', true)] + [InlineData('A', 'B', false)] + [InlineData('1', '2', false)] + [InlineData('%', '&', false)] + public void MaskedTextBox_CharProperties_Set_GetReturnsExpected(char originalValue, char value, bool isPasswordChar) + { + if (isPasswordChar) + { + _maskedTextBox.PasswordChar = originalValue; + _maskedTextBox.PasswordChar.Should().Be(originalValue); - [WinFormsTheory] - [InlineData('A', 'B')] - [InlineData('1', '2')] - [InlineData('%', '&')] - public void MaskedTextBox_PasswordChar_Set_GetReturnsExpected(char originalValue, char value) - { - _maskedTextBox.PasswordChar = originalValue; - _maskedTextBox.PasswordChar.Should().Be(originalValue); + _maskedTextBox.PasswordChar = value; + _maskedTextBox.PasswordChar.Should().Be(value); + } + else + { + _maskedTextBox.PromptChar = originalValue; + _maskedTextBox.PromptChar.Should().Be(originalValue); - // Set different. - _maskedTextBox.PasswordChar = value; - _maskedTextBox.PasswordChar.Should().Be(value); + _maskedTextBox.PromptChar = value; + _maskedTextBox.PromptChar.Should().Be(value); + } } [WinFormsFact] - public void MaskedTextBox_PasswordChar_SetInvalid_ThrowsArgumentException() + public void MaskedTextBox_PromptCharAndPasswordChar_SetInvalid_ThrowsArgumentException() { - Action act = () => _maskedTextBox.PasswordChar = '\t'; + Action act = () => _maskedTextBox.PromptChar = '\0'; act.Should().Throw(); + + Action act2 = () => _maskedTextBox.PasswordChar = '\t'; + act2.Should().Throw(); } [WinFormsFact] From de9ed647dd66229aac7afc403b992ad22eac3bd2 Mon Sep 17 00:00:00 2001 From: v-melonwang Date: Thu, 23 May 2024 08:32:20 +0000 Subject: [PATCH 3/5] Updated --- .../tests/UnitTests/MaskedTextBoxTests.cs | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs index 33224839bc8..a3a63fa3fdb 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs @@ -25,51 +25,51 @@ public void Dispose() [WinFormsFact] public void MaskedTextBox_Constructor() { - using MaskedTextBox mtb = new(); + using MaskedTextBox maskedTextBox = new(); - Assert.NotNull(mtb); + Assert.NotNull(maskedTextBox); // Check default values - mtb.BeepOnError.Should().BeFalse(); - mtb.AsciiOnly.Should().BeFalse(); - mtb.Culture.Should().Be(CultureInfo.CurrentCulture); - mtb.AcceptsTab.Should().BeFalse(); - mtb.CanUndo.Should().BeFalse(); - mtb.WordWrap.Should().BeFalse(); - mtb.Multiline.Should().BeFalse(); - mtb.ResetOnSpace.Should().BeTrue(); - mtb.SkipLiterals.Should().BeTrue(); - mtb.ValidatingType.Should().BeNull(); - mtb.TextAlign.Should().Be(HorizontalAlignment.Left); - mtb.FormatProvider.Should().Be(null); - mtb.ResetOnPrompt.Should().BeTrue(); - mtb.ValidatingType.Should().BeNull(); - mtb.PromptChar.Should().Be('_'); - mtb.GetLineFromCharIndex(2).Should().Be(0); - mtb.GetFirstCharIndexFromLine(100).Should().Be(0); - mtb.GetFirstCharIndexOfCurrentLine().Should().Be(0); - mtb.PasswordChar.Should().Be('\0'); - mtb.RejectInputOnFirstFailure.Should().BeFalse(); - mtb.Text.Should().Be(string.Empty); - mtb.UseSystemPasswordChar.Should().BeFalse(); - - mtb.IsHandleCreated.Should().BeFalse(); + maskedTextBox.BeepOnError.Should().BeFalse(); + maskedTextBox.AsciiOnly.Should().BeFalse(); + maskedTextBox.Culture.Should().Be(CultureInfo.CurrentCulture); + maskedTextBox.AcceptsTab.Should().BeFalse(); + maskedTextBox.CanUndo.Should().BeFalse(); + maskedTextBox.WordWrap.Should().BeFalse(); + maskedTextBox.Multiline.Should().BeFalse(); + maskedTextBox.ResetOnSpace.Should().BeTrue(); + maskedTextBox.SkipLiterals.Should().BeTrue(); + maskedTextBox.ValidatingType.Should().BeNull(); + maskedTextBox.TextAlign.Should().Be(HorizontalAlignment.Left); + maskedTextBox.FormatProvider.Should().Be(null); + maskedTextBox.ResetOnPrompt.Should().BeTrue(); + maskedTextBox.ValidatingType.Should().BeNull(); + maskedTextBox.PromptChar.Should().Be('_'); + maskedTextBox.GetLineFromCharIndex(2).Should().Be(0); + maskedTextBox.GetFirstCharIndexFromLine(100).Should().Be(0); + maskedTextBox.GetFirstCharIndexOfCurrentLine().Should().Be(0); + maskedTextBox.PasswordChar.Should().Be('\0'); + maskedTextBox.RejectInputOnFirstFailure.Should().BeFalse(); + maskedTextBox.Text.Should().Be(string.Empty); + maskedTextBox.UseSystemPasswordChar.Should().BeFalse(); + + maskedTextBox.IsHandleCreated.Should().BeFalse(); } [WinFormsFact] public void MaskedTextBox_ConstructorString() { - using MaskedTextBox mtb = new("Hello World!"); + using MaskedTextBox maskedTextBox = new("Hello World!"); - Assert.NotNull(mtb); + Assert.NotNull(maskedTextBox); } [WinFormsFact] public void MaskedTextBox_ConstructorMaskedTextProvider() { - using MaskedTextBox mtb = new(new MaskedTextProvider("Hello World!")); + using MaskedTextBox maskedTextBox = new(new MaskedTextProvider("Hello World!")); - Assert.NotNull(mtb); + Assert.NotNull(maskedTextBox); } [WinFormsTheory] From 9ee4b307d7a078bef890e42f2ee95a6b259ea5e8 Mon Sep 17 00:00:00 2001 From: v-melonwang Date: Fri, 24 May 2024 09:55:12 +0000 Subject: [PATCH 4/5] Updated --- .../tests/UnitTests/MaskedTextBoxTests.cs | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs index a3a63fa3fdb..ac7b3a611e0 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs @@ -25,35 +25,33 @@ public void Dispose() [WinFormsFact] public void MaskedTextBox_Constructor() { - using MaskedTextBox maskedTextBox = new(); - - Assert.NotNull(maskedTextBox); + Assert.NotNull(_maskedTextBox); // Check default values - maskedTextBox.BeepOnError.Should().BeFalse(); - maskedTextBox.AsciiOnly.Should().BeFalse(); - maskedTextBox.Culture.Should().Be(CultureInfo.CurrentCulture); - maskedTextBox.AcceptsTab.Should().BeFalse(); - maskedTextBox.CanUndo.Should().BeFalse(); - maskedTextBox.WordWrap.Should().BeFalse(); - maskedTextBox.Multiline.Should().BeFalse(); - maskedTextBox.ResetOnSpace.Should().BeTrue(); - maskedTextBox.SkipLiterals.Should().BeTrue(); - maskedTextBox.ValidatingType.Should().BeNull(); - maskedTextBox.TextAlign.Should().Be(HorizontalAlignment.Left); - maskedTextBox.FormatProvider.Should().Be(null); - maskedTextBox.ResetOnPrompt.Should().BeTrue(); - maskedTextBox.ValidatingType.Should().BeNull(); - maskedTextBox.PromptChar.Should().Be('_'); - maskedTextBox.GetLineFromCharIndex(2).Should().Be(0); - maskedTextBox.GetFirstCharIndexFromLine(100).Should().Be(0); - maskedTextBox.GetFirstCharIndexOfCurrentLine().Should().Be(0); - maskedTextBox.PasswordChar.Should().Be('\0'); - maskedTextBox.RejectInputOnFirstFailure.Should().BeFalse(); - maskedTextBox.Text.Should().Be(string.Empty); - maskedTextBox.UseSystemPasswordChar.Should().BeFalse(); + _maskedTextBox.BeepOnError.Should().BeFalse(); + _maskedTextBox.AsciiOnly.Should().BeFalse(); + _maskedTextBox.Culture.Should().Be(CultureInfo.CurrentCulture); + _maskedTextBox.AcceptsTab.Should().BeFalse(); + _maskedTextBox.CanUndo.Should().BeFalse(); + _maskedTextBox.WordWrap.Should().BeFalse(); + _maskedTextBox.Multiline.Should().BeFalse(); + _maskedTextBox.ResetOnSpace.Should().BeTrue(); + _maskedTextBox.SkipLiterals.Should().BeTrue(); + _maskedTextBox.ValidatingType.Should().BeNull(); + _maskedTextBox.TextAlign.Should().Be(HorizontalAlignment.Left); + _maskedTextBox.FormatProvider.Should().Be(null); + _maskedTextBox.ResetOnPrompt.Should().BeTrue(); + _maskedTextBox.ValidatingType.Should().BeNull(); + _maskedTextBox.PromptChar.Should().Be('_'); + _maskedTextBox.GetLineFromCharIndex(2).Should().Be(0); + _maskedTextBox.GetFirstCharIndexFromLine(100).Should().Be(0); + _maskedTextBox.GetFirstCharIndexOfCurrentLine().Should().Be(0); + _maskedTextBox.PasswordChar.Should().Be('\0'); + _maskedTextBox.RejectInputOnFirstFailure.Should().BeFalse(); + _maskedTextBox.Text.Should().Be(string.Empty); + _maskedTextBox.UseSystemPasswordChar.Should().BeFalse(); - maskedTextBox.IsHandleCreated.Should().BeFalse(); + _maskedTextBox.IsHandleCreated.Should().BeFalse(); } [WinFormsFact] From 56e598f8627877b510abd0b4844937048984dd49 Mon Sep 17 00:00:00 2001 From: v-melonwang Date: Fri, 24 May 2024 10:22:12 +0000 Subject: [PATCH 5/5] Updated --- .../tests/UnitTests/MaskedTextBoxTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs index ac7b3a611e0..83ed18ce717 100644 --- a/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs +++ b/src/System.Windows.Forms/tests/UnitTests/MaskedTextBoxTests.cs @@ -25,7 +25,7 @@ public void Dispose() [WinFormsFact] public void MaskedTextBox_Constructor() { - Assert.NotNull(_maskedTextBox); + _maskedTextBox.Should().NotBeNull(); // Check default values _maskedTextBox.BeepOnError.Should().BeFalse(); @@ -59,7 +59,7 @@ public void MaskedTextBox_ConstructorString() { using MaskedTextBox maskedTextBox = new("Hello World!"); - Assert.NotNull(maskedTextBox); + maskedTextBox.Should().NotBeNull(); } [WinFormsFact] @@ -67,7 +67,7 @@ public void MaskedTextBox_ConstructorMaskedTextProvider() { using MaskedTextBox maskedTextBox = new(new MaskedTextProvider("Hello World!")); - Assert.NotNull(maskedTextBox); + maskedTextBox.Should().NotBeNull(); } [WinFormsTheory]