ProtoTest.Core
1.0.1
dotnet add package ProtoTest.Core --version 1.0.1
NuGet\Install-Package ProtoTest.Core -Version 1.0.1
<PackageReference Include="ProtoTest.Core" Version="1.0.1" />
<PackageVersion Include="ProtoTest.Core" Version="1.0.1" />
<PackageReference Include="ProtoTest.Core" />
paket add ProtoTest.Core --version 1.0.1
#r "nuget: ProtoTest.Core, 1.0.1"
#:package ProtoTest.Core@1.0.1
#addin nuget:?package=ProtoTest.Core&version=1.0.1
#tool nuget:?package=ProtoTest.Core&version=1.0.1
ProtoTest.Core
The shared, runner-independent runtime at the centre of the ProtoTest foundation: host and lifecycle, an isolated execution context per test, hooks and attributes, clients, owned resources and tracing.
dotnet add package ProtoTest.Core
Most test projects install a runner adapter such as ProtoTest.NUnit or ProtoTest.Xunit3, which brings Core in transitively.
Quick start
public sealed class EnvironmentContext(Uri baseUri) : IProtoContext
{
public Uri BaseUri { get; } = baseUri;
}
public sealed class EnvironmentHook : IProtoTestHook
{
public Task BeforeTestAsync(ProtoExecutionContext context)
{
context.SetContext(new EnvironmentContext(new Uri("https://localhost:5099")));
return Task.CompletedTask;
}
public Task AfterTestAsync(ProtoExecutionContext context) => Task.CompletedTask;
}
await using var host = new ProtoHostBuilder()
.AddTestHook<EnvironmentHook>()
.ConfigureTracing(trace => trace.OutputPath = "TestResults/run.prototrace")
.AddRunGate("no error findings", context => context
.ItemsOfKind(ProtoReportItemKinds.Finding)
.Any(item => item.Status == ProtoReportStatus.Error)
? ProtoRunGateResult.Failed("The run recorded error findings.")
: ProtoRunGateResult.Passed("No error findings were recorded."))
.Build();
var testMethod = typeof(EnvironmentTests).GetMethod(nameof(EnvironmentTests.ReadsTheEnvironment))!;
await host.StartAsync();
_ = await host.StartTestAsync("Reads the environment", testMethod);
// Inside a test, Proto.Context is the active ProtoExecutionContext.
var environment = Proto.Context.Resolve<EnvironmentContext>();
Proto.Context.AddAttachment("environment.txt", environment.BaseUri.ToString());
What it adds
- Host builder —
ConfigureServices,ConfigureAppConfiguration,ConfigureTestIds,ConfigureTracing,AddTestHook<THook>,AddRunHook<TRunHook>,AddRunGate,AddResourceandBuild(). - Execution context —
Proto.Contextexposes the test identity,Resolve<T>/SetContext<T>,Client<T>(name),RegisterResource,AddAttachment,AddFinding,RecordObservationandTrace. - Applications —
AddApplication(name, app => …)declares an application and its clients;AddCapabilityandProtoHost.HasCapabilityback[RequiresCapability]. - Skip conditions —
[RequiresCapability(kind, CapabilityName = …)]and[RequiresInProcess]; adapters evaluate them beforeStartTestAsync. - Tracing — the lifecycle writes
test.setup,test.executionandtest.teardown; entities, resources, findings and gates are recorded automatically.ProtoTraceOptionscontrolsEnabled,OutputPath,ActivitySources,CaptureSourceLocationsandEmbedSources.
One ProtoExecutionContext exists per async flow, one host per builder, and AddTestHook/AddRunHook/AddRunGate do not dedupe repeated calls.
Learn more
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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 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.Configuration (>= 10.0.12)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
-
net8.0
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
-
net9.0
- Microsoft.Extensions.Configuration (>= 9.0.20)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.20)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.20)
- Microsoft.Extensions.DependencyInjection (>= 9.0.20)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.20)
NuGet packages (23)
Showing the top 5 NuGet packages that depend on ProtoTest.Core:
| Package | Downloads |
|---|---|
|
ProtoTest.Json
Shared JSON shape matching and value constraints for ProtoTest integrations. |
|
|
ProtoTest.Http
Shared HTTP foundations for ProtoTest protocol integrations. |
|
|
ProtoTest.Web
Backend-neutral, component-based web testing for ProtoTest. |
|
|
ProtoTest.Sql
A per-test database connection with transaction isolation and owned release for ProtoTest. |
|
|
ProtoTest.Messaging
Messaging integration for ProtoTest: publish and await messages with a predicate and timeout over a broker capability. |
GitHub repositories
This package is not used by any popular GitHub repositories.