VictorySaber
VictorySaber

Reputation: 3164

NBuilder - creating more Random types e.g. EmailAddress

Right now I am using NBuilder to generate Customers in my mock repository. Unfortunately the only option I have for random strings seems to be .Phrase()

var customers = Builder<Customer>.CreateListOfSize(10)
                               .All()
                               .WithConstructor(() => new Customer(
                r.Int().ToString(),
                r.Phrase(5),
                r.Phrase(15),
                r.Phrase(15), // EmailAddress
                r.Phrase(15),
                r.Phrase(15),
                r.DateTime()
                ))
                .Build();

I would love to be able to generate semi-sensible data, like an email address. Is there a way to customise NBuilder to do this, or should I be piecing together two .Phrase() calls with an @ symbol?

Upvotes: 0

Views: 312

Answers (1)

Andrej Matijevic
Andrej Matijevic

Reputation: 56

You can maybe try use Faker.NET is great library for exactly that thing that you need.

In the link you can read about using the library.

http://www.jerriepelser.com/blog/creating-test-data-with-nbuilder-and-faker

Upvotes: 1

Related Questions