Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds code coverage to FormatControl #12168

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

namespace System.Windows.Forms.Design.Tests;
public class FormatControlTests : IDisposable
{
private readonly FormatControl _formatControl = new();
public void Dispose() => _formatControl.Dispose();

[Fact]
public void DefaultProperties_ShouldReturnExpected()
{
_formatControl.Should().NotBeNull();
_formatControl.Should().BeOfType<FormatControl>();
_formatControl.Should().BeAssignableTo<Control>();
_formatControl.Dirty.Should().BeFalse();
_formatControl.FormatType.Should().BeEmpty();
_formatControl.NullValue.Should().BeNull();
}

[Fact]
public void SetsNullValueTextBoxEnabled_ShouldNotThrow()
{
_formatControl.Invoking(f => f.NullValueTextBoxEnabled = false).Should().NotThrow();
}

public static IEnumerable<object[]> TestData()
{
yield return new object[] { null!, SR.BindingFormattingDialogFormatTypeNoFormatting };
yield return new object[] { "N1", SR.BindingFormattingDialogFormatTypeNumeric };
yield return new object[] { "d", SR.BindingFormattingDialogFormatTypeDateTime };
yield return new object[] { "E1", SR.BindingFormattingDialogFormatTypeScientific };
yield return new object[] { "CustomString", SR.BindingFormattingDialogFormatTypeCustom };
}

[Theory]
[MemberData(nameof(TestData))]
public void FormatTypeStringFromFormatString_ShouldReturnCorrectFormatType(string formatString, string formatTypeString) => FormatControl.FormatTypeStringFromFormatString(formatString).Should().Be(formatTypeString);

[Fact]
public void ResetFormattingInfo_ShouldNotThrow() => _formatControl.Invoking(f => f.ResetFormattingInfo()).Should().NotThrow();
}