Stratara.Testing
3.2.3
See the version list below for details.
dotnet add package Stratara.Testing --version 3.2.3
NuGet\Install-Package Stratara.Testing -Version 3.2.3
<PackageReference Include="Stratara.Testing" Version="3.2.3" />
<PackageVersion Include="Stratara.Testing" Version="3.2.3" />
<PackageReference Include="Stratara.Testing" />
paket add Stratara.Testing --version 3.2.3
#r "nuget: Stratara.Testing, 3.2.3"
#:package Stratara.Testing@3.2.3
#addin nuget:?package=Stratara.Testing&version=3.2.3
#tool nuget:?package=Stratara.Testing&version=3.2.3
Stratara.Testing
Derived. The behaviour described here is specified under
openspec/specs/. Those specifications are the source; this page explains and illustrates them.
Test doubles and assertion helpers for applications built on the Stratara framework. Unit-test your event-sourced aggregates, encryption, messaging, and session-aware code without spinning up Postgres or RabbitMQ testcontainers.
Contents
AggregateTestHarness<T>/Aggregate.Rehydrate<T>(...)— given/when/then rehydration of an aggregate from events, using the sameApply(...)dispatch as production. Throws on an unmapped event so a forgotten overload fails the test (opt out withIgnoringUnmappedEvents()).InMemoryKeyStore— anIKeyStorethat mints random 256-bit DEKs per scope and supports rotation / revocation / scope-erasure, without a master KEK or key file.TestBlobEncryptor.CreateAesGcm()— the real AES-GCMISecureBlobEncryptorover anInMemoryKeyStore, so blob round-trips exercise production encryption.InMemoryMessageBus— anIMessageBuswith synchronous in-process dispatch and aPublishedlist for assertions.TestSessionContext/TestSessionContextProvider— preset Actor/SubjectSessionContextvalues and anISessionContextProviderdouble.InMemoryTenantMembershipStore— anITenantMembershipStoremirroring the EF store's contract semantics, including the membership-guarded active-tenant selection and the erasure sweeps.InMemorySettingStore— anISettingStorewith exact-scope reads/writes, so the scoped-settings fallback chain can be exercised without a database.InMemoryApiKeyStore— anIApiKeyStoremirroring the EF store's contract semantics: issuance, idempotent import of a caller-supplied key, fail-closed validation, revocation, erasure sweeps, and machine keys materialized into a membership store you can share and inspect.TestTenants.Of("acme")— stable, deterministic tenant/user ids derived from readable slugs.TestEvent.Create(payload, ...)— wrap an event payload inIEvent<T>with realistic metadata.ProjectionTester.HandleAsync(projection, event)— invoke a projection's (private)HandleAsynchandler directly, so you can unit-test it against mocked repositories.
Example
var account = AggregateTestHarness<Account>
.Given(new AccountOpened(id, "Ada", 100m))
.And(new AmountWithdrawn(id, 30m))
.Build();
Assert.Equal(70m, account.Balance);
Dependencies
Stratara.Abstractions,Stratara.Contracts,Stratara.Shared,Stratara.SecurityMicrosoft.Extensions.DependencyInjection
Reference it from your test projects only (<PackageReference Include="Stratara.Testing" />). It is
not meant for production code paths — the InMemoryKeyStore and DummyKeyStore provide no
durability or KEK custody.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.8)
- Stratara.Abstractions (>= 3.2.3)
- Stratara.Contracts (>= 3.2.3)
- Stratara.Security (>= 3.2.3)
- Stratara.Shared (>= 3.2.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Stratara.Testing:
| Package | Downloads |
|---|---|
|
Stratara.Testing.EntityFrameworkCore
Spin up the real Stratara event-sourcing write stack (EventSource, aggregation, snapshots, the EF Core write store) against a shared in-memory SQLite database in one call — production code paths, no Postgres, no Docker. Builds on Stratara.Testing's in-memory doubles. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Three correctness fixes, all of the same kind: behaviour that failed by succeeding. A pipeline
behaviour registered twice ran twice and nothing said so; a closed generic type name normalized to a
malformed key that two different types could share, and the loser of that collision was discarded
silently; and a heavy command republished from the outbox left its lane whenever its type could not
be resolved. None produced an error, and no test covered any of them. They were found by reading the
code against the specification rather than by a failure report.
### Fixed
- **A pipeline behaviour registered twice now installs once.** Every behaviour registrar used a
plain scoped registration, so a host that called one twice — the ordinary result of composing two
service bundles that each set up their own slice of the framework — installed the stage twice and
ran it twice per request. None of the three consequences was benign: every validator ran twice
against every request, so a validator with a side effect (a uniqueness check against the database)
performed it twice; the tenant guard ran twice, the second time against a second options instance
that could disagree with the first; and two nested resilience pipelines multiplied rather than
added, turning a configured budget of four attempts into sixteen. `AddStrataraValidation`,
`AddStrataraTenantIsolation`, `AddStrataraResilienceBehavior`, `AddCommandAuditing` and the
`AddPipelineBehavior` / `AddPipelineBehaviorWithResult` primitives are now idempotent per behaviour
type. Registering two *different* behaviours is unaffected.
- **A closed generic type name now normalizes correctly.** Resolving a recorded type name is meant to
ignore the assembly version and match on the type name and assembly name alone. For a closed
generic it did neither: the name was truncated at its second comma, which for a generic falls
*inside* the type-argument brackets, so the outer assembly name was dropped and the key became a
malformed fragment. Two closed generics that differed only in the assembly that declared them
collapsed onto one key, and the second registration was then silently discarded — an event
upcaster could match the wrong source type, and a type a host believed it had registered was
unresolvable. Names are now parsed rather than counted, and each type argument is reduced the same
way as the outer name, so upgrading the *payload's* assembly no longer strands rows either.
- **A heavy command republished from the outbox stays in the heavy lane.** When a stored command's
recorded type could not be resolved in the process draining the outbox, republication fell back to
the shared command topic regardless of the lane the command belonged to. Depending on how the lanes
are deployed, the command was then either dead-lettered by the interactive worker or executed on
the interactive lane — the starvation the separate lane exists to prevent. The lane is now recorded
on the envelope when the command is enqueued, so republication no longer depends on resolving the
type.
### Changed
- **Registering two different types under one recorded name now fails.** The trusted-type resolver
previously kept the first and discarded the second without a word, which is indistinguishable from
a registration that never happened: the type simply fails to resolve later, when a stored row is
read. `ITrustedTypeResolver.Register` now throws, naming both types. Registering the same type
again remains a no-op. Reaching this requires two distinct types sharing a full type name *and* a
simple assembly name in one process.
- **`TenantIsolationOptions` follows the options pattern.** The mode can now be bound from
configuration with `Configure<TenantIsolationOptions>(section)` in addition to the
`AddStrataraTenantIsolation(o => ...)` callback, and a second call to the registrar no longer
leaves a conflicting second options instance behind. `Stratara.Mediator` therefore takes a
dependency on `Microsoft.Extensions.Options`.
### Added
- **`CommandEnvelope.Heavy`** records whether a command declared itself long-running when it was
enqueued. Optional and defaulting to `false`, which is how an envelope written by an earlier
version deserializes; the signed canonical form is unchanged, so existing signatures still verify.