-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add code coverage for DataGridViewCellConverter (#12622)
related #10453 Add unit tests for DataGridViewCellConverter.cs to test its methods
- Loading branch information
1 parent
ac6adf7
commit 7d88751
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...stem.Windows.Forms/tests/UnitTests/System/Windows/Forms/DataGridViewCellConverterTests.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,52 @@ | ||
// 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.Design.Serialization; | ||
using System.Globalization; | ||
|
||
namespace System.Windows.Forms.Tests; | ||
|
||
public class DataGridViewCellConverterTests | ||
{ | ||
private readonly DataGridViewCellConverter _converter = new(); | ||
|
||
[WinFormsTheory] | ||
[InlineData(typeof(InstanceDescriptor), true)] | ||
[InlineData(typeof(string), true)] | ||
public void CanConvertTo_ReturnsExpected(Type destinationType, bool expected) => | ||
_converter.CanConvertTo(context: null, destinationType).Should().Be(expected); | ||
|
||
[WinFormsFact] | ||
public void ConvertTo_InstanceDescriptorWithDataGridViewCell_ReturnsInstanceDescriptor() | ||
{ | ||
using DataGridViewTextBoxCell cell = new(); | ||
Type destinationType = typeof(InstanceDescriptor); | ||
|
||
_converter.ConvertTo(context: null, CultureInfo.InvariantCulture, cell, destinationType).Should().NotBeNull(); | ||
_converter.ConvertTo(context: null, CultureInfo.InvariantCulture, cell, destinationType).Should().BeOfType<InstanceDescriptor>(); | ||
} | ||
|
||
[WinFormsFact] | ||
public void ConvertTo_InstanceDescriptorWithNonDataGridViewCell_ThrowsNotSupportedException() | ||
{ | ||
object value = new(); | ||
Type destinationType = typeof(InstanceDescriptor); | ||
|
||
Action action = () => _converter.ConvertTo(context: null, CultureInfo.InvariantCulture, value, destinationType); | ||
action.Should().Throw<NotSupportedException>() | ||
.WithMessage("'DataGridViewCellConverter' is unable to convert 'System.Object' to 'System.ComponentModel.Design.Serialization.InstanceDescriptor'."); | ||
} | ||
|
||
[WinFormsFact] | ||
public void ConvertTo_OtherType_ReturnsStringRepresentation() | ||
{ | ||
using DataGridViewTextBoxCell cell = new(); | ||
Type destinationType = typeof(string); | ||
|
||
_converter.ConvertTo(context: null, CultureInfo.InvariantCulture, cell, destinationType).Should().NotBeNull(); | ||
_converter.ConvertTo(context: null, CultureInfo.InvariantCulture, cell, destinationType).Should().BeOfType<string>(); | ||
_converter.ConvertTo(context: null, CultureInfo.InvariantCulture, cell, destinationType).Should().Be(cell.ToString()); | ||
} | ||
} |