My favorites | Sign in
Project Logo
                
Search
for
Updated Jun 11, 2009 by jimbobdog
Labels: Featured
DataWangExamples  
Demonstrates how to create lists of random data using the DataWang API.

Examples - HowTo

This page gives examples of how you use DataWang

Create a list of random furniture

1. Create your entity. Here is an entity that represents a piece of furniture. Notice the DataWangType attribute over the Name and Colour properties. These tell DataWang the category of data to generate for this property.

    public class FurnitureItem
    {
        [DataWangType(Category = "furniture")]
        public string Name { get; set; }

        [DataWangType(Category = "colours")]
        public string Colour { get; set; }
        
        public string NonWangProperty { get; set; }
    }

2. Call DataWang! We set up custom category providers for the furniture items and the colours based on the GoogleSetDataProvider() and we want 10 Furniture instances to be returned in our list. Notice the first parameter to each of the GoogleSetDataProvider objects matches the category name we applied to the entity properties. The remaining parameters are the "seed items" that we will send to Google Sets to help it generate our random data.

var result = DataWang.ThatsDataWang<FurnitureItem>(10, 
     new PreloadedContainer(
         new GoogleSetDataProvider("furniture", 
             "chair", "plate", "table", "sofa", "curtains"),
         new GoogleSetDataProvider("colours", 
             "red", "blue","black", "orange", "pink")));

3. Display results.

result.ForEach(item => 
   Trace.WriteLine(string.Format("{0}, colour {1}", item.Name, item.Colour)));

The DbgView trace output is (formatted),

NameColour
chairred
tableblack
sofaorange
cabinetblue
deskwhite
bedbrown
benchgreen
bar%20stoolpink
hutchyellow
workstationgray

Just get a list of stuff

1. Providers return a List of string so you can invoke them directly to access this data.

var result = new GoogleSetDataProvider("furniture", 
             "chair", "plate", "table", "sofa", "curtains").Generate(
                 new MockDataSetRequest(10));

or

var result = new EmailDataProvider().Generate(
                 new MockDataSetRequest(200));

Comment by liuyh...@yahoo.com.cn, Aug 18, 2009

id


Sign in to add a comment
Hosted by Google Code