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

Add code coverage for DataGridViewComboBoxCell.ObjectCollection #12580

Conversation

Zheng-Li01
Copy link
Member

@Zheng-Li01 Zheng-Li01 commented Dec 4, 2024

related #10453

Proposed changes

Add unit tests for DataGridViewComboBoxCell.ObjectCollection.cs to test its properties & methods

Microsoft Reviewers: Open in CodeFlow

@Zheng-Li01 Zheng-Li01 requested a review from a team as a code owner December 4, 2024 02:49
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.92431%. Comparing base (f432c76) to head (0e283df).
Report is 22 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #12580         +/-   ##
===================================================
+ Coverage   75.83381%   75.92431%   +0.09050%     
===================================================
  Files           3164        3167          +3     
  Lines         636443      636883        +440     
  Branches       47002       47011          +9     
===================================================
+ Hits          482639      483549        +910     
+ Misses        150347      149869        -478     
- Partials        3457        3465          +8     
Flag Coverage Δ
Debug 75.92431% <100.00000%> (+0.09050%) ⬆️
integration 18.17244% <ø> (-0.00813%) ⬇️
production 49.62409% <ø> (+0.17023%) ⬆️
test 97.05239% <100.00000%> (-0.00002%) ⬇️
unit 46.84137% <ø> (+0.19807%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@Zheng-Li01 Zheng-Li01 added the waiting-review This item is waiting on review by one or more members of team label Dec 4, 2024
ricardobossan
ricardobossan previously approved these changes Dec 5, 2024
Copy link
Member

@ricardobossan ricardobossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All LGTM!

@ricardobossan
Copy link
Member

Hi @Tanya-Solyanik

While reviewing the test code for the DataGridViewComboBoxCell.ObjectCollection class, I encountered a System.InvalidCastException in the AddRange(ObjectCollection value) method. Specifically, the following line:

AddRangeInternal((ICollection<object>)value);

Here's the stack trace:

System.InvalidCastException: Unable to cast object of type 'ObjectCollection' to type 'System.Collections.Generic.ICollection`1[System.Object]'.
   at DataGridViewComboBoxCell.ObjectCollection.AddRange(ObjectCollection value)

This indicates a casting issue when passing ObjectCollection to AddRangeInternal. After testing, I found a working solution by modifying the AddRange and AddRangeInternal methods as follows:

public void AddRange(ObjectCollection value)
{
    _owner.CheckNoDataSource();
    AddRangeInternal(value);
    _owner.OnItemsCollectionChanged();
}

internal void AddRangeInternal(ObjectCollection items)
{
    ArgumentNullException.ThrowIfNull(items);

    foreach (object item in items)
    {
        if (item is null)
        {
            throw new InvalidOperationException(SR.InvalidNullItemInCollection);
        }
    }

    InnerArray.Add(items);
    if (_owner.Sorted)
    {
        InnerArray.Sort(Comparer);
    }
}

This implementation avoids the invalid cast and ensures the method functions as expected. Please let me know your thoughts.

Copy link
Member

@Tanya-Solyanik Tanya-Solyanik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some minor suggestions

@Tanya-Solyanik Tanya-Solyanik added waiting-author-feedback The team requires more information from the author and removed waiting-review This item is waiting on review by one or more members of team labels Dec 9, 2024
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label Dec 9, 2024
@Zheng-Li01 Zheng-Li01 added the waiting-review This item is waiting on review by one or more members of team label Dec 9, 2024
@Tanya-Solyanik
Copy link
Member

@ricardobossan - please create a new issue and submit a PR, great find!

@Tanya-Solyanik Tanya-Solyanik added ready-to-merge PRs that are ready to merge but worth notifying the internal team. and removed waiting-review This item is waiting on review by one or more members of team labels Dec 9, 2024
@lonitra lonitra merged commit 0773d89 into dotnet:main Dec 10, 2024
8 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0 Preview1 milestone Dec 10, 2024
@dotnet-policy-service dotnet-policy-service bot removed the ready-to-merge PRs that are ready to merge but worth notifying the internal team. label Dec 10, 2024
@Zheng-Li01 Zheng-Li01 deleted the Add_Code_Coverafe_For_DataGridViewComboBoxCell_ObjectCollect branch December 11, 2024 01:10
@github-actions github-actions bot locked and limited conversation to collaborators Jan 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants