TDW.Marv.Testing
0.9.1
dotnet add package TDW.Marv.Testing --version 0.9.1
NuGet\Install-Package TDW.Marv.Testing -Version 0.9.1
<PackageReference Include="TDW.Marv.Testing" Version="0.9.1" />
<PackageVersion Include="TDW.Marv.Testing" Version="0.9.1" />
<PackageReference Include="TDW.Marv.Testing" />
paket add TDW.Marv.Testing --version 0.9.1
#r "nuget: TDW.Marv.Testing, 0.9.1"
#:package TDW.Marv.Testing@0.9.1
#addin nuget:?package=TDW.Marv.Testing&version=0.9.1
#tool nuget:?package=TDW.Marv.Testing&version=0.9.1
TDW.Marv.Testing
Test helpers for Marv IRC bot plugins. Provides builders for handler contexts, mock factories, and a plugin test harness.
Who is this for?
This package is for plugin authors writing unit tests for their Marv plugins. It pairs with TDW.Marv.Core.
Quick start
Add this package alongside your preferred test framework (xUnit, NUnit, etc.) and NSubstitute (included as a dependency).
using Marv.Testing;
using NSubstitute;
using Xunit;
public class HelloPluginTests
{
[Fact]
public async Task Hello_RepliesWithGreeting()
{
var harness = PluginTestHarness<HelloPlugin>.Create();
await harness.LoadAsync();
var ctx = CommandContextBuilder.Create("hello")
.InChannel("#test").From("alice").Build();
await harness.HandleCommandAsync(ctx);
await harness.Bot.Received().SendMessageAsync(
"#test", Arg.Is<string>(s => s.Contains("alice")), Arg.Any<CancellationToken>());
}
}
Context builders
Reduce test setup to 2-3 lines with fluent builders:
// Command context
var ctx = CommandContextBuilder.Create("greet", "world")
.InChannel("#test").From("alice").Build();
// Regex match context
var ctx = RegexMatchContextBuilder.Create(@"hello (\w+)", "hello world")
.InChannel("#test").From("alice").Build();
// Typed events
var evt = EventBuilder<MessageEvent>.Create(raw => new MessageEvent
{
Sender = MockUser.Create("alice"),
Text = "hello",
RawMessage = raw
}).Build();
Mock factories
| Factory | Description |
|---|---|
MockBot.Create(nick?, prefix?) |
NSubstitute mock of IBot |
MockUser.Create(nick, account?) |
Mock IUser |
MockChannel.Create(name) |
Mock IChannel |
DummyIrcMessage.Privmsg / .Notice / .Empty |
Pre-built IRC messages |
DummyIrcMessage.PrivmsgFrom(nick, target, text) |
Custom PRIVMSG |
Plugin test harness
PluginTestHarness<T> wires up DI with mocked dependencies:
var harness = PluginTestHarness<MyPlugin>.Create(
configureServices: services =>
{
services.AddSingleton(Options.Create(new MyConfig { ... }));
});
await harness.LoadAsync();
// Access the plugin and mock bot
harness.Plugin; // MyPlugin instance
harness.Bot; // IBot mock (use .Received() assertions)
Documentation
Full API reference: Plugin API docs
| 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.0)
- Microsoft.Extensions.Logging (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- NSubstitute (>= 5.3.0)
- TDW.Marv.Core (>= 0.9.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.