Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any tools to populate class properties with random data? [closed]

Tags:

c#

random

class

What I'd like to do is create a class with some attributes on different properties, pass that class to another that will set the properties with appropriate random data... here in pseudo code:

public class Customer
{
   [Attribute("FirstName")]
   private string CustomerFirstName;
   public {get;set} //etc

   [Attribute("LastName")]
   private string CustomerLastName;
   public {get;set;} //etc

   [Attribute("DateTime")]
   private DateTime CustomerSignUpDate;
   public DateTime {get;set;} //yadda

   [Attribute("Phone")]
   private string CustomerPhone;
   public string {get;set;} //yadda
}

And then do like this

IList<Customer> CustomerList=ClassFillerOutClass(new Customer(),5);

And the result would be a List of 5 Customers that have appropriate 'random' data in their properties.

If this doesn't exist...I guess I could start a project myself to do...I just don't want to reinvent the wheel if it's not necessary.

EDIT: I forgot a piece. I'm looking to use this as a test tool. So in the example above I could quickly create a list of 5 customers with random but appropriate values. And then say pass that to my persistence method, and have something I can check against. I'm trying to avoid manually creating a populated object everytime for my TDD purposes.

EDIT 2: Ok so I started rolling my own...I'll post it on Codeplex this weekend and link it here...I clearly won't be done but it'll be a start if anyone else wants to work on it.

like image 331
Webjedi Avatar asked Sep 11 '09 21:09

Webjedi


3 Answers

I tried AutoFixture (http://autofixture.codeplex.com/) and it worked well for me. I was able to generate an object with a deep hierarchy of children in one line of code.

like image 68
Maxim Eliseev Avatar answered Nov 09 '22 23:11

Maxim Eliseev


Ok...so I never found one....so I decided to start my own. Check out: Object Hydrator.

The project is presently a quick spike...but I think it has potential...let me know if you have ideas how to make it better.

like image 41
Webjedi Avatar answered Nov 10 '22 00:11

Webjedi


Nowadays you have also NBuilder ( nbuilder.org ) that does the same.

I don't know if both projects are linked.

like image 36
Machado Avatar answered Nov 10 '22 00:11

Machado