You can customize the ObjectRandomizer class, which takes an array of objects, uses reflection to examine the object for private members, and then uses reflection to set a random value for that member. This only works if you don't care what the random data looks like for every object.
Alternatively, you can create a set of classes for each data object that generates random data for them. This may work if you do not want to include random generation methods in actual assemblies. For example, if you have a Person class, you can have a PersonRandomizer class in a test assembly. In your test class (or in the Randomizer class), you can use reflection to find the PersonRandomizer type, and if it exists, call PersonRandomizer.Randomize(Person p) .
If you come with the yahya clause, I suggest creating an IRandomizable interface for objects that support randomization or label them with a new Randomizable attribute that you can detect at runtime.
source share