A library to monitor your messages and check they conform to your specifications. Can be run as part of a test suite, or as a standalone service.
This has a dependency on the Newtonsoft.Json.Schema library - which requires a license if you are making over 1000 validations per hour.
See the readme at the Overseer.ServiceConsole project page. This project provides both a windows service and a windows console application.
When running as a unit test, there are two styles: post-test, and post-suite. Not all test runners can do post-suite (such as XUnit).
Under XUnit, this just involves creating the monitor in the test constructor and then validating the messages in the test Dispose method.
public class Tests : IDisposable
{
private readonly InMemoryMessageReader _queue;
private readonly QueueMonitor _monitor;
private readonly InMemoryValidationOutput _output;
public Tests()
{
var source = new ResourceValidatorSource(GetType().Assembly, "DomainTests.{messageType}.json");
_queue = new InMemoryMessageReader();
_output = new InMemoryValidationOutput();
_monitor = new QueueMonitor(_queue, new DirectMessageConverter(), new MessageValidator(source), _output);
_monitor.Start();
}
[Fact]
public void When_publishing_a_valid_message()
{
PushMessage(new CandidateCreated
{
ID = 12345,
Name = "Andy Dote",
Email = "AndyDote@example.com"
});
}
[Fact]
public void When_publishing_an_invalid_message()
{
PushMessage(new CandidateCreated
{
ID = 9876,
});
}
private void PushMessage(object domainEvent)
{
_queue.Push(new Message
{
Type = "CandidateCreated",
Body = JsonConvert.SerializeObject(domainEvent)
});
}
public void Dispose()
{
_monitor.Stop();
foreach (var result in _output.Results)
{
result.Status.ShouldBe(Status.Pass);
}
}
}