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 unit tests for ListControlStringCollectionEditor #12516

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Nora-Zhou01
Copy link
Member

@Nora-Zhou01 Nora-Zhou01 commented Nov 20, 2024

Related #10773

Proposed changes

  • Add unit test ListControlStringCollectionEditorTests.cs for public properties and method of the ListControlStringCollectionEditor
  • Enable nullability in ListControlStringCollectionEditorTests.cs
Microsoft Reviewers: Open in CodeFlow

Copy link

codecov bot commented Nov 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.74520%. Comparing base (e4085eb) to head (7a1c240).
Report is 356 commits behind head on main.

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #12516         +/-   ##
===================================================
+ Coverage   75.01536%   75.74520%   +0.72983%     
===================================================
  Files           3047        3158        +111     
  Lines         631584      636134       +4550     
  Branches       46764       47003        +239     
===================================================
+ Hits          473785      481841       +8056     
+ Misses        154434      150829       -3605     
- Partials        3365        3464         +99     
Flag Coverage Δ
Debug 75.74520% <100.00000%> (+0.72983%) ⬆️
integration 18.17498% <ø> (+0.24058%) ⬆️
production 49.31432% <ø> (+1.18968%) ⬆️
test 97.04561% <100.00000%> (+0.02913%) ⬆️
unit 46.50538% <ø> (+1.37924%) ⬆️

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

---- 🚨 Try these New Features:

@Nora-Zhou01 Nora-Zhou01 added the waiting-review This item is waiting on review by one or more members of team label Nov 22, 2024
[Fact]
public void EditValue_WithNullContext_ReturnsBaseEditValue()
{
var editor = new ListControlStringCollectionEditor(typeof(string));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var editor = new ListControlStringCollectionEditor(typeof(string));
ListControlStringCollectionEditor editor = new(typeof(string));

Same in below tests as well

public void EditValue_WithListControlAndNullDataSource_ReturnsBaseEditValue()
{
var editor = new ListControlStringCollectionEditor(typeof(string));
ListBox listControl = new();
Copy link
Member

Choose a reason for hiding this comment

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

Please dispose ListBox

Suggested change
ListBox listControl = new();
using ListBox listControl = new();

var provider = new Mock<IServiceProvider>().Object;
object? value = new();

ArgumentException exception = Assert.Throws<ArgumentException>(() => editor.EditValue(context.Object, provider, value));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
ArgumentException exception = Assert.Throws<ArgumentException>(() => editor.EditValue(context.Object, provider, value));
ArgumentException exception = ((Action)(() => editor.EditValue(context.Object, provider, value))).Should().Throw<ArgumentException>().Which;

@lonitra lonitra 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 Nov 22, 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.

Other than small comments, LGTM. Just make sure to rebase with updated main remote upstream branch, to get rid of the errors when trying to build.

@@ -0,0 +1,70 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

Copy link
Member

@ricardobossan ricardobossan Nov 22, 2024

Choose a reason for hiding this comment

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

When trying to run the tests myself i could not build the code with errors:

The "Csc" task could not be initialized with its input parameters. 
The "InterceptorsNamespaces" parameter is not supported by the "Csc" task loaded from assembly: Microsoft.Build.Tasks.CodeAnalysis, Version=4.12.10.37901, Culture=neutral, PublicKeyToken=31bf3856ad364e35 from the path: C:\.tools\.nuget\packages\microsoft.net.sdk.compilers.toolset\9.0.100-preview.7.24407.12\Microsoft.Build.Tasks.CodeAnalysis.dll. Verify that the parameter exists on the task, the <UsingTask> points to the correct assembly, and it is a settable public instance property.

I think that is due to the commit from which you checked out from to make the tests. I solved this by rebasing with the main branch on the runtime repo remote. You can do this:

gh pr checkout 12516 # If you are out of the branch now. I use github cli for this
git fetch --all
git pull --rebase $UPSTREAM_REMOTE main # $UPSTREAM_REMOTE should be the name of the remote where you're trying to send your PR to. As I work on my fork, mine is called `upstream`
git push --force

public void EditValue_WithNullContext_ReturnsBaseEditValue()
{
var editor = new ListControlStringCollectionEditor(typeof(string));
var provider = new Mock<IServiceProvider>().Object;
Copy link
Member

Choose a reason for hiding this comment

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

Please declare variables with explicit types. This happens in other areas of the code as well.

{
var editor = new ListControlStringCollectionEditor(typeof(string));

ListBox listControl = new() { DataSource = new List<string> { "item1", "item2", "item3" } };
Copy link
Member

Choose a reason for hiding this comment

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

Please dispose of this control with using

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📭 waiting-author-feedback The team requires more information from the author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants