Skip to content

Commit 949909e

Browse files
committed
Address FeedBacks
1 parent 2887987 commit 949909e

File tree

1 file changed

+63
-42
lines changed

1 file changed

+63
-42
lines changed

src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DesignerUtilsTests.cs

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -405,27 +405,43 @@ internal void GetBoundsForSelectionType_ShouldReturnExpectedBounds(
405405
}
406406

407407
[WinFormsFact]
408-
public void ApplyListViewThemeStyles_ShouldNotThrow_WhenCalledWithValidListView()
408+
public void ApplyListViewThemeStyles_ShouldSetWindowThemeToExplorer()
409409
{
410410
using ListView listView = new();
411411
Exception exception = Record.Exception(() => DesignerUtils.ApplyListViewThemeStyles(listView));
412412
exception.Should().BeNull();
413+
listView.IsHandleCreated.Should().BeTrue();
413414
}
414415

415416
[WinFormsFact]
416-
public void ApplyTreeViewThemeStyles_ShouldNotThrow_WhenCalledWithValidTreeView()
417+
public void ApplyListViewThemeStyles_ShouldThrowArgumentNullException_WhenListViewIsNull()
418+
{
419+
Action action = () => DesignerUtils.ApplyListViewThemeStyles(null!);
420+
action.Should().Throw<ArgumentNullException>();
421+
}
422+
423+
[WinFormsFact]
424+
public void ApplyTreeViewThemeStyles_ShouldSetWindowThemeToExplorer()
417425
{
418426
using TreeView treeView = new();
419427
Exception exception = Record.Exception(() => DesignerUtils.ApplyTreeViewThemeStyles(treeView));
420428
exception.Should().BeNull();
429+
treeView.IsHandleCreated.Should().BeTrue();
430+
}
431+
432+
[WinFormsFact]
433+
public void ApplyTreeViewThemeStyles_ShouldThrowArgumentNullException_WhenTreeViewIsNull()
434+
{
435+
Action action = () => DesignerUtils.ApplyTreeViewThemeStyles(null!);
436+
action.Should().Throw<ArgumentNullException>();
421437
}
422438

423439
[WinFormsFact]
424440
public void CheckForNestedContainer_ShouldReturnSameContainer_WhenNotNested()
425441
{
426-
Mock<IContainer> mockContainer = new();
427-
IContainer? result = DesignerUtils.CheckForNestedContainer(mockContainer.Object);
428-
result.Should().BeSameAs(mockContainer.Object);
442+
Mock<IContainer> nestedContainer = new();
443+
IContainer? result = DesignerUtils.CheckForNestedContainer(nestedContainer.Object);
444+
result.Should().BeSameAs(nestedContainer.Object);
429445
}
430446

431447
[WinFormsFact]
@@ -499,36 +515,59 @@ public void GetUniqueSiteName_ShouldReturnName_WhenNameIsNotInUseAndValid()
499515
[InlineData(0, 0, 100, 100, 10, 10, ToolboxSnapDragDropEventArgs.SnapDirection.Top, true, 0, 10)]
500516
[InlineData(0, 0, 100, 100, 10, 10, ToolboxSnapDragDropEventArgs.SnapDirection.Right, true, -10, 0)]
501517
internal void GetBoundsFromToolboxSnapDragDropInfo_ShouldReturnExpectedBounds(
502-
int x, int y, int width, int height, int offsetX, int offsetY,
503-
ToolboxSnapDragDropEventArgs.SnapDirection snapDirection, bool isMirrored,
504-
int expectedX, int expectedY)
518+
int x,
519+
int y,
520+
int width,
521+
int height,
522+
int offsetX,
523+
int offsetY,
524+
ToolboxSnapDragDropEventArgs.SnapDirection snapDirection,
525+
bool isMirrored,
526+
int expectedX,
527+
int expectedY)
505528
{
506529
Rectangle originalBounds = new(x, y, width, height);
507-
ToolboxSnapDragDropEventArgs args = new(snapDirection, new Point(offsetX, offsetY), new DragEventArgs(null, 0, 0, 0, DragDropEffects.None, DragDropEffects.None));
508-
509-
Rectangle result = DesignerUtils.GetBoundsFromToolboxSnapDragDropInfo(e: args, originalBounds: originalBounds, isMirrored: isMirrored);
530+
ToolboxSnapDragDropEventArgs args = new(
531+
snapDirection,
532+
new Point(offsetX, offsetY),
533+
new DragEventArgs(
534+
null,
535+
0,
536+
0,
537+
0,
538+
DragDropEffects.None,
539+
DragDropEffects.None));
540+
541+
Rectangle result = DesignerUtils.GetBoundsFromToolboxSnapDragDropInfo(
542+
e: args,
543+
originalBounds: originalBounds,
544+
isMirrored: isMirrored);
510545

511546
result.X.Should().Be(expectedX);
512547
result.Y.Should().Be(expectedY);
513548
}
514549

515550
[WinFormsTheory]
516-
[InlineData(ContentAlignment.TopLeft, 14)]
517-
[InlineData(ContentAlignment.TopCenter, 14)]
518-
[InlineData(ContentAlignment.TopRight, 14)]
519-
[InlineData(ContentAlignment.MiddleLeft, 31)]
520-
[InlineData(ContentAlignment.MiddleCenter, 31)]
521-
[InlineData(ContentAlignment.MiddleRight, 31)]
522-
[InlineData(ContentAlignment.BottomLeft, 48)]
523-
[InlineData(ContentAlignment.BottomCenter, 48)]
524-
[InlineData(ContentAlignment.BottomRight, 48)]
525-
public void GetTextBaseline_ShouldReturnExpectedBaseline(ContentAlignment alignment, int expectedBaseline)
551+
[InlineData(100, 50, "Arial", 10, ContentAlignment.TopLeft, 14)]
552+
[InlineData(100, 50, "Arial", 10, ContentAlignment.TopCenter, 14)]
553+
[InlineData(100, 50, "Arial", 10, ContentAlignment.TopRight, 14)]
554+
[InlineData(100, 50, "Arial", 10, ContentAlignment.MiddleLeft, 31)]
555+
[InlineData(100, 50, "Arial", 10, ContentAlignment.MiddleCenter, 31)]
556+
[InlineData(100, 50, "Arial", 10, ContentAlignment.MiddleRight, 31)]
557+
[InlineData(100, 50, "Arial", 10, ContentAlignment.BottomLeft, 48)]
558+
[InlineData(100, 50, "Arial", 10, ContentAlignment.BottomCenter, 48)]
559+
[InlineData(100, 50, "Arial", 10, ContentAlignment.BottomRight, 48)]
560+
[InlineData(200, 100, "Times New Roman", 12, ContentAlignment.TopLeft, 16)]
561+
[InlineData(200, 100, "Times New Roman", 12, ContentAlignment.MiddleCenter, 57)]
562+
[InlineData(200, 100, "Times New Roman", 12, ContentAlignment.BottomRight, 97)]
563+
public void GetTextBaseline_ShouldReturnExpectedBaseline_WithVariousFontsAndBounds(
564+
int width, int height, string fontFamily, float fontSize, ContentAlignment alignment, int expectedBaseline)
526565
{
527566
using Button button = new()
528567
{
529-
Width = 100,
530-
Height = 50,
531-
Font = new Font("Arial", 10)
568+
Width = width,
569+
Height = height,
570+
Font = new Font(fontFamily, fontSize)
532571
};
533572

534573
int baseline = DesignerUtils.GetTextBaseline(button, alignment);
@@ -543,22 +582,4 @@ public void GetTextBaseline_ShouldThrowNullNullException_WhenControlIsNull()
543582

544583
action.Should().Throw<NullReferenceException>();
545584
}
546-
547-
[WinFormsTheory]
548-
[InlineData(ContentAlignment.TopLeft, 16)]
549-
[InlineData(ContentAlignment.MiddleCenter, 57)]
550-
[InlineData(ContentAlignment.BottomRight, 97)]
551-
public void GetTextBaseline_ShouldRespectFontAndBounds(ContentAlignment alignment, int expectedBaseline)
552-
{
553-
using Button button = new()
554-
{
555-
Width = 200,
556-
Height = 100,
557-
Font = new Font("Times New Roman", 12)
558-
};
559-
560-
int baseline = DesignerUtils.GetTextBaseline(button, alignment);
561-
562-
baseline.Should().Be(expectedBaseline);
563-
}
564585
}

0 commit comments

Comments
 (0)