MiniMock

Minimalistic approach to mocking in .NET

View on GitHub

Events

TL;DR

public interface IVersionLibrary
{
    event EventHandler<Version> NewVersionAdded;
}

Action<Version> triggerNewVersionAdded = _ => { };

var versionLibrary = Mock.IVersionLibrary(config => config
        .NewVersionAdded(raise: new Version(2, 0, 0, 0)) // Raises the event right away
        .NewVersionAdded(trigger: out triggerNewVersionAdded) // Provides a trigger for when a new version is added
);

// Inject into system under test

triggerNewVersionAdded(new Version(2, 0, 0, 0));

Alternative to creating a action for triggering the is to use the out parameter for configuration instead.

var versionLibrary = Mock.IVersionLibrary(out var config);

// Inject into system under test

config.NewVersionAdded(raise: new Version(2, 0, 0, 0));

Please note