Skip to content
Luke Sigler edited this page Apr 22, 2014 · 7 revisions

Fibbing Without Configuration

var fibbedProduct = Build.NewFibber().Fib(new Product());

Configuring A Class For Fibbing (One Line Configuration)

var fibber = Build.NewFibber().Configure(c => c.ForType<Product>(p => p.UseDefaults()));

Configuring a Class With Custom Generators

var fibber = Build.NewFibber()
    .Configure(c =>
    {
        c.ForType<Product>(p => p.For<string>("This string for all properties of type string")
            .For<bool>(RandGen.Bool) // A randomly selected value
            .For<long>(() => SomeOtherMethod()) // Any other method that returns a value of type long.
            .For<int>((v) => v + 1)); // Modify the existing value
    });

Configuring Multiple Classes For Fibbing

var fibber = Build.NewFibber()
    .Configure(c =>
    {
        c.ForType<Product>(p => p.For<string>(() => Generators.Current.String(10, 48, false))
            .For<bool>(RandGen.Bool)
            .For<int>(RandGen.Int32));
					
        c.ForType<Supplier>(s => s.UseDefaults());
    });

Ensuring Consistent Random Data

 var fibber = Build.NewFibber()
            .Seed(42342342)
            .Configure(c =>
            {
                c.ForType<Product>(p => p.For<string>(RandGen.ShortString)
                            .For<bool>(RandGen.Bool)
                            .For<int>(RandGen.Int));
            });

Setting Max Depth For Classes That Have Properties With Hierarchical Relationships.

 var fibber = Build.NewFibber()
            .MaxDepth(3)
            .Configure(c =>
            {
                c.ForType<Product>(p => p.For<string>(() => Generators.Current.String(10, 48, false))
                    .For<bool>(RandGen.Bool)
                    .For<int>(RandGen.Int32));
					
                c.ForType<Supplier>(s => s.UseDefaults());
    });

Generating Data

var fibber = Build.NewFibber()
    .Configure(c =>
    {
	    c.ForType<Product>(p => p.UseDefaults());
    });
	
var list = new List<Product>();

for (int i = 0; i < 100000; i++)
{
    list.Add(fibber.Fib<Product>(new Product()));
}