nickdodd79 / AutoBogus

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

[Idea] Simple generation of data with some fixed values #63

Closed Ian1971 closed 3 years ago

Ian1971 commented 3 years ago

Some time ago I created a library we use internally which also sits on top of Bogus. It is broadly very similar to AutoBogus, but AutoBogus is better and more comprehensive. In fact we have migrated the internals of the library to AutoBogus recently. One thing though that we have is the ability to generate data via a delimited string, where fields that are in the string use the values from the string, but everything else is auto generated. e.g. The string looks like this

var testData =
    " Name | DateOfBirth \r\n" +
    " X    | 2000-01-01 \r\n" +
    " Y    | 1987-02-03 ";

and is used like this

var people = generator.CreateData(testData );

We find this useful in some unit tests, because the tests can succinctly set up their test data and they only need to set up the values they care about. It is easier to see at a glance the test data.

Anyway, I am mentioning it because I wanted to share it and I wanted to get your opinion on it and where it should live. Should it be a separate nuget package, and if so what should I call it? e.g. it could be used like new AutoFaker<Person>().CreateData();

Thanks Ian

Ian1971 commented 3 years ago

I've created a PR showing how it works https://github.com/nickdodd79/AutoBogus/pull/64

nickdodd79 commented 3 years ago

Hey @Ian1971

Thanks for your contribution. I have just pushed 2.13.0 which includes you template PR 👍

Nick.

Ian1971 commented 3 years ago

@nickdodd79 Just noticed the docs you added are missing the new lines, so it would fail. image

nickdodd79 commented 3 years ago

Hey @Ian1971

Because the string starts with @ it honors the new lines. I also have a test in the playground to check this above worked.

https://github.com/nickdodd79/AutoBogus/blob/8c182f937b65719e7b59bc479546caf3a97fc135/src/AutoBogus.Playground/TemplateFixture.cs#L1-L42

Nick.

Ian1971 commented 3 years ago

Brilliant. I never knew that. That makes our usages tidier.

On Mon, Mar 15, 2021 at 8:31 PM Nick Dodd @.***> wrote:

Hey @Ian1971 https://github.com/Ian1971

Because the string starts with @ it honors the new lines. I also have a test in the playground to check this above worked.

https://github.com/nickdodd79/AutoBogus/blob/8c182f937b65719e7b59bc479546caf3a97fc135/src/AutoBogus.Playground/TemplateFixture.cs#L1-L42

Nick.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nickdodd79/AutoBogus/issues/63#issuecomment-799730618, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACN2SK5PC3AA5Q5J4U27GLTDZVBBANCNFSM4X4LYLCA .