Skip to content

Automatically Moq dependencies encountered through Splat's Locator.

License

Notifications You must be signed in to change notification settings

ryanwersal/AutoSplat

Repository files navigation

AutoSplat

Build Status NuGet

The objective is to do for Splat what projects like Autofac.Extras.Moq provide for Autofac. In short, provide primitive mocks for types encountered using Splat's Locator to simplify mocking scenarios where you are not verifying all dependencies but still require them to, at least, be non-null.

Usage

What It Does

AutoSplat provides the AutoMockContext class to handle swapping the Locator dependency resolver for you. It will put the original resolver back in place once the context disposes. When inside the context, accessing services will return a mocked instance using Moq.

Creating Mocks

If verifying mocked methods and such is required you will need to create the Mock yourself (within the context with the Locator dependency resolver swapped) and invoke the resolver's Register method with the mock:

var example = new Mock<IExample>();
example.Setup(m => m.DoFoo()).Returns("foo");
Locator.CurrentMutable.Register(example.Object, typeof(IExample));

About

Automatically Moq dependencies encountered through Splat's Locator.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages