-
Notifications
You must be signed in to change notification settings - Fork 986
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
base: main
Are you sure you want to change the base?
Add unit tests for ListControlStringCollectionEditor #12516
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more.
|
[Fact] | ||
public void EditValue_WithNullContext_ReturnsBaseEditValue() | ||
{ | ||
var editor = new ListControlStringCollectionEditor(typeof(string)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please dispose ListBox
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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArgumentException exception = Assert.Throws<ArgumentException>(() => editor.EditValue(context.Object, provider, value)); | |
ArgumentException exception = ((Action)(() => editor.EditValue(context.Object, provider, value))).Should().Throw<ArgumentException>().Which; |
There was a problem hiding this 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. | |||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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" } }; |
There was a problem hiding this comment.
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
Related #10773
Proposed changes
Microsoft Reviewers: Open in CodeFlow