Reeve.PluginAuthoring.TestKit
1.0.0
dotnet add package Reeve.PluginAuthoring.TestKit --version 1.0.0
NuGet\Install-Package Reeve.PluginAuthoring.TestKit -Version 1.0.0
<PackageReference Include="Reeve.PluginAuthoring.TestKit" Version="1.0.0" />
<PackageVersion Include="Reeve.PluginAuthoring.TestKit" Version="1.0.0" />
<PackageReference Include="Reeve.PluginAuthoring.TestKit" />
paket add Reeve.PluginAuthoring.TestKit --version 1.0.0
#r "nuget: Reeve.PluginAuthoring.TestKit, 1.0.0"
#:package Reeve.PluginAuthoring.TestKit@1.0.0
#addin nuget:?package=Reeve.PluginAuthoring.TestKit&version=1.0.0
#tool nuget:?package=Reeve.PluginAuthoring.TestKit&version=1.0.0
Reeve plugin TestKit
Reeve.PluginAuthoring.TestKit is an in-process test harness for Reeve plugins.
It loads your plugin DLL into a load context of its own, creates the plugin through its factory, and hands it an
in-memory IPluginHostServices whose fakes record what the plugin does. Tests run with dotnet test, offline, with no
Reeve backend, Docker or network.
Installation
dotnet add package Reeve.PluginAuthoring.TestKit
The package targets net11.0 and references the ASP.NET Core shared framework, which the .NET SDK includes. It
depends on Reeve.PluginAbstractions 1.0.0, so a test project that references it builds against the same plugin SDK
as Reeve 1.0.0. Projects created with dotnet new reeve-plugin already reference it from their tests/ project.
Usage
The harness needs the path of the plugin DLL in the plugin project's own build output,
<plugin>/bin/<configuration>/<tfm>/<name>.dll. The scaffolded tests/SmokeTests.cs defines a PluginDllLocator
helper that computes it; copy it if your test project was not created from the template.
using Acme.MyWeatherInput;
using Reeve.PluginAbstractions;
using Reeve.PluginAuthoring.TestKit;
using Xunit;
public sealed class MyWeatherInputTests
{
[Fact]
public async Task Reports_its_devices_after_a_resync()
{
var dllPath = PluginDllLocator.Resolve(typeof(MyWeatherInputFactory).Assembly);
await using var harness = new PluginHarness();
using var host = new FakePluginHostServices();
var plugin = await harness.StartAsync(
dllPath,
new Dictionary<string, string> { ["apiKey"] = "test-key" },
host);
var input = Assert.IsAssignableFrom<IInputPlugin>(plugin);
await input.TriggerResyncAsync(CancellationToken.None);
Assert.NotEmpty(host.DeviceEventSink.Discovered);
Assert.Equal(PluginHealthStatus.Healthy, plugin.GetHealth().Status);
}
}
Like the Reeve host, the harness gives the plugin the test's copies of the assemblies the host shares with plugins
(Reeve.PluginAbstractions, ReeveWorkflow.Abstractions, Reeve.Contracts, Reeve.Adapters.Protocol and
Microsoft.Extensions.Logging.Abstractions). It resolves the plugin's other dependencies through its .deps.json
from the folder it loads the plugin from.
PluginHarness
LoadFactory(path)loads the DLL and creates its singleIPluginFactory. It throwsInvalidOperationExceptionwhen the DLL has no factory or more than one.LoadInstance<T>(path)creates the single concrete implementation ofT, for a Block or Trigger plugin that has noIPluginFactory(pass itsIWorkflowBlockFactoryorITriggerPluginFactory).StartAsync(path, config, host, instanceId?, ct)loads the factory, callsCreateandStartAsync, and returns the runningIReevePlugin.- Disposing the harness stops and disposes every plugin
StartAsynccreated, also one whose start threw, ignores exceptions they throw, and unloads every load context.
Each load uses a fresh collectible load context. The types you load must have a public parameterless constructor. A harness is not thread-safe; use one per test.
FakePluginHostServices
AuditWriter,DeviceEventSinkandInMemoryIssueRegistryare the recorders behindAuditSink,DeviceEventsandIssueRegistry.Cacheis a real memory cache, andDataProtectorreturns its input unchanged.- Gated capabilities are absent, as on a host that granted none. Grant one with
With<T>(impl), naming the capability interface asT, for exampleWith<IHttpEgress>(egress).Withrefuses a class asT. GrantedPermissionsis empty andGrantedDeviceTypesisAllTypesuntil you set them withWithGrantedPermissions(...)andWithGrantedDeviceTypes(...).InMemoryObjectStorageis an in-memoryIObjectStorage. To let the plugin use it, grant anIObjectStorageAccesswhoseStoragereturns it. It does not encrypt or enforce size limits.FakePluginHostServices.InMemoryDeviceMetadatais an in-memoryIPluginDeviceMetadata. Return it from theDeviceMetadataof theIDeviceReadAccessyou grant.Reset()clears the recorders, the issue registry, the cache, the object storage and the grants. Dispose the instance after use.
host.With<IObjectStorageAccess>(new StorageAccess(host.InMemoryObjectStorage));
sealed class StorageAccess(IObjectStorage storage) : IObjectStorageAccess
{
public IObjectStorage Storage => storage;
}
Recorders
RecordingDeviceEventSink records every call in arrival order: Discovered, Removed, StateChanges (the raw JSON
overload), CanonicalStateChanges (the typed CanonicalDevice overload), CapabilityChanges, AvailabilityChanges
and DeviceEvents.
RecordingAuditWriter records every audit entry in Entries. AssertEntry(action) returns the first entry with that
action or throws.
InMemoryIssueRegistry keeps issues by code and optional subject. OpenIssues lists the open issues without a
subject, OpenIssuesBySubject every open issue, OpenIssuesFor(code) the open issues of one code, and
ClearedIssues the cleared ones. AssertIssueRaised(code[, subject]) returns the open issue, and
AssertIssueCleared(code[, subject]) the most recently cleared one, or they throw. Raising and clearing validate the
input the way the host registry does and throw ArgumentException for what the host refuses: a blank code or message,
a code over 128 characters, an invalid subject or DocsUrl, a subject on a code the host maps to a core alert, and a
roll issue without an update intent id. A message over 2000 characters is cut, as on the host.
The recorders and the issue registry are thread-safe, so a plugin may publish from several tasks at once. Grant
capabilities and call Reset() while setting up a test, not while the plugin runs.
Limits
- The harness does not run the host's pre-flight checks on the plugin's references. Run
reeve-plugindev validatefor them. - Plugins are trusted in-process code. The fakes enforce no policy on what the plugin does with the services it receives.
PluginHarness's loading members are marked[RequiresUnreferencedCode]and[RequiresDynamicCode]. Run the tests in an ordinary, untrimmed, JIT-compiled test process. A test project with the trim or AOT analyzers on gets IL2026 and IL3050 at those calls.
Documentation
- Plugin TestKit reference in the Reeve documentation.
- Plugin contribution kit: creating, testing and publishing a plugin.
- CHANGELOG and CONTRIBUTING.
Licence
MIT, see LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Reeve.PluginAbstractions (>= 1.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 0 | 11/28/2026 |