Test Data Generator

I've pushed to github a new project, TestDataGenerator that should help with filling random objects with data. I felt the need for a tool like this when testing various serialization techniques and persistence strategies.

Basically this utility should construct the instance of an object using a public constructor, and fill all it's public, writable properties with random data.

Sample usage:

 1 class Sample
 2 {
 3  private readonly int intValue;
 4  private readonly string stringValue;
 5 
 6  private Sample()
 7  {
 8      this.intValue = -1;
 9      this.stringValue = null;
10      this.StringProp = null;
11      this.DateProp = DateTime.MinValue;
12  }
13 
14  public Sample(int intVal, string stringVal)
15      :this()
16  {
17      this.intValue = intVal;
18      this.stringValue = stringVal;
19  }
20 
21  public int PrivateInt { get { return intValue; } }
22  public string PrivateString { get { return stringValue; } }
23 
24  public string StringProp { get; set; }
25  public DateTime DateProp { get; set; }
26 }
27 
28 [Test]
29 public void Catalog_Can_Create_Using_Consutrctor()
30 {
31  Catalog catalog = new Catalog();
32  object instance = catalog.CreateInstance(typeof(Sample));
33 
34  Assert.IsInstanceOfType(typeof(Sample), instance);
35  Sample sample = instance as Sample;
36 
37  Assert.AreNotEqual(-1, sample.PrivateInt);
38  Assert.IsNotNull(sample.PrivateString);
39  Assert.IsNotNull(sample.StringProp);
40  Assert.AreNotEqual(DateTime.MinValue, sample.DateProp);
41 }

For more samples see unit tests.
I'll try to add more cases ( abstract class, interface implementation discovery ) in the future. You are welcome to submit sample classes, preferably as unit tests.

Comments