-
Notifications
You must be signed in to change notification settings - Fork 997
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 DesignerFrame #12712
base: main
Are you sure you want to change the base?
Add unit tests for DesignerFrame #12712
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12712 +/- ##
===================================================
+ Coverage 75.75455% 76.03633% +0.28178%
===================================================
Files 3159 3165 +6
Lines 635942 639539 +3597
Branches 46987 47257 +270
===================================================
+ Hits 481755 486282 +4527
+ Misses 150726 149697 -1029
- Partials 3461 3560 +99
Flags with carried forward coverage won't be shown. Click here to find out more. |
MethodInfo? invalidateOverlaysMethod = overlayControlType?.GetMethod("InvalidateOverlays", [typeof(Region)]); | ||
invalidateOverlaysMethod.Should().NotBeNull(); | ||
|
||
using (var region = new Region(new Rectangle(25, 25, 50, 50))) |
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 explicitly with a type. This happens again a few lines below.
MethodInfo? invalidateOverlaysMethod = overlayControlType?.GetMethod("InvalidateOverlays", [typeof(Region)]); | ||
invalidateOverlaysMethod.Should().NotBeNull(); | ||
|
||
using (var region = new Region(new Rectangle(25, 25, 50, 50))) |
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 explicitly with a type. This happens again a few lines below.
designerFrame.Controls.Cast<Control>().Should().NotContain(control); | ||
} | ||
|
||
[Fact] |
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.
This PR provides thorough testing for the OverlayControl
class. However, since OverlayControl
is a private
class fully encapsulated within the DesignerFrame
class (the actual target of this PR), it cannot be accessed directly outside of DesignerFrame
.
Testing OverlayControl
here relies heavily on reflection
, which we typically avoid in unit tests.
An alternative approach could involve recreating OverlayControl
within the test class, but given its size and complexity, this may introduce significant overhead for testing an inner private
class.
At this stage, it might be more practical to focus on testing DesignerFrame
's more exposed properties and methods, deferring OverlayControl
-specific tests for a future refactor.
What do you think @lonitra @Tanya-Solyanik ?
Example of how tests could go:
[Fact]
public void Designer_ProcessDialogKey()
{
Mock<ISite> mockSite = new(); // Consider making this a field if reused
using DesignerFrame designerFrame = new(mockSite.Object); // Same for this if used across methods
bool result = designerFrame.TestAccessor().Dynamic.ProcessDialogKey(Keys.Enter);
result.Should().BeFalse();
}
Related #10773
Proposed changes
Microsoft Reviewers: Open in CodeFlow