Document unit-test / theory-data impact of .NET 11 double→decimal conversion
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 88/100
- Tipo di issue
- Documentazione
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- csharp
- Ambito
- documentation
Direzione di ricerca
Inizia da docs/core/compatibility/core-libraries/11/decimal-biginteger-floating-point-conversions.md e controlla la sezione Recommended action esistente; la pagina correlata sulle librerie .NET 11 è docs/core/whats-new/dotnet-11/libraries.md. Aggiungi una sottosezione concisa sull’impatto sui test unitari, con le indicazioni e gli esempi xUnit e NUnit descritti nell’issue. Il lavoro è completato quando la pagina spiega come i dati di test in virgola mobile vengono convertiti in decimal e mostra alternative che preservano decimal.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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).
- Lingua principale
- Nessun dato sulla lingua
- Stelle
- 4.8k
- Fork
- 6.1k
- Merge medio
- 21h 58m
- PR unite (30g)
- 197
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dotnet/docs
-
:watch: Not Triaged dotnet-fundamentals/svc
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
dotnet/docs#56465 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
dotnet-fundamentals/svc install/subsvc
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Upgrade from `net9.0` to LTS (or STS) image tagForse già presa @ShyneChikwapulo l’ha presa 9 giorni fa. Apertadotnet-target-version
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
dotnet/docs#56293 · 3 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Documentation for dotnet sln add doesn't mention the --include-references flagForse già presa @BartoszKlonowski l’ha presa 9 giorni fa. Apertadotnet-fundamentals/svc
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
dotnet/docs#56289 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Add more to the documentationForse già presa @adarsh6980 l’ha presa 28 giorni fa. Apertadotnet-fsharp/svc help wanted
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
dotnet/docs#56209 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
area: certificates help wanted priority: must type: docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
WNSolutions/digimenu-tn#35 ·
-
bug cli p3
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 3 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
documentation good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno