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 DesignerFrame #12712

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 Jan 6, 2025

Related #10773

Proposed changes

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

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

Attention: Patch coverage is 72.84483% with 63 lines in your changes missing coverage. Please review.

Project coverage is 76.03633%. Comparing base (e91e3bc) to head (c696dd8).
Report is 100 commits behind head on main.

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     
Flag Coverage Δ
Debug 76.03633% <72.84483%> (+0.28178%) ⬆️
integration 18.15475% <ø> (-0.02003%) ⬇️
production 49.79941% <ø> (+0.48186%) ⬆️
test 97.01477% <72.84483%> (-0.03030%) ⬇️
unit 47.00904% <ø> (+0.47733%) ⬆️

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)))
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 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)))
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 explicitly with a type. This happens again a few lines below.

designerFrame.Controls.Cast<Control>().Should().NotContain(control);
}

[Fact]
Copy link
Member

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();
}

@ricardobossan ricardobossan added the 📭 waiting-author-feedback The team requires more information from the author label Jan 6, 2025
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.

2 participants