Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thomhurst/TUnit
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.62.0
Choose a base ref
...
head repository: thomhurst/TUnit
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.63.0
Choose a head ref
  • 12 commits
  • 66 files changed
  • 2 contributors

Commits on Jul 28, 2026

  1. chore(deps): update tunit to 1.62.0 (#6508)

    Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
    thomhurst and renovate-bot authored Jul 28, 2026
    Configuration menu
    Copy the full SHA
    b3147ad View commit details
    Browse the repository at this point in the history

Commits on Jul 29, 2026

  1. Configuration menu
    Copy the full SHA
    4f2f1b5 View commit details
    Browse the repository at this point in the history
  2. chore(deps): update dependency mockolate to 3.4.0 (#6512)

    Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
    thomhurst and renovate-bot authored Jul 29, 2026
    Configuration menu
    Copy the full SHA
    9e6d8ac View commit details
    Browse the repository at this point in the history
  3. chore(deps): update dependency cliwrap to 3.10.4 (#6513)

    Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
    thomhurst and renovate-bot authored Jul 29, 2026
    Configuration menu
    Copy the full SHA
    fe936cc View commit details
    Browse the repository at this point in the history

Commits on Jul 30, 2026

  1. fix(mocks): dispatch abstract indexers through the engine instead of …

    …calling base (#6517)
    
    CreateIndexerModel never set IsAbstractMember, so every class indexer took
    the virtual-member path in GenerateOverrideIndexer and emitted a
    `return base[...];` / `base[...] = value;` fallback. For an abstract
    indexer there is no base implementation, so the generated mock failed to
    compile with CS0205 — blocking e.g. DbDataReader, which declares two
    abstract indexers.
    
    Carry IsAbstractMember/IsVirtualMember on the indexer model like methods
    and properties already do; the existing abstract branches in
    GenerateOverrideIndexer then emit engine-only dispatch. Virtual indexers
    keep their base fallback.
    
    Fixes #6516
    thomhurst authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    8350a00 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7ac3300 View commit details
    Browse the repository at this point in the history
  3. chore(deps): update dependency stackexchange.redis to 3.0.25 (#6522)

    Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
    thomhurst and renovate-bot authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    0732319 View commit details
    Browse the repository at this point in the history
  4. chore(deps): update dependency brace-expansion to v5.0.9 (#6523) aw

    Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
    thomhurst and renovate-bot authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    974443c View commit details
    Browse the repository at this point in the history
  5. feat(mocks): experimental compile-time internals access (#6514 Tier 2) (

    #6520)
    
    * feat(mocks): experimental compile-time internals access (#6514 Tier 2)
    
    Runtime auto-stubs (#6519) satisfy SDK-internal generic requests with
    functional defaults, but the test can never configure or verify such a
    type — it cannot write the type's name. This prototype removes that
    constraint: behind TUnitMocksExperimentalInternalsAccess, internal
    types of selected referenced assemblies become first-class mockable —
    nameable in test code, source-generated typed mocks, setups, matchers,
    verification — with zero InternalsVisibleTo required from the target
    assembly.
    
    Mechanism (the established publicizer pattern, wired for TUnit.Mocks):
    a Mono.Cecil MSBuild task rewrites the selected references so internals
    are public, preserving assembly identity, and swaps them into
    ReferencePathWithRefAssemblies only — the compiler's view. deps.json
    and copy-local keep the originals, so the runtime loads the real
    assembly, where the task-emitted IgnoresAccessChecksTo attribute makes
    the compiled IL (including generated mock classes implementing internal
    interfaces) valid. The mocks source generator needs no changes: through
    the publicized reference the types simply look public.
    
    Validated end to end against a fake-SDK library that grants no IVT to
    anyone (the exact case runtime stubs cannot reach): naming, mocking,
    typed setup/matcher/verification of an internal interface requested by
    SDK-internal code, and a hand-written implementation proving the
    runtime honors the attribute at type load. Incremental builds stay
    no-op; cold builds order correctly via project references.
    
    Experimental caveats documented in the project README: undocumented
    (but ecosystem-established) runtime attribute, inert on .NET Framework,
    AOT unverified, packaging not yet done.
    
    * feat(mocks): productionize internals access — packaging, dual-runtime task, tests, CI, docs
    
    Graduates the #6514 Tier 2 prototype into the TUnit.Mocks package:
    
    - The publicizer task multi-targets net472 (Visual Studio's .NET
      Framework MSBuild) and net8.0 (dotnet msbuild), selected via
      $(MSBuildRuntimeType); MSBuild references are compile-time only and
      pinned to a version shipping both assets. Task and Mono.Cecil ship
      under tasks/<tfm>/ in the nupkg (NU5100 suppressed — task assemblies
      are exactly the thing that must not live in lib/).
    - TUnit.Mocks.InternalsAccess.targets moved into src/TUnit.Mocks, packed
      to buildTransitive/<tfm>/ and build/, and imported by
      TUnit.Mocks.targets — consumers need only the opt-in property and
      item. Fully inert otherwise (verified: full TUnit.Mocks.Tests suite
      unaffected). Dual-path task resolution covers packaged and repo-local
      layouts.
    - Correctness fix surfaced by new coverage: publicize the
      IMPLEMENTATION assembly (%(OriginalPath)), not the reference assembly
      — Roslyn ref assemblies strip internal members when no IVT exists, so
      internal constructors vanished and internal classes emitted TM006.
      The compiler-facing item (the ref assembly) is still what gets
      swapped out.
    - Coverage expanded: internal class partial mocks (internal ctor),
      closed-generic internal interfaces, strong-named target assembly
      (identity preservation asserted down to the public key token), and
      unit tests of the task itself — publicizing, incrementality, the
      generated IgnoresAccessChecksTo source, and TUMIA001 for unresolved
      names. Build-order edges use SetTargetFramework per task TFM
      (SkipGetTargetFrameworkProperties alone leaks the referencing
      TargetFramework and breaks the outer build).
    - Verified against the produced nupkg: extracted-package buildTransitive
      import compiles and runs a consumer implementing an internal
      interface, including under PublishTrimmed (full trim mode). Native
      AOT remains unverified.
    - CI: projects added to TUnit.CI.slnx and a RunMockInternalsAccessTests
      pipeline module runs the suite; docs gain an "Internals Access
      (experimental)" section.
    
    * fix(mocks): harden internals-access task per review
    
    - Preserve original reference metadata (Aliases, EmbedInteropTypes) on the
      swapped compiler reference via CopyMetadataTo
    - Content-hash (.sig) incrementality instead of timestamp comparison, so
      downgrades/equal-timestamp replacements re-publicize; sig files in FileWrites
    - Resolve implementation assembly from runtime/copy-local assets when the
      compile asset is a ref assembly with no OriginalPath (TUMIA003 when absent)
    - Warn TUMIA004 on ambiguous simple-name matches instead of silent first-pick
    - Wrap resolve/publicize in try/catch -> TUMIA005 error instead of unhandled
      Cecil exception crashing the build host
    - TUnitMocksInternalsAccessEmitAttributeDefinition=false suppresses the
      IgnoresAccessChecksToAttribute definition when another package injects it
    - README: diagnostics table + rationale for custom task vs Krafs.Publicizer
    
    * fix(mocks): scope publicizer to assembly-visible members and remove all ambiguous matches
    
    Review round 3:
    - TUMIA004 now supersedes ALL same-simple-name matches, not just the winner —
      a leftover duplicate shared the publicized copy's assembly identity (CS1703).
      New SupersededReferences task output feeds the targets Remove.
    - Publicize promotes only internal/protected internal/private protected;
      private and protected members are untouched, so a formerly-private overload
      can no longer capture existing calls in consuming code.
    - IgnoresAccessChecksTo is emitted with the assembly's real identity read from
      the resolved file, not the file-derived requested name.
    
    * fix(mocks): dedupe internals-access requests, union ambiguous-match metadata, version the cache signature
    
    - Duplicate TUnitMocksInternalsAccess items (same simple name, any case) now
      produce a single publicized reference instead of handing Csc the same
      rewritten assembly twice.
    - When multiple resolved references share the requested simple name, extern
      aliases are unioned and EmbedInteropTypes kept if any match set it, so
      compiler-significant metadata carried only by a non-selected match survives
      the swap.
    - The incrementality signature now includes the task version, so a TUnit.Mocks
      upgrade re-publicizes instead of reusing a copy produced by older rewrite
      rules.
    
    * fix(mocks): resolve runtime implementation assets by assembly identity
    
    A compile asset's file name can differ from the assembly identity it
    contains; the implementation then appears among the runtime assets under
    the real name, so the file-name-only match missed it and publicized the
    stripped ref assembly (TUMIA003). The fallback now reads the reference's
    real identity and matches runtime assets by identity name, preferring a
    version-exact match, with the file-name match kept as the fast path.
    
    * fix(mocks): identity-aware ambiguous-match handling and identity-based request lookup
    
    Same-simple-name matches are now partitioned by real assembly identity:
    only the winner's exact identity (name/version/public key) is superseded
    and metadata-merged; different-identity references (legal only under
    extern aliases) stay in the compiler's reference list untouched.
    
    Requested names that miss by file name now fall back to matching each
    reference's real assembly identity, so a renamed compile asset resolves
    by the documented simple assembly name instead of failing TUMIA001.
    
    * fix(mocks): publicize every distinct assembly identity behind a simple name, collision-proof output paths
    
    A simple-name request has no way to single out one of two extern-aliased
    references with different identities, so each identity group now gets its
    own publicized copy (per-identity aliases preserved, never merged across
    identities); previously the non-first identity was retained and could
    never be publicized.
    
    Publicized copies now land in a per-source-path subdirectory, so two
    implementation assemblies sharing a file name (renamed assets, or two
    identities behind one name) cannot overwrite each other's copy.
    
    * fix(mocks): identity-first runtime-asset resolution, case-safe path tokens
    
    The filename-first shortcut in FindRuntimeImplementation handed both
    identity groups of a same-file-name extern-alias pair the first
    implementation, so the second publicized copy carried the wrong
    identity. Identity now decides; the requested-name filename match
    survives only for a reference whose own identity cannot be read.
    
    Path tokens fold case only on Windows hosts — on a case-sensitive
    filesystem /deps/A/Foo.dll and /deps/a/Foo.dll are different sources
    and folding would collapse their destinations.
    
    * fix(mocks): identity-first reference lookup, full-identity runtime matching, platform-aware path compare
    
    - FindReferenceMatches now matches readable assembly identities first; a
      colliding file name holding a different identity can no longer hide the
      real match. File-name matching survives only for unreadable references
      and as a no-identity-match compatibility fallback. Identity reads are
      cached per task invocation.
    - FindRuntimeImplementation compares the full identity: a candidate with
      a conflicting public key token is never selected; version drift alone
      remains the tolerated fallback.
    - The reference-asset exclusion folds path case only on case-insensitive
      hosts, matching the HashPathToken rule.
    thomhurst authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    228dcf6 View commit details
    Browse the repository at this point in the history
  6. chore(deps): update dependency microsoft.build.utilities.core to v18 (#…

    …6525)
    
    Co-authored-by: Renovate Bot <renovate@whitesourcesoftware.com>
    thomhurst and renovate-bot authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    8ac5340 View commit details
    Browse the repository at this point in the history
  7. feat(mocks): make the async-factory Returns alias available below net…

    …9.0 (#6518)
    
    * feat(mocks): make the async-factory Returns alias available below net9.0
    
    The Returns(Func<Task<T>>) alias added for #6495 carried
    [OverloadResolutionPriority(-1)] to stay unambiguous against the
    synchronous Returns(Func<T>) sibling for typeless lambdas like
    Returns(() => null). The attribute type only reaches a consumer's
    compilation on net9.0+, so the whole alias was gated there — on net8.0
    and net472, .Returns(async () => ...) did not exist at all and a mocked
    async call could only be handed back already-completed (issue #6515).
    
    Below net9.0 the alias is now generic instead:
    Returns<TAsyncFactoryResult>(Func<Task<TAsyncFactoryResult>>). A
    typeless lambda body (null / throw / default) cannot infer the type
    parameter, which excludes the alias from the candidate set and resolves
    the tie to the synchronous overload exactly as ORP does — while a
    genuine async lambda with an inferable body binds the alias, ValueTask
    included. The net9.0+ ORP shape is unchanged (it keeps the compile-time
    result-type check the generic form trades for inference). Bare
    Task/ValueTask members have no synchronous sibling to collide with, so
    their alias is now emitted unconditionally without either mechanism.
    
    The Issue6495 tests drop their net9.0+ gates and now run on every
    target framework, and Issue6515Tests adds the issue's timeout-race
    consumer shape.
    
    Fixes #6515
    
    * fix(mocks): keep outer-nullable Task members on the gated async alias
    
    Review finding (#6518): IsGenericTaskType tested EndsWith(">"), so an
    outer-nullable member type like Task<string?>? — which carries a
    trailing '?' — was misread as bare Task and got the ungated,
    unprioritized alias next to the synchronous factory, turning an
    existing Returns(() => null) setup into CS0121 on every TFM. Trim the
    annotation before testing.
    
    The new regression coverage surfaced a second, pre-existing break on
    the same member shape: EmitRawReturnCheck used the annotated return
    type in an `is` pattern, which is never legal (CS8116) — so
    outer-nullable async members could not be mocked at all. The pattern
    now drops the outer annotation; a null raw value falls through to the
    existing informative throw.
    
    Covered by a generator test compiling the ambiguous call site and
    runtime tests on the Task<string?>? shape (sync null-lambda binding and
    pending async factory).
    
    * fix(mocks): convert async-factory results to the declared task type; make the generic alias primary on every TFM
    
    Review finding (#6518): below net9.0 the generic alias infers the async
    lambda's own result type, which may be a SUBTYPE of the member's
    declared result (Task<object> member, async () => "value" infers
    Task<string>) — and Task<T>/ValueTask<T> are invariant, so the
    implementation's raw-return check rejected the stored task and produced
    a faulted task. The generic alias now converts to the declared task
    type: an exact-typed factory task passes through untouched (identity
    preserved), anything else is mirrored by an async wrapper that stays
    pending until the inner task completes.
    
    Writing regression coverage exposed that the net9.0+ ORP branch was
    WORSE on the same member shape: a natural-typed async lambda converts
    to object, ORP(-1) pruning runs before betterness, and Returns(object
    value) silently boxed the delegate as the member's value. The generic
    alias wins that contest (lambda-to-delegate beats lambda-to-object), so
    it is now the primary alias on EVERY target framework. The ORP(-1)
    non-generic alias remains, net9.0+-only, for the one shape generics
    cannot express — async () => null pins no type, so the deprioritised
    alias is the sole applicable candidate — and ORP pruning guarantees the
    two aliases are never ambiguous with each other.
    
    Second review finding: for an outer-nullable member, ReturnsAsync
    accepts a null task, but the raw-return pattern can never match null —
    the generated check now returns null there instead of throwing.
    
    Runtime coverage: subtype conversion (Task, ValueTask, typed
    parameters, pending-ness), exact-task identity, null-task on an
    outer-nullable member, and the async-null-body corner on net9.0+.
    Suites: 1193/1193 net10.0, 1192/1192 net9.0, 1176/1176 net8.0;
    generator 91/91 with 7 snapshots updated.
    
    * fix(mocks): harden the generic async-factory Returns alias per review
    
    - Replay implicit numeric widening in the conversion helper: a boxed int
      cannot unbox as long, so numeric-primitive result types get a guarded
      Convert.ChangeType branch (string/bool excluded to avoid silent parsing);
      anything else throws an informative InvalidCastException naming both types
    - Uniquify the alias's type parameter against the mocked type's and method's
      own type parameters (a user-declared TAsyncFactoryResult shadowed it and
      rebound the helper's result type)
    - Pass a null factory task straight to the raw-return check (valid for
      outer-nullable members) instead of faulting inside the conversion helper
    
    * fix(mocks): make the async-factory conversion helper honest about C# conversions
    
    Codex round 2 on #6518, all in the generated __TUnitMocksAwaitAndConvert helper:
    
    - Task<dynamic>/ValueTask<dynamic> members no longer break consumer compilation:
      `dynamic` is illegal as a pattern type (CS8208) and as a typeof operand (CS1962),
      so the helper's pattern/typeof spell it `object` (an identity conversion at the
      return site). Constructed types containing dynamic (Task<dynamic>) are legal and
      keep their spelling.
    - A null factory result on a non-nullable value-type member (Task<int> member,
      alias inferring Task<int?>) now throws the informative InvalidCastException
      naming the inferred and declared types instead of silently producing default
      (zero). The check is a runtime one so generic result types are judged by their
      instantiation; null remains valid for reference/nullable results.
    - Convert.ChangeType is gone: only C#'s implicit numeric widening table is
      replayed, each source type as a dedicated compiler-verified cast case.
      Narrowing/rounding pairs C# rejects (long->int, double->int, double->decimal)
      now surface via the informative InvalidCastException instead of silently
      truncating or rounding.
    
    * fix(mocks): replay implicit constant numeric conversions in the async-factory helper
    
    `async () => 1` on a Task<byte> member compiles against the declared
    delegate via C#'s implicit constant expression conversion, but the
    generic alias infers int and the widening table had no int -> byte
    entry, so the awaited boxed int faulted with InvalidCastException.
    Constant-ness is erased at runtime, so the helper now replays these
    conversions as range-guarded exact-value cases (int -> sbyte/byte/
    short/ushort/uint/ulong, long -> ulong when non-negative); out-of-range
    values keep taking the informative InvalidCastException path.
    
    * fix(mocks): runtime null guard for defaultable T? results and constant-zero-to-enum replay
    
    A trailing '?' on an unconstrained (or class-constrained) type parameter
    is the defaultable annotation, not Nullable<T> — Task<T?> with T = int
    is Task<int>, so the textual EndsWith check wrongly suppressed the
    runtime value-type null guard and a null factory result became 0. The
    guard skip is now decided from the type-parameter model: only
    struct-constrained T? (genuine Nullable<T>) and concrete annotated
    types skip it.
    
    The conversion helper also replays C#'s implicit constant-zero-to-enum
    conversion as a value-guarded case: integral sources only (never
    another enum), exactly zero, enum destinations only — judged by
    typeof(T).IsEnum so generic instantiations participate. Non-zero values
    keep the informative InvalidCastException.
    
    * fix(mocks): include native integers in the async conversion tables
    
    nint -> long (and nuint -> ulong, and both -> float/double/decimal) are
    ordinary implicit numeric conversions, the small integral types convert
    to nint/nuint, and a non-negative int constant converts to nuint — none
    of which the widening/constant tables replayed, so a factory inferring a
    native-integer type faulted with InvalidCastException. Both spellings
    map (System.IntPtr IS nint to the compiler on the supported TFMs).
    Native integers are also excluded from the maybe-enum destination set.
    
    * fix(mocks): replay implicit tuple conversions element-wise in the async alias
    
    A Task<(object, object)> member with .Returns(async () => ("a", "b"))
    infers (string, string); the boxed ValueTuple<string, string> matched no
    case and threw InvalidCastException. The conversion switch now has an
    ITuple case for value-tuple result types (System.Tuple excluded — it
    never converts implicitly) that converts each element through its own
    generated converter, replaying the same conversion set as a whole
    result — reference/boxing, numeric widening, guarded constants,
    zero-to-enum — and recursing for nested tuples. The tuple's exact case
    is subsumed by the element-wise path, keeping tuple type patterns out
    of the generated code.
    
    Tuple element names are now stripped wherever the helper spells the
    type (typeof rejects them), fixing the pre-existing consumer compile
    break for named-tuple async members like Task<(int Id, string Name)>.
    
    * fix(mocks): no enum-zero case on IConvertible results, no numeric cases on type parameters
    
    Two consumer-compilation breaks in the async conversion helper:
    
    - A member declared Task<IConvertible> emitted the constant-zero-to-enum
      case (`case IConvertible zero when ...`) directly after
      `case IConvertible exact`, making it unreachable — CS8120 is an error.
      IConvertible joins the exclusion list (typeof(IConvertible).IsEnum is
      false, so the case was dead at runtime anyway).
    
    - A type parameter NAMED like a BCL numeric type (interface IFoo<Int32>)
      was mistaken for System.Int32 by the name-based conversion tables, and
      the numeric widening/constant cases were emitted into a helper returning
      the open parameter — CS0029. Type parameters now bypass the numeric
      tables entirely and take only the exact/null/zero-to-enum cases, all
      runtime-guarded per instantiation.
    
    * fix(mocks): skip typed-local dynamic consumption tests under Native AOT
    
    Assigning an awaited `dynamic` to a typed local makes the C# runtime
    binder build an expression tree, which NREs in ExpressionTreeRewriter
    under Native AOT (net8). The conversion helper itself stays covered on
    AOT by the object-typed null-result test.
    thomhurst authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    bc26e16 View commit details
    Browse the repository at this point in the history
  8. +semver:minor - feat(mocks): runtime auto-stubs for interfaces the so…

    …urce generator cannot see (#6519)
    
    * +semver:minor - feat(mocks): runtime auto-stubs for interfaces the source generator cannot see
    
    A loose-mode mock member that must produce an interface with no
    source-generated factory — most notably a generic method like
    IFeatures.Get<T>() invoked inside a third-party SDK with a T that is
    internal to that SDK, unnameable by the test assembly — fell through to
    null, surfacing as an NRE deep in SDK code (#6514). Runtime-proxy
    libraries handle this via Castle auto-substitution, and its absence was
    a structural migration blocker.
    
    The engine's auto-mock fallback now emits a functional stub at runtime
    when the registry has no factory: a Reflection.Emit type in a dynamic
    assembly named DynamicProxyGenAssembly2 carrying Castle DynamicProxy's
    well-known public key, so the InternalsVisibleTo grants SDKs already
    extend for NSubstitute/Moq compatibility apply to TUnit.Mocks too.
    Dynamic assemblies are never strong-name verified, so the public key
    alone satisfies the grant.
    
    Stubs are recursive with NSubstitute-style defaults — empty strings,
    completed tasks, empty collections, zeroed value types, further stubs
    (or a real configurable Mock<T> when a generated factory exists) for
    interface members — properties round-trip set values, and member
    results are cached for stable identity. Generic interface methods are
    supported, including constraint re-emission. Not configurable or
    verifiable: their types cannot be named by the test.
    
    Guards: loose mode only; RuntimeFeature.IsDynamicCodeSupported (inert
    on Native AOT, retaining the previous defaults); opt-out via
    TUnitMocksSettings.RuntimeAutoStubs; emission failures (no IVT grant,
    static abstracts, by-ref returns) are cached misses that fall back to
    the previous behavior. netstandard2.0 keeps a no-op implementation.
    
    Fixes #6514
    
    * fix(mocks): key the runtime-stub return cache by closed return type
    
    Review finding (#6519): a generic member like T Get<T>() on a
    runtime-stubbed interface shares one member slot across every
    instantiation, so the per-slot default cache handed Get<string>() the
    boxed value cached by Get<int>() and the emitted unbox/cast threw
    InvalidCastException. The cache key now pairs the slot with the closed
    return type observed at the call; property slots are unaffected (their
    type is constant) and same-instantiation identity stays stable.
    
    * fix(mocks): key stub indexer state by index arguments; disambiguate ValueTask default construction
    
    Review findings (#6519):
    
    Indexers: the emitted accessors forwarded only the member slot, so
    stub[1] = x made stub[2] return x and every index observed the last
    write. The emitted IL now boxes the index arguments into an object?[]
    and state lives in a per-(slot, structural index key) map; defaults
    stay index-independent for stable identity. Indexers with by-ref /
    ref-struct / pointer index parameters (which cannot be boxed) keep the
    previous slot-level behavior.
    
    ValueTask<T> defaults: ValueTask<T> has both (T) and (Task<T>)
    constructors, and a null inner default (reference-typed T) matches
    either, making Activator.CreateInstance ambiguous. The constructor is
    now selected explicitly by parameter type.
    
    * fix(mocks): key auto-mock cache by Type identity, not FullName string
    
    Two types with identical namespace-qualified names from different assemblies
    collided in the auto-mock/stub cache (memberName + FullName string), so the
    second invocation retrieved the first type's stub and the TReturn cast threw
    InvalidCastException. Cache is now keyed by (memberName, Type). TryGetAutoMock
    (no callers) updated to match.
    
    * fix(mocks): serialize stub emission and route typed cache misses through stubs
    
    Review round 4:
    - EmitStubType now runs under a static lock: ConcurrentDictionary.GetOrAdd
      only de-duplicates per key, so distinct interfaces first-touched in
      parallel reached ModuleBuilder.DefineType/TypeBuilder.CreateType on the
      shared module concurrently (unsafe on coreclr, dotnet/runtime#64094).
      Cache hits stay lock-free.
    - The eight typed cache-miss handlers (1-8 args) in MockEngine.Typed.cs now
      call TryGetLooseAutoMockResult instead of an inlined registry-only lookup,
      so members returning interfaces without a generated factory (e.g.
      System.*) reach the runtime-stub fallback like the object-array handler.
    
    * test(mocks): pin null round-trip for writable stub properties and indexers
    
    Codex round-5 finding claimed ConcurrentDictionary rejects null values so
    `stub.Name = null` would throw. It rejects null KEYS, not values; the stub
    keys by slot int / index tuple. Regression test pins the behavior.
    
    * fix(mocks): restore the legacy string TryGetAutoMock overload for binary compat
    
    Re-keying the auto-mock cache by (memberName, Type) removed the public
    TryGetAutoMock(string, out IMock?) CLR signature, breaking assemblies
    compiled against the previous shape with MissingMethodException. The
    legacy overload is back and resolves entries by the old
    memberName + "|" + returnType.FullName key format against the new cache.
    
    * fix(mocks): single-emission stub cache, honest TryGetAutoMock miss, netstandard docs
    
    Stub type cache now stores Lazy<Type?> so racing first-touches of the
    same interface emit exactly one permanent dynamic type instead of one
    per contender; cache hits stay lock-free.
    
    TryGetAutoMock(string, Type) returns false for a cached null — a
    definitive miss is not a usable mock, and NotNullWhen(true) promises
    non-null on true.
    
    Docs now state the netstandard2.0 asset (.NET Framework hosts) does not
    include the runtime emitter.
    
    * fix(mocks): preserve custom modifiers on emitted stub signatures
    
    Custom modifiers are part of the CLR signature a MethodImpl must match:
    an init setter's modreq(IsExternalInit) or an in parameter's
    modreq(InAttribute) dropped during emission made CreateType reject the
    stub, turning the interface into a cached miss (null). DefineExplicitImpl
    now builds the signature with SetSignature, copying the target's return
    and parameter required/optional custom modifiers.
    thomhurst authored Jul 30, 2026
    Configuration menu
    Copy the full SHA
    527719c View commit details
    Browse the repository at this point in the history
Loading