forked from dotnet/winforms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds code coverage for FormatStringDialog
Related dotnet#10773 ## Proposed changes - Adds code coverage for `FormatStringDialog`. ## Customer Impact - None ## Regression? - No ## Risk - Minimal ## Test methodology - Unit tests ## Test environment(s) - 9.0.100-rc.1.24452.12
- Loading branch information
Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)
committed
Sep 24, 2024
1 parent
34dc978
commit c85431f
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
...ndows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/FormatStringDialogTests.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,107 @@ | ||
// 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; | ||
using Moq; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
|
||
public class FormatStringDialogTests : IDisposable | ||
{ | ||
private readonly FormatStringDialog _formatStringDialog; | ||
|
||
private readonly Mock<ITypeDescriptorContext> _context = new(MockBehavior.Strict); | ||
|
||
public FormatStringDialogTests() => _formatStringDialog = new(_context.Object); | ||
|
||
public void Dispose() => _formatStringDialog.Dispose(); | ||
|
||
[Fact] | ||
public void Ctor_WithContext_DoesNotThrow() | ||
{ | ||
Action action = () => new FormatStringDialog(_context.Object); | ||
|
||
action.Should().NotThrow(); | ||
} | ||
|
||
[Fact] | ||
public void FormatStringDialog_HasProperRTLConfiguration() | ||
{ | ||
if (SR.RTL == "RTL_False") | ||
{ | ||
_formatStringDialog!.RightToLeft.Should().Be(RightToLeft.No); | ||
_formatStringDialog!.RightToLeftLayout.Should().Be(false); | ||
} | ||
else | ||
{ | ||
_formatStringDialog!.RightToLeft.Should().Be(RightToLeft.Yes); | ||
_formatStringDialog!.RightToLeftLayout.Should().Be(true); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void SetsDataGridViewCellStyle_DoesNotThrow() | ||
{ | ||
Action action = () => _formatStringDialog.DataGridViewCellStyle = new(); | ||
|
||
action.Should().NotThrow(); | ||
} | ||
|
||
[Fact] | ||
public void Dirty_ReturnsDefault() => _formatStringDialog.Dirty.Should().Be(false); | ||
|
||
[Fact] | ||
public void SetsListControl_DoesNotThrow() | ||
{ | ||
Action action = () => | ||
{ | ||
using ListBox listControl = new(); | ||
_formatStringDialog.ListControl = listControl; | ||
}; | ||
action.Should().NotThrow(); | ||
} | ||
|
||
[Fact] | ||
public void End_DoesNotThrow() | ||
{ | ||
Action action = FormatStringDialog.End; | ||
|
||
action.Should().NotThrow(); | ||
} | ||
|
||
[Fact] | ||
public void FormatControlFinishedLoading_AdjustsButtonPositionsCorrectly() | ||
{ | ||
using dynamic? okButtonField = _formatStringDialog.TestAccessor().Dynamic._okButton; | ||
using dynamic? cancelButtonField = _formatStringDialog.TestAccessor().Dynamic._cancelButton; | ||
using dynamic? formatControlField = _formatStringDialog.TestAccessor().Dynamic._formatControl1; | ||
|
||
int okButtonLeftOriginalState = okButtonField.Left; | ||
int cancelButtonLeftOriginalState = cancelButtonField.Left; | ||
|
||
int GetRightSideOffset(Control ctl) | ||
{ | ||
int result = ctl.Width; | ||
Control? control = ctl; | ||
while (control is not null) | ||
{ | ||
result += control.Left; | ||
control = control.Parent; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
int formatControlRightSideOffset = GetRightSideOffset(formatControlField); | ||
int cancelButtonRightSideOffset = GetRightSideOffset(cancelButtonField); | ||
|
||
_formatStringDialog.FormatControlFinishedLoading(); | ||
|
||
((object)okButtonField.Top).Should().Be(formatControlField.Bottom + 5); | ||
((object)cancelButtonField.Top).Should().Be(formatControlField.Bottom + 5); | ||
((object)okButtonField.Left).Should().Be(okButtonLeftOriginalState + formatControlRightSideOffset - cancelButtonRightSideOffset); | ||
((object)cancelButtonField.Left).Should().Be(cancelButtonLeftOriginalState + formatControlRightSideOffset - cancelButtonRightSideOffset); | ||
} | ||
} |