nickdodd79 / AutoBogus

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

Add support for readonly IList properties (Protobuf RepeatedFields). #20

Closed rccampbe closed 5 years ago

rccampbe commented 5 years ago

I wanted to auto-generate test data for gRPC services, but ran into some issues using AutoBogus on the Protocol Buffers generated code:

  1. Protocol Buffers C# generated code contains readonly properties of type RepeatedField for lists of objects.
  2. The RepeatedField class only has a default constructor.

So I modified the AutoBinder to:

  1. Allow populating readonly properties implementing IList using IList.Add to copy items into the default constructed RepeatedField.
  2. Allow Enumerables that can't be populated via construction to be default constructed and populated later.
nickdodd79 commented 4 years ago

Hey @rccampbe,

I liked the implementation you put together and so wanted to extend on it to include populating dictionaries as well as ensure WithSkip() and recursive depths were honored. I therefore had a slight refactor and have pushed v2.7.0.

Can you verify that the implementation still fulfills your needs in terms of your PR objective? I don't know too much about the Protobuf stuff so not sure how to verify it's use case.

Thanks, Nick.

rccampbe commented 4 years ago

@nickdodd79 Thanks for the update. I had a regression and I've got a fix for it. I created issue #22 . I'll submit a new PR for it.