gdi-rendering-tests

Write xUnit tests for System.Drawing Graphics, Bitmap, GraphicsPath, and Font rendering APIs.

1.2k|337|Updated Oct 13, 2022
One-click install
npx skills add https://github.com/dotnet/dotnet --skill gdi-rendering-tests
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gdi-rendering-tests
Source: https://github.com/dotnet/dotnet/tree/main/src/winforms/.github/skills/gdi-rendering-tests
Command: npx skills add https://github.com/dotnet/dotnet --skill gdi-rendering-tests

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Writing tests for GDI+ rendering APIs requires verifying that drawing calls actually produce pixels, covering both integer and float overloads, and matching .NET version guards — this Skill codifies those conventions so tests are consistent and complete.

Core Features & Use Cases

  • Bitmap-Based Verification: Uses VerifyBitmapNotEmpty and VerifyBitmapEmpty helpers that lock bitmap bits and scan for non-zero pixels to confirm rendering occurred.
  • Overload and Version Coverage: Enforces separate integer/float overload tests, Draw/Fill pair coverage, and #if NET11_0_OR_GREATER guards matching the API under test.
  • GraphicsPath Point Validation: Verifies PathPoints arrays with FluentAssertions approximate comparison at 0.000001f precision.
  • Use Case: When adding a new DrawRoundedRectangle API to System.Drawing, generate the full test matrix — integer and float overloads, Draw and Fill variants, and GraphicsPath point assertions — following the established naming and disposal conventions.

Quick Start

Write unit tests for the new Graphics.DrawRoundedRectangle API following the GDI+ rendering test conventions.

Frequently Asked Questions about gdi-rendering-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test that a Graphics drawing method actually renders pixels?

Create a small Bitmap, get a Graphics from it, call the drawing API, then call VerifyBitmapNotEmpty. This helper locks the bitmap bits and scans the pixel buffer for any non-zero bytes, confirming something was rendered.

How do I test integer and float overloads of System.Drawing APIs?

Write separate tests for each overload, named with an Integer or Float suffix such as Graphics_DrawRoundedRectangle_Integer. Even when the integer overload delegates to the float version, test both to verify the Rectangle to RectangleF conversion.

How do I verify GraphicsPath points in unit tests?

Use FluentAssertions BeApproximatelyEquivalentTo on path.PathPoints with a precision of 0.000001f. Capture the actual PathPoints output from a test run first, then use those values as the expected data.

Should GDI+ rendering tests use WinFormsFact or Fact attributes?

Graphics tests do not require STA threads, so use standard xUnit [Fact] and [Theory] attributes rather than [WinFormsFact] or [WinFormsTheory]. The test project combines xUnit with FluentAssertions.

How do version guards work for new .NET drawing API tests?

Wrap tests in the same preprocessor directive as the API itself, currently #if NET11_0_OR_GREATER. This ensures tests compile and run only on target frameworks where the API exists.

What are the limitations of bitmap-based rendering verification?

VerifyBitmapNotEmpty only confirms that some pixels were drawn, not that the output matches an expected image. For font metrics, verify values fall within expected ranges since rendering varies across environments.