MagicCSharp.Testing
1.0.0
See the version list below for details.
dotnet add package MagicCSharp.Testing --version 1.0.0
NuGet\Install-Package MagicCSharp.Testing -Version 1.0.0
<PackageReference Include="MagicCSharp.Testing" Version="1.0.0" />
<PackageVersion Include="MagicCSharp.Testing" Version="1.0.0" />
<PackageReference Include="MagicCSharp.Testing" />
paket add MagicCSharp.Testing --version 1.0.0
#r "nuget: MagicCSharp.Testing, 1.0.0"
#:package MagicCSharp.Testing@1.0.0
#addin nuget:?package=MagicCSharp.Testing&version=1.0.0
#tool nuget:?package=MagicCSharp.Testing&version=1.0.0
MagicCSharp.Testing
Test doubles for the MagicCSharp framework. No test framework dependency, no database, no containers — add
MagicCSharp.Testing.Database when you need those.
| Type | Replaces | Why |
|---|---|---|
FakeClock |
IClock |
Move time by hand. A thirty-day late fee is testable in milliseconds. |
FakeKeyGen |
IKeyGenService |
Snowflake ids derived from FakeClock, so ids and timestamps agree. |
SyncEventDispatcher |
IEventDispatcher |
Runs handlers inline and records them, so you can assert without sleeping. |
InMemoryDistributedLockProvider |
IDistributedLockProvider |
Real mutual exclusion in-process, re-entrant during inline event dispatch. |
TrackingDistributedLockProvider |
IDistributedLockProvider |
Grants everything, records the names — for asserting what was locked. |
Wiring
var clock = new FakeClock();
services.RemoveAll<IClock>();
services.AddSingleton<IClock>(clock);
services.RemoveAll<IKeyGenService>();
services.AddSingleton<IKeyGenService>(new FakeKeyGen(clock));
services.RemoveAll<IDistributedLockProvider>();
services.AddSingleton<IDistributedLockProvider, InMemoryDistributedLockProvider>();
services.RemoveAll<IEventDispatcher>();
services.AddSingleton<IEventDispatcher>(sp =>
new SyncEventDispatcher(sp.GetRequiredService<IAsyncEventDispatcher>()));
Asserting on events
clock.SetTime(2026, 3, 1);
await createOrder.Execute(new CreateOrderRequest(userId: 1, productIds: [2, 3]));
Assert.True(events.HasDispatchedEvent<OrderCreated>());
Assert.Single(events.GetDispatchedEvents<OrderCreated>());
One deliberate difference from production
SyncEventDispatcher runs handlers inline, inside whatever lock the emitting use case holds. In production
dispatch is fire-and-forget, so handlers run after that lock is released. InMemoryDistributedLockProvider
closes the gap: while SyncEventDispatcher is dispatching, a handler re-acquiring a name the emitter holds
gets a no-op handle rather than deadlocking. The window is scoped to that one dispatch, so genuinely
concurrent flows still get ordinary mutual exclusion.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- DistributedLock.Core (>= 1.0.8)
- MagicCSharp (>= 1.0.0)
- MagicCSharp.Events (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MagicCSharp.Testing:
| Package | Downloads |
|---|---|
|
MagicCSharp.Testing.Database
Repository integration testing for MagicCSharp against a real PostgreSQL in Testcontainers: one container shared across the suite, a logical database per test class, schema created once, and tables truncated between tests. Separate from MagicCSharp.Testing because it needs Docker, xUnit and Npgsql. |
GitHub repositories
This package is not used by any popular GitHub repositories.