Harden the public API, fix Invoke constant arguments, add Use.From - #9
Merged
Merged
Conversation
Argument validation over the configuration and generation API (ArgumentNullException, ArgumentOutOfRangeException for negative counts, ArgumentException for unknown members, non-source and non-convention types). Every bare InvalidOperationException carries the type and member it failed at. Invoke(c => c.Method(...)) in the configuration: constants arrive as their value (they arrived as the ConstantExpression before, untested), captured variables are evaluated, null is allowed, Use.From(lambda) and Use.From(ctx => ...) compute an argument per object, other method calls are rejected with a message naming the options. Context lambdas (From, Source, Use.From) get a non-nullable IGenerationContext; a FuncSource built from one throws a clear message outside of a session. The dead Ctor(...) stub is gone. GenerateDocumentationFile on with CS1591 suppressed, cref references fixed. .gitattributes with text=auto. Tests: the shared stable sequence helper skips the random seed comparison for bools and enums (four draws from ten enum values reproduced the same multiset on CI), ShouldNotBeEmpty guards in front of ShouldAllBe on derived collections, 19 new tests. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
IntegerSource, LongSource, RandomNumberSource and their nullable variants treated max as exclusive, so new IntegerSource(1, 3) never produced 3 while NumberSource<T> and the date sources are inclusive on both ends. Int128Source was worse: it built a value from two non-negative draws and clamped it to the range, so the default source never produced a negative value and a restricted range piled up on its bounds. The uniform inclusive pick of NumberSourceBase moves to Random.NextInclusive in Util, unchanged, and all four sources share it now. NumberSource keeps its sequences, the long and Int128 sequences changed, the integer ones did not (the rejection bound only differs when the top value is drawn). All four throw ArgumentOutOfRangeException when max is below min. Also: LongSourceBase.SetMinMax takes long instead of int, it could not reach the range of its own source before, and Int128IdSource.SetStartValue takes Int128 instead of long. Both are source compatible. README gets a breaking changes block at the top of the 6.0 section. 845 tests per framework. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Several sources still have an exclusive user facing maximum (ColorSource, RandomTextSource, RandomUtfTextSource, and the continuous Decimal/Double/Float sources), so the README says "every integer and date source" instead of "all ranges in AutoPoco". The restricted range test for Int128Source now also asserts that no value takes half the draws, which is what the old clamping implementation did. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The breaking change reads as if the own random generator caused it. It did not: the per-member seeds did, and StableRandom is insurance against a future .NET changing the algorithm behind a seeded Random, not a reaction to a bug. A seeded System.Random is not operating system dependent, that was never the reason. The one real operating system dependency this library had was the culture list behind the old CountrySource, fixed in 4.1.3. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ArgumentNullExceptionfor null setups, types, expressions, providers, factories and evaluators;ArgumentOutOfRangeExceptionfor negative counts inList,Collection,First,Random,Next;ArgumentExceptionwith the offending name for unknown properties, fields and methods, non-source types inUse(Type)and non-convention types inRegister(Type).throw new InvalidOperationException()carry a message with the type and member they failed at.Invoke(c => c.Method("literal"))in the configuration stored theConstantExpressionitself as the argument. Untested so far, only the generation-timeInvokecompiled the lambda. Constants arrive as their value now, captured variables are evaluated once,nullis allowed.Use.From(() => value)andUse.From(ctx => ...)asInvokeargument markers, computed per object. Any other method call in the argument list is rejected with a message naming the options.From,Source,Use.From) take a non-nullableIGenerationContext, so no morectx!. AFuncSourcebuilt from such a lambda throws a clearInvalidOperationExceptionwhen used outside a session.Ctor(...)stub on the generic type builder is removed.GenerateDocumentationFileon, CS1591 suppressed, unresolvedcrefreferences fixed..gitattributeswith* text=auto.MyTestEnumwith ten values and four draws this collides often enough to fail on Windows net9 on main after PR Add generic NumberSource<T> and NullableNumberSource<T> with min/max #5. Bools and enums skip that comparison now.ShouldNotBeEmpty()in front ofShouldAllBeon collections derived from filtering.IGenerationContextin theIDataSourcecontract itself. Standalone use of a source has no context and the test suite callsNext(null)a few hundred times. The nullable parameter is the honest contract there; the ergonomic pain was in the lambdas, which are fixed.Test plan
Use.Fromper object,Use.Fromwith context, mixed withUse.Source, rejection messages; null and range checks across container, builders, conventions, session, generator, collection and selection;FuncSourcewithout context; error messages carry member namesdotnet build -c Releasezero warnings with the documentation file on🤖 Generated with Claude Code