-
Notifications
You must be signed in to change notification settings - Fork 1k
Add code coverage for DataGridViewDesigner #13014
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
Merged
Tanya-Solyanik
merged 6 commits into
dotnet:main
from
Zheng-Li01:Add_code_covrage_for_DataGridViewDesignerTests
Mar 6, 2025
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c74b6c0
Add code coverage for DataGridViewDesigner
Zheng-Li01 784d430
Handle FeedBacks
Zheng-Li01 5bb9cf9
Handle FeedBacks
Zheng-Li01 fd078a8
Handle FeedBacks
Zheng-Li01 2a9fa4d
Handle FeedBacks
Zheng-Li01 b278975
Remove the #nullable enable in the test file
Zheng-Li01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
...ows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/DataGridViewDesignerTests.cs
This file contains hidden or 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,152 @@ | ||
// 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 System.ComponentModel.Design; | ||
using Moq; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
|
||
public class DataGridViewDesignerTests : IDisposable | ||
{ | ||
private readonly DataGridViewDesigner _designer; | ||
private readonly DataGridView _dataGridView; | ||
|
||
public DataGridViewDesignerTests() | ||
{ | ||
_designer = new(); | ||
_dataGridView = new(); | ||
_designer.Initialize(_dataGridView); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_designer.Dispose(); | ||
_dataGridView.Dispose(); | ||
} | ||
|
||
[Fact] | ||
public void Control_ReturnsDataGridView() | ||
{ | ||
_designer.Control.Should().NotBeNull(); | ||
_designer.Control.Should().BeOfType<DataGridView>(); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_SetsAutoResizeHandlesToTrue() => | ||
_designer.AutoResizeHandles.Should().BeTrue(); | ||
|
||
[Fact] | ||
public void AssociatedComponents_ReturnsDataGridViewColumns() => | ||
_designer.AssociatedComponents.Should().BeSameAs(_dataGridView.Columns); | ||
|
||
[Fact] | ||
public void AutoSizeColumnsMode_Get_ReturnsExpected() | ||
{ | ||
_dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; | ||
_designer.AutoSizeColumnsMode.Should().Be(DataGridViewAutoSizeColumnsMode.Fill); | ||
} | ||
|
||
[Fact] | ||
public void AutoSizeColumnsMode_Set_CallsComponentChangeService() | ||
{ | ||
Mock<IComponentChangeService> mockChangeService = new(); | ||
Mock<ISite> site = new(); | ||
site.Setup(s => s.GetService(typeof(IComponentChangeService))).Returns(mockChangeService.Object); | ||
_dataGridView.Site = site.Object; | ||
|
||
_designer.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; | ||
|
||
mockChangeService.Verify(s => s.OnComponentChanging(It.IsAny<object>(), It.IsAny<PropertyDescriptor>()), Times.Exactly(_dataGridView.Columns.Count)); | ||
Zheng-Li01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mockChangeService.Verify(s => s.OnComponentChanged(It.IsAny<object>(), It.IsAny<PropertyDescriptor>(), It.IsAny<object>(), It.IsAny<object>()), Times.Exactly(_dataGridView.Columns.Count)); | ||
_dataGridView.AutoSizeColumnsMode.Should().Be(DataGridViewAutoSizeColumnsMode.Fill); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_Get_ReturnsExpected() | ||
{ | ||
object dataSource = new(); | ||
_dataGridView.DataSource = dataSource; | ||
|
||
_designer.DataSource.Should().BeSameAs(dataSource); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_Set_SetsExpected() | ||
{ | ||
object dataSource = new(); | ||
_designer.DataSource = dataSource; | ||
|
||
_dataGridView.DataSource.Should().BeSameAs(dataSource); | ||
_dataGridView.AutoGenerateColumns.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void DataSource_Set_Null_SetsExpected() | ||
{ | ||
_dataGridView.AutoGenerateColumns = false; | ||
_designer.DataSource = null; | ||
|
||
_dataGridView.DataSource.Should().BeNull(); | ||
_dataGridView.AutoGenerateColumns.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void Initialize_SetsAutoGenerateColumnsCorrectly() | ||
{ | ||
using DataGridViewDesigner designer = new(); | ||
designer.Initialize(_dataGridView); | ||
Zheng-Li01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_dataGridView.AutoGenerateColumns.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void InitializeNewComponent_SetsColumnHeadersHeightSizeModeToAutoSize() | ||
{ | ||
using DataGridViewDesigner designer = new(); | ||
designer.Initialize(_dataGridView); | ||
designer.InitializeNewComponent(null); | ||
Zheng-Li01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_dataGridView.ColumnHeadersHeightSizeMode.Should().Be(DataGridViewColumnHeadersHeightSizeMode.AutoSize); | ||
} | ||
|
||
[Fact] | ||
public void Verbs_ReturnsExpected() | ||
{ | ||
DesignerVerbCollection verbs = _designer.Verbs; | ||
|
||
verbs.Should().NotBeNull(); | ||
verbs.Count.Should().Be(2); | ||
verbs[0]!.Text.Should().Be(SR.DataGridViewEditColumnsVerb); | ||
verbs[1]!.Text.Should().Be(SR.DataGridViewAddColumnVerb); | ||
} | ||
|
||
[Fact] | ||
public void ActionLists_CachesActionLists() | ||
{ | ||
DesignerActionListCollection actionLists1 = _designer.ActionLists; | ||
DesignerActionListCollection actionLists2 = _designer.ActionLists; | ||
|
||
actionLists1.Should().BeSameAs(actionLists2); | ||
} | ||
|
||
[Fact] | ||
public void PreFilterProperties_ShadowsPropertiesCorrectly() | ||
{ | ||
using DataGridViewDesigner designer = new(); | ||
designer.Initialize(_dataGridView); | ||
Zheng-Li01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Dictionary<string, PropertyDescriptor> properties = new() | ||
{ | ||
{ "AutoSizeColumnsMode", TypeDescriptor.GetProperties(typeof(DataGridView))["AutoSizeColumnsMode"]!}, | ||
{ "DataSource", TypeDescriptor.GetProperties(typeof(DataGridView))["DataSource"]!} | ||
}; | ||
|
||
designer.TestAccessor().Dynamic.PreFilterProperties(properties); | ||
|
||
properties["AutoSizeColumnsMode"].ComponentType.Should().Be(typeof(DataGridViewDesigner)); | ||
properties["DataSource"].ComponentType.Should().Be(typeof(DataGridViewDesigner)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.