bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.81k stars 500 forks source link

Is it possible and ok to "extend" Bogus with our own company classes of data? If so, what classes do we need to focus on extending? #363

Closed dfarrNTST closed 3 years ago

dfarrNTST commented 3 years ago

Hi, we use Bogus for a lot of our test/mock data and would like to use the same pattern in creating fully test/mock data of our own business classes/objects. 1) Is it ok to do this? and if so 2) What classes/features do we need to focus on adding our own classes to extend it? (e.g. Is there an extension guide or some quick guidance you can give for this?)

Thanks!

bchavez commented 3 years ago

Is it ok to do this?

Absolutely. I 100% recommend this. Customize as much as you'd like and make it your own. I've exposed almost all internals of Bogus for this purpose. If you need anything else made public; let me know.

Of course, goes without saying, if you take a dependency on anything internal inside Bogus things could change. However, the internals don't really change that often (if at all).

What classes/features do we need to focus on adding our own classes to extend it? (e.g. Is there an extension guide or some quick guidance you can give for this?)

I just created an ExtendingBogus example that shows how to create a new "data set" from scratch and augmenting existing data sets with C# extension methods. You can take a look here:

https://github.com/bchavez/Bogus/tree/master/Examples/ExtendingBogus

There is technically a third way to extend Bogus by patching the internal BSON database as done here in this unit test, but I don't recommend it unless you really want to use this approach.

Hope that helps! Let me know if you have any other questions, I'll be happy to help. Feel free to carry on the conversation after I close the issue.

Thanks, Brian