How to use AutoFixture to build with customized properties while keeping type customizations?

后端 未结 3 1744
深忆病人
深忆病人 2021-02-13 00:19

I am trying to use autofixture to create an object but there are certain properties that I want to always be defaulted (while the rest could be auto generated). However, wheneve

3条回答
  •  情深已故
    2021-02-13 00:29

    As noted by the accepted answer Customizations will override each other, so you would have to write a customization for every combination of properties you'd want to use.

    I wrote a library that allows you to compose Customizations so that they don't override each other but rather get merged together. This would allow you to have one Customization for People named Ben and one for Born in 1900, and you can compose them together with the Compose function.

    It doesn't quite address the original question, but it may give you some ideas on how to achieve what you want. The Compose function is accomplished by creating a custom IFixture implementation that handles the customizations.

    https://github.com/LethargicDeveloper/Lift.AutoFixture

    EDIT: I saw "active 4 months ago." I missed the "3 years." Sorry for resurrecting such an old post, but hopefully this will be useful.

提交回复
热议问题