-
Notifications
You must be signed in to change notification settings - Fork 1k
Add unit test for ButtonBaseAdapter.ColorOptions.cs file #13458
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
base: main
Are you sure you want to change the base?
Add unit test for ButtonBaseAdapter.ColorOptions.cs file #13458
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13458 +/- ##
====================================================
+ Coverage 62.21083% 76.64619% +14.43536%
====================================================
Files 3213 3231 +18
Lines 638302 639202 +900
Branches 47201 47294 +93
====================================================
+ Hits 397093 489924 +92831
+ Misses 234153 145708 -88445
+ Partials 7056 3570 -3486
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
[WinFormsFact] | ||
public void Button_Calculate_BackColorIsSystemControl() | ||
{ | ||
using Bitmap bmp = new Bitmap(1, 1); |
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.
The Bitmap can be removed, the same problem exists elsewhere
using Bitmap bmp = new(1, 1);
{ | ||
using Bitmap bmp = new Bitmap(1, 1); | ||
using Graphics g = Graphics.FromImage(bmp); | ||
ColorOptions options = new ColorOptions(g, Color.Black, SystemColors.Control) |
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 use fully name
using Graphics graphics = Graphics.FromImage(image);
data.ButtonShadowDark.Should().Be(SystemColors.ControlDarkDark); | ||
data.Highlight.Should().Be(SystemColors.ControlLightLight); | ||
data.WindowText.Should().Be(data.WindowFrame); | ||
data.WindowDisabled.Should().Be(data.ButtonShadow); |
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 HighContrast is True, this assertion will fail, so it is necessary to add a conditional judgment here. The other tests also have this problem.
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.
Pull Request Overview
This PR adds a new unit test file, ButtonBaseAdapterTests.cs, to improve test coverage for the ButtonStandardAdapter.cs file.
- Added multiple tests to validate ColorOptions behavior under different modes (default, non-SystemControl colors with high contrast on/off, and disabled states).
- Consolidates assertions for computed color values based on brightness and high contrast conditions.
data.ButtonFace.Should().Be(backColor); | ||
data.ButtonShadow.Should().Be(ControlPaint.Dark(backColor)); | ||
data.ButtonShadowDark.Should().Be(ControlPaint.LightLight(backColor)); | ||
data.Highlight.Should().Be(ControlPaint.LightLight(backColor)); |
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.
The test 'Button_Calculate_BackColorNotSystemControl_HighContrastTrue' asserts data.Highlight twice with different expectations (line 86 asserting ControlPaint.LightLight(backColor) and line 89 asserting data.LowHighlight). Consider consolidating these assertions or clarifying the expected behavior to eliminate potential ambiguity.
data.Highlight.Should().Be(ControlPaint.LightLight(backColor)); | |
// data.Highlight is expected to match data.LowHighlight in high contrast mode. |
Copilot uses AI. Check for mistakes.
|
||
data.ButtonFace.Should().Be(backColor); | ||
data.ButtonShadow.Should().Be(ControlPaint.Dark(backColor)); | ||
data.ButtonShadowDark.Should().Be(ControlPaint.LightLight(backColor)); |
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.
[nitpick] In high contrast mode, ButtonShadowDark is expected to be ControlPaint.LightLight(backColor) instead of the usual DarkDark. Adding a comment to explain this deviation would improve clarity for future maintainers.
Copilot uses AI. Check for mistakes.
Related #13442
Proposed changes
Microsoft Reviewers: Open in CodeFlow