Object Generation

Creating a single object

Start the process off by calling Session.Single<T>
  • Session
    • Single<T>: Kicks off the generation process for a single object of type T
      • Impose(x=>x.Property, "Value"): Imposes a value onto a property of the generated object, overwriting any data source provided value. Re-returns the Single<T> object
      • Get(): Creates the object with all property modification applied and returns it

Example:
Create a user and override some properties on that user
            SimpleUser user = mSession.Single<SimpleUser>()
                .Impose(x => x.EmailAddress, "override@override.com")
                .Impose(x=>x.FirstName, "Override")
                .Impose(x=>x.LastName, "Override")
                .Get();

Creating a collection of objects

Start the process off by calling Session.List<T>
  • Session
    • List<T>(int count): Kicks off the generation process for a list of T of size 'count'
      • Impose(x=>x.Property, "Value"): Imposes a value onto the property of every single object, re-returns the List<T> object
      • First(int count): Selects the first 'count' items in the collection
        • Impose(x=>x.Property, "Value"): Imposes value onto the property of every single object in the current selection, re-returns the First object
        • Next(int count): Selects the next 'count' items in the collection, re-returns the First object
        • All(): Returns to the List<T> object
      • Random(int count): Selects a random selection of items from the collection of size 'count'
        • Impose(x=>x.Property, "Value"): Imposes value onto the property of every single object in the current selection, re-returns the Random object
        • Next(int count):: Selects the next 'count' items in the randomised collection, this will not include any previously selected items
        • All(): Returns to the List<T> object
      • Get(): Creates the list of objects with all property modifications applied and returns it

Example
Create a list of users, call the first 5 of them Bob, call the next 5 of them Alice
            mSession.List<SimpleUser>()
                .First(5)
                    .Impose(x => x.FirstName, "Bob")
                .Next(5)
                    .Impose(x => x.FirstName, "Alice")
                .All()
                .Get();

# First Name
0 Bob
1 Bob
2 Bob
3 Bob
4 Bob
5 Alice
6 Alice
7 Alice
8 Alice
9 Alice


Example
Create a list of users, call a 5 randoms Bob, and the other 5 randoms Alice
            mSession.List<SimpleUser>()
                .Random(5)
                    .Impose(x => x.FirstName, "Bob")
                .Next(5)
                    .Impose(x => x.FirstName, "Alice")
                .All()
                .Get();

# First Name
0 Bob
1 Alice
2 Alice
3 Bob
4 Bob
5 Alice
6 Bob
7 Alice
8 Bob
9 Alice


Example
Create a list of users, call a 5 randoms Bob, and the other 5 randoms Alice
Ensure the first 5 have last names of "Blue"
Ensure the last 5 have last names of "Red"
            mSession.List<SimpleUser>()
                .Random(5)
                    .Impose(x => x.FirstName, "Bob")
                .Next(5)
                    .Impose(x => x.FirstName, "Alice")
                .All()
                .First(5)
                    .Impose(x => x.LastName, "Blue")
                .Next(5)
                    .Impose(x => x.FirstName, "Red")
                .All()
                .Get();

# First Name Last Name
0 Bob Blue
1 Alice Blue
2 Alice Blue
3 Bob Blue
4 Bob Blue
5 Alice Red
6 Bob Red
7 Alice Red
8 Bob Red
9 Alice Red

Last edited Apr 8, 2010 at 1:38 AM by robashton, version 3

Comments

PixelSyndicate Jun 10, 2015 at 6:17 PM 
Something that might be helpful in this context is to demonstrate the IntegerIdSource as a DataSource for generating incrementing integers for use in Unique ID's for your Pocos.

x.Include<User>()
.Setup(c => c.UserName).Use<EmailAddressSource>()
.Setup(c => c.FirstName).Use<FirstNameSource>()
.Setup(c => c.LastName).Use<LastNameSource>()
.Setup(c => c.ID).Use<IntegerIdSource>()
.Setup(c => c.Password).Use<RandomStringSource>(5, 9);