MiniMock

Minimalistic approach to mocking in .NET

View on GitHub

MiniMock

MiniMock offers a minimalistic approach to mocking in .NET with a focus on simplicity and ease of use.

    public interface IBookRepository
    {
        Task<Guid> AddBook(Book book, CancellationToken token);
        int BookCount { get; set; }
        Book this[Guid index] { get; set; }
        event EventHandler<Book> NewBookAdded;
    }

    [Fact]
    [Mock<IBookRepository>]
    public async Task BookCanBeCreated()
    {
        Action<Book> trigger = _ => { };

        var mockRepo = Mock.IBookRepository(config => config
            .AddBook(returns: Guid.NewGuid())
            .BookCount(value: 10)
            .Indexer(values: new Dictionary<Guid, Book>())
            .NewBookAdded(trigger: out trigger));
        
        var sut = new BookModel(mockRepo);
        var actual = await sut.AddBook(new Book());
        
        Assert.Equal("We now have 10 books", actual);
    }

Try it out or continue with Getting started to learn more or read the Mocking guidelines to get a better understanding of when, why and how to mock and when not to.

For more details on specific aspects you can read about Construction, Methods, Properties, Events or Indexers. Or you shift into high gear with Advanced Features, FaQ or Troubleshooting.

If you are more into the ins and outs of MiniMock you can read the Motivation behind MiniMock or the ADRs.