Document unit-test / theory-data impact of .NET 11 double→decimal conversion
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 88/100
- Loại issue
- Tài liệu
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- csharp
- Lĩnh vực
- documentation
Hướng nghiên cứu
Bắt đầu với docs/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions.md và kiểm tra mục Recommended action hiện có; trang thư viện .NET 11 liên quan là docs/core/whats-new/dotnet-11/libraries.md. Thêm một tiểu mục ngắn gọn về ảnh hưởng đến unit test, gồm hướng dẫn và ví dụ về xUnit và NUnit được mô tả trong issue. Hoàn tất khi trang giải thích cách dữ liệu kiểm thử dấu phẩy động được chuyển đổi sang decimal và trình bày các phương án thay thế giúp giữ nguyên decimal.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Type of issue
- Content issue (typos, broken links, missing/outdated content)
- Product issue (bug in docs tooling/platform)
Location
- https://learn.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions
- Source:
docs/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions.md - Also referenced from
docs/core/whats-new/dotnet-11/libraries.md
Description
The breaking-change page correctly documents that float/double → decimal is now correctly rounded (exact binary value), and recommends decimal literals (1.23m) instead of casting double literals.
What is easy to miss in migration: unit-test theory / inline data often injects floating literals as double, then binds or casts them to decimal parameters. That path was “quietly OK” on .NET 10 (15-digit-style conversion) and fails equality / validation on .NET 11 even when production code already uses decimal end-to-end.
xUnit
// Compiles: 0.1 is a double attribute argument
[Theory]
[InlineData(0.1)]
public void Rate(decimal rate)
{
// Under .NET 10: rate often equals 0.1m
// Under .NET 11: rate == 0.1000000000000000055511151231m → assert fails
Assert.Equal(0.1m, rate);
}
// Does NOT compile: decimal is not a valid C# attribute argument type
// [InlineData(0.1m)]
Workaround that keeps real decimals: MemberData / ClassData / TheoryData<decimal> with 0.1m values (not attribute args).
NUnit
// Non-m literals become double, then convert to decimal param
[TestCase(0.1)]
public void Rate(decimal rate) { ... }
// Prefer:
[TestCase("0.1")]
public void Rate(decimal rate) { ... } // parsed as decimal
Why document this on the BC page
- The failure mode is often tests only, so teams can think production is broken when CI is.
- It is not obvious that
InlineData(0.1)+decimalis a double conversion (C# forbids0.1min attributes). - Same BC already says “don’t assume a binary FP literal and a decimal literal with the same source text represent the same value” — a short “Impact on unit tests” subsection with xUnit/NUnit examples would catch a large class of migration failures.
Suggested addition (sketch)
Under Recommended action, add something like:
Unit tests (xUnit / NUnit / similar)
Theory/case attributes cannot take decimal constants in C#. Non-integer numeric attribute args are double/float. Binding those to decimal parameters uses the same conversion as (decimal)double and therefore changes under this BC. Prefer:
- xUnit:
TheoryData/MemberDatawithdecimalvalues (0.1m), or string data +decimal.Parse - NUnit:
[TestCase("0.1")]intodecimal, or explicit0.1monly outside attributes
Page URL
Related
- Runtime BC is intentional; this is a docs request only (no ask to revert conversion).
- xUnit docs request: https://github.com/xunit/xunit/issues/3658
- xUnit attribute limitation is language-level (
decimalnot allowed in attribute arguments).
- Ngôn ngữ chính
- Không có dữ liệu ngôn ngữ
- Star
- 4.8k
- Fork
- 6.1k
- Merge trung bình
- 21 giờ 58 phút
- Pull request đã merge (30 ngày)
- 197
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/docs
-
:watch: Not Triaged dotnet-fundamentals/svc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
dotnet/docs#56465 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
How to upgrade to `10.0.4xx`?Đang mởdotnet-fundamentals/svc install/subsvc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Upgrade from `net9.0` to LTS (or STS) image tagCó thể đã có người làm @ShyneChikwapulo đã nhận 8 ngày trước. Đang mởdotnet-target-version
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
dotnet/docs#56293 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Documentation for dotnet sln add doesn't mention the --include-references flagCó thể đã có người làm @BartoszKlonowski đã nhận 8 ngày trước. Đang mởdotnet-fundamentals/svc
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
dotnet/docs#56289 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add more to the documentationCó thể đã có người làm @adarsh6980 đã nhận 27 ngày trước. Đang mởdotnet-fsharp/svc help wanted
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
dotnet/docs#56209 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
zts212653/clowder-ai#1678 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Docs] CONTRIBUTING still says FreeType 2.14.3 and TabLabel.h says ImGui 1.92.9b after the bumpsCó thể đã có người làm @mgradwohl đã nhận hôm nay. Đang mởagent:WSL documentation LOW
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
cloudflare/skills#247 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
social-harness/moltzap#1412 ·
Maintainer thường phản hồi trong vòng 1 ngày