Ejemplo n.º 1
0
 public void ChangeHowPrimitivesAreGenerated()
 {
     // Change the strategy for populating primitives.
     var factory = new GuineaPig.Factory();
     factory.ValueObjects.RegisterFactories(new RandomPrimativeGenerator());
     var book = factory.Create<Book>();
 }
Ejemplo n.º 2
0
 public void FactoryMethodsContainedInAFactoryClass()
 {
     // Register many factory methods by grouping them in a class.
     var factory = new GuineaPig.Factory();
     factory.Entities.RegisterFactories(new EntityFactoryClass());
     var book = factory.Create<Book>();
 }
Ejemplo n.º 3
0
 public void CustomEntity()
 {
     // Define custom entity factory methods when you want more control
     // over the creation or for types that require special construction.
     var factory = new GuineaPig.Factory();
     factory.Entities.RegisterFactoryFunction(
     () => new Customer("Some Required Ctor Param"));
     var customer = factory.Create<Customer>();
 }
Ejemplo n.º 4
0
        public void CustomValueType()
        {
            // Define your own primitive factory methods for things like money,
            // rectangle, etc.
            var factory = new GuineaPig.Factory();
            factory.ValueObjects.RegisterFactoryFunction(
            () => new Money(21, "USD"));

            var book = factory.Create<Book>();
        }
Ejemplo n.º 5
0
 public void CustomEntityUsingFactory()
 {
     // Take an instance of the factory in your factory method and use it
     // to populate primitives
     var factory = new GuineaPig.Factory();
     factory.Entities.RegisterFactoryFunction(
     f => f.Build(new Customer("Some Required Ctor Param"))
         .FillUninitialisedValueObjects()
         .Entity);
     var customer = factory.Create<Customer>();
 }
Ejemplo n.º 6
0
 public void CustomEntityWithFactoryFillSelectProperties()
 {
     // Populate only desired properties, both entity and value types
     var factory = new GuineaPig.Factory();
     factory.Entities.RegisterFactoryFunction(
     f => f.Build(new Book())
         .Fill(b => b.Publisher) // Populate entity using factory
         .Fill(b => b.PublishedOn) // Populate value object using factory
         .Set(b => b.ISBN = "12345678") // Explicitly set property
         .Entity);
     var book = factory.Create<Book>();
 }
Ejemplo n.º 7
0
 public void SimplestUsage()
 {
     // Create entity and auto populates primitive properties
     var factory = new GuineaPig.Factory();
     var book = factory.Create<Book>();
 }
Ejemplo n.º 8
0
 public void CustomiseInstance()
 {
     // Customise the instance using a lambda
     var factory = new GuineaPig.Factory();
     var book = factory.Create<Book>(b => b.Title = "Test Title");
 }