Skip to content

Commit

Permalink
Add code coverage for DataGridViewCellStyleConverter (#12462)
Browse files Browse the repository at this point in the history
* Add code coverage for  DataGridViewCellStyleConverter

* Handle FeedBacks

* Handle FeedBacks
  • Loading branch information
Zheng-Li01 authored Nov 22, 2024
1 parent 680fcad commit df46341
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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 DataGridViewCellStyleConverterTests
{
private readonly DataGridViewCellStyleConverter _converter;
private readonly DataGridViewCellStyle _style;

public DataGridViewCellStyleConverterTests()
{
_converter = new();
_style = new();
}

[WinFormsFact]
public void CanConvertTo_InstanceDescriptor_ReturnsTrue()
{
_converter.CanConvertTo(null, typeof(InstanceDescriptor)).Should().BeTrue();
}

[WinFormsFact]
public void CanConvertTo_OtherType_ReturnsFalse()
{
_converter.CanConvertTo(null, typeof(int)).Should().BeFalse();
}

[WinFormsFact]
public void ConvertTo_InstanceDescriptor_ReturnsInstanceDescriptor()
{
object? convertTo = _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(InstanceDescriptor));
convertTo.Should().NotBeNull();
convertTo.Should().BeOfType<InstanceDescriptor>();
}

[WinFormsFact]
public void ConvertTo_UnsupportedType_ThrowsNotSupportedException()
{
Action action = () => _converter.ConvertTo(null, CultureInfo.InvariantCulture, _style, typeof(int));
action.Should().Throw<NotSupportedException>();
}
}

0 comments on commit df46341

Please sign in to comment.