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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Reeve.PluginAuthoring.TestKit" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Reeve.PluginAuthoring.TestKit" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Reeve.PluginAuthoring.TestKit" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Reeve.PluginAuthoring.TestKit --version 1.0.0
                    
#r "nuget: Reeve.PluginAuthoring.TestKit, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Reeve.PluginAuthoring.TestKit@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Reeve.PluginAuthoring.TestKit&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Reeve.PluginAuthoring.TestKit&version=1.0.0
                    
Install as a Cake Tool

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 single IPluginFactory. It throws InvalidOperationException when the DLL has no factory or more than one.
  • LoadInstance<T>(path) creates the single concrete implementation of T, for a Block or Trigger plugin that has no IPluginFactory (pass its IWorkflowBlockFactory or ITriggerPluginFactory).
  • StartAsync(path, config, host, instanceId?, ct) loads the factory, calls Create and StartAsync, and returns the running IReevePlugin.
  • Disposing the harness stops and disposes every plugin StartAsync created, 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, DeviceEventSink and InMemoryIssueRegistry are the recorders behind AuditSink, DeviceEvents and IssueRegistry.
  • Cache is a real memory cache, and DataProtector returns its input unchanged.
  • Gated capabilities are absent, as on a host that granted none. Grant one with With<T>(impl), naming the capability interface as T, for example With<IHttpEgress>(egress). With refuses a class as T.
  • GrantedPermissions is empty and GrantedDeviceTypes is AllTypes until you set them with WithGrantedPermissions(...) and WithGrantedDeviceTypes(...).
  • InMemoryObjectStorage is an in-memory IObjectStorage. To let the plugin use it, grant an IObjectStorageAccess whose Storage returns it. It does not encrypt or enforce size limits.
  • FakePluginHostServices.InMemoryDeviceMetadata is an in-memory IPluginDeviceMetadata. Return it from the DeviceMetadata of the IDeviceReadAccess you 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 validate for 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

Licence

MIT, see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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