nickdodd79 / AutoBogus

A C# library complementing the Bogus generator by adding auto creation and population capabilities.
MIT License
431 stars 50 forks source link

Sample using AutoBogus.Moq #44

Closed JerryNixon closed 3 years ago

JerryNixon commented 3 years ago

Hey, just looking around for a sample using AutoBogus.Moq? Just need to get started.

nickdodd79 commented 3 years ago

Hey @JerryNixon

You can use Moq to create mock instances of dependency types. This is achieved by using the configuration handlers (at the global, faker or generate level) to register the Moq binder.

// Global
AutoFaker.Configure(builder =>
{
    builder.WithBinder<MoqBinder>();
});

// Faker 
var faker = AutoFaker.Create(builder =>
{
    builder.WithBinder<MoqBinder>();
});

// Generate
var person = AutoFaker.Generate<Person>(builder =>
{
    builder.WithBinder<MoqBinder>();
});

Hope that helps.

Nick.