Modernize library: target net8.0/net10.0, modern C# idioms, xUnit v3#121
Modernize library: target net8.0/net10.0, modern C# idioms, xUnit v3#121
Conversation
- Drop netstandard2.0, target net8.0 and net10.0 LTS only - Enable nullable reference types and implicit usings - Replace static Random instance with Random.Shared (thread-safe) - Replace RandomNumberGenerator.Create() + disposal with RandomNumberGenerator.Fill() - Use ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual/ThrowIfLessThan/ThrowIfGreaterThan guard APIs everywhere instead of manual throws - Add where T : struct, Enum constraint on GetEnum<T>() to eliminate runtime type check - Use Math.Clamp instead of separate Math.Min/Math.Max in GetBool - Rewrite UpperCaseFirstCharacter with stackalloc Span<char> for zero-allocation - Convert to file-scoped namespace, collection expressions, expression-bodied members - Use string interpolation instead of concatenation - Add nullable annotations to GetVersion parameters and EnumerableExtensions - Upgrade build packages: SourceLink 10.0.103, AsyncFixer 2.1.0, MinVer 7.0.0 - Use dynamic copyright year expression matching project convention - Upgrade test project to xUnit v3 with Microsoft Testing Platform - Add Foundatio.Xunit.v3 13.0.0-beta3, xunit.v3.mtp-v2 3.2.2 - Add TestingPlatformDotnetTestSupport and new-test-runner: true for CI - Restore test parallelization disabling via AssemblyInfo.cs - Add codeql-analysis.yml, copilot-setup-steps.yml, global.json, AGENTS.md - Update README with comprehensive usage examples (all snippets compile clean) Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
This PR modernizes the Exceptionless.RandomData library by targeting .NET 8.0 and .NET 10.0 (dropping .NET Standard 2.0), adopting modern C# idioms, and upgrading to xUnit v3 with the Microsoft Testing Platform. The changes focus on using newer .NET APIs like Random.Shared, RandomNumberGenerator.Fill(), guard methods (ArgumentOutOfRangeException.ThrowIf*), and performance improvements with stackalloc Span<char>. The PR also enables nullable reference types, adds comprehensive README examples, and includes new documentation (AGENTS.md) and GitHub workflows.
Changes:
- Modernized to .NET 8.0/10.0 with nullable reference types, implicit usings, file-scoped namespaces, and collection expressions
- Replaced custom Random instance with
Random.Sharedand updated to use modern guard APIs andRandomNumberGenerator.Fill() - Upgraded test infrastructure to xUnit v3 with Microsoft Testing Platform
- Updated build packages (SourceLink, AsyncFixer, MinVer) and added GitHub Actions workflows for CodeQL and Copilot setup
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Exceptionless.RandomData/RandomData.cs | Core library modernized with Random.Shared, guard APIs, stackalloc Span, nullable annotations, and expression-bodied members |
| test/Exceptionless.RandomData.Tests/RandomDataTests.cs | Tests updated to file-scoped namespace, collection expressions, and fixed String casing |
| test/Exceptionless.RandomData.Tests/Properties/AssemblyInfo.cs | Updated xUnit attribute name for test parallelization settings |
| test/Exceptionless.RandomData.Tests/Exceptionless.RandomData.Tests.csproj | Upgraded to xUnit v3 packages and Microsoft Testing Platform with multi-targeting |
| build/common.props | Updated target frameworks, enabled nullable/implicit usings, dynamic copyright year, upgraded build packages |
| global.json | Added test runner configuration for Microsoft Testing Platform |
| README.md | Enhanced with comprehensive usage examples for all API methods |
| AGENTS.md | New agent guidelines document with coding standards and repository conventions |
| .github/workflows/codeql-analysis.yml | New CodeQL analysis workflow |
| .github/workflows/copilot-setup-steps.yml | New Copilot setup workflow |
| .github/workflows/build.yml | Added new-test-runner flag for Microsoft Testing Platform |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… when equal is allowed; add XML docs to all public API Co-authored-by: Cursor <cursoragent@cursor.com>
Refactors enum test to use a more descriptive name. Improves code readability by explicitly declaring the type of the result variable in the GetSentencesTest method and marking the _numbers array as readonly.
Summary
Random.Sharedinstead of a staticnew Random()instance — thread-safe by defaultRandomNumberGenerator.Create()+ disposal withRandomNumberGenerator.Fill()static methodArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual,ThrowIfLessThan,ThrowIfGreaterThanguard APIs everywhere instead of manualthrowstatementswhere T : struct, Enumconstraint onGetEnum<T>()to eliminate runtimetypeof(T).IsEnumcheckMath.Clampinstead of separateMath.Min/Math.MaxinGetBoolUpperCaseFirstCharacterwithstackalloc Span<char>for zero-allocation pathGetVersionparameters andEnumerableExtensions$([System.DateTime]::Now.ToString(yyyy))xunit.v3.mtp-v2 3.2.2,Foundatio.Xunit.v3 13.0.0-beta3)TestingPlatformDotnetTestSupportandnew-test-runner: truefor CIAssemblyInfo.cscodeql-analysis.yml,copilot-setup-steps.yml,global.json,AGENTS.mdPublic API changes
GetEnum<T>(): addedwhere T : struct, Enumconstraint — callers passing non-enum type arguments will now get a compile-time error instead of a runtimeArgumentExceptionGetVersion(string, string): parameters are now nullable (string?) — callers passingnullnow behave consistently with empty string (defaults applied)EnumerableExtensions.Random<T>(): return type is nowT?(wasT) — callers must handle possible nullTest plan
dotnet build Exceptionless.RandomData.slnx --configuration Release— 0 warnings, 0 errors (both net8.0 and net10.0)dotnet run --project test/Exceptionless.RandomData.Tests -f net8.0— 4 tests passdotnet run --project test/Exceptionless.RandomData.Tests -f net10.0— 4 tests pass