-
Notifications
You must be signed in to change notification settings - Fork 986
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for TextBoxBaseDesigner (#12433)
* Add unit test for TextBoxBaseDesigner * Update Initialize function and remove blank line * Remove white space, add line before assertion and check default textbox text * update testcase * Removed whitespace
- Loading branch information
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
...dows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/TextBoxBaseDesignerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// 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.Design; | ||
using System.ComponentModel; | ||
using System.Windows.Forms.Design.Behavior; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
|
||
public class TextBoxBaseDesignerTests : IDisposable | ||
{ | ||
private readonly TextBoxBaseDesigner _designer; | ||
private readonly TextBox _textbox; | ||
|
||
public TextBoxBaseDesignerTests() | ||
{ | ||
_designer = new(); | ||
_textbox = new(); | ||
Mock<ISite> site = new(); | ||
site.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(new Mock<IDesignerHost>().Object); | ||
_textbox.Site = site.Object; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_designer.Dispose(); | ||
_textbox.Dispose(); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_SetsAutoResizeHandlesToTrue_AND_SelectionRules_ReturnsCorrectRules() | ||
{ | ||
_designer.AutoResizeHandles.Should().BeTrue(); | ||
_designer.Initialize(_textbox); | ||
|
||
SelectionRules rules = _designer.SelectionRules; | ||
|
||
rules.Should().NotHaveFlag(SelectionRules.TopSizeable | SelectionRules.BottomSizeable); | ||
} | ||
|
||
[WinFormsTheory] | ||
[InlineData(BorderStyle.None, 0)] | ||
[InlineData(BorderStyle.FixedSingle, 2)] | ||
[InlineData(BorderStyle.Fixed3D, 3)] | ||
public void SnapLines_ReturnsCorrectSnapLines(BorderStyle borderStyle, int expectedBaselineOffset) | ||
{ | ||
_textbox.BorderStyle = borderStyle; | ||
_designer.Initialize(_textbox); | ||
|
||
List<SnapLine> snapLines = (List<SnapLine>)_designer.SnapLines; | ||
|
||
snapLines.Should().NotBeNull(); | ||
|
||
SnapLine? baselineSnapLine = snapLines.Cast<SnapLine>().FirstOrDefault(sl => sl.SnapLineType == SnapLineType.Baseline); | ||
|
||
baselineSnapLine.Should().NotBeNull(); | ||
baselineSnapLine!.Priority.Should().Be(SnapLinePriority.Medium); | ||
int expectedBaseline = DesignerUtils.GetTextBaseline(_textbox, Drawing.ContentAlignment.TopLeft) + expectedBaselineOffset; | ||
|
||
baselineSnapLine.Offset.Should().Be(expectedBaseline); | ||
} | ||
|
||
[WinFormsTheory] | ||
[InlineData(false, true, SelectionRules.LeftSizeable | SelectionRules.RightSizeable)] | ||
[InlineData(true, true, SelectionRules.AllSizeable)] | ||
[InlineData(false, false, SelectionRules.AllSizeable)] | ||
public void SelectionRules_ReturnsCorrectRules(bool multiline, bool autoSize, SelectionRules expectedRules) | ||
{ | ||
_textbox.Multiline = multiline; | ||
_textbox.AutoSize = autoSize; | ||
_designer.Initialize(_textbox); | ||
|
||
_designer.SelectionRules.Should().HaveFlag(expectedRules); | ||
} | ||
|
||
[Fact] | ||
public void InitializeNewComponent_ClearsTextProperty() | ||
{ | ||
_textbox.Text.Should().BeEmpty(); | ||
|
||
_textbox.Text = "Test Text"; | ||
_designer.Initialize(_textbox); | ||
|
||
_textbox.Text.Should().Be("Test Text"); | ||
|
||
_designer.InitializeNewComponent(null); | ||
|
||
_textbox.Text.Should().BeEmpty(); | ||
} | ||
} |