public void DefaultBuilder()
        {
            var dgt = plant.Create <DocumentGroupTable>();

            Assert.That(dgt.Name, Is.EqualTo("My docs"));
            Assert.That(dgt.DocumentGroupId, Is.EqualTo(123));
        }
        public void DefaultCreation()
        {
            var customer = plant.Create <Customer>();

            Assert.That(customer.Name, Is.EqualTo("Microsoft"));
            Assert.That(customer.Email, Is.EqualTo("*****@*****.**"));
        }
Ejemplo n.º 3
0
        public void Should_Send_Constructor_Arguments_In_Correct_Order()
        {
            var testPlant = new BasePlant();

            testPlant.DefineConstructionOf <Book>(new { Publisher = "Tor", Author = "Robert Jordan" });
            Assert.AreEqual("Tor", testPlant.Create <Book>().Publisher);
            Assert.AreEqual("Robert Jordan", testPlant.Create <Book>().Author);
        }
Ejemplo n.º 4
0
        public void Variation()
        {
            var house1 = plant.Create <House>();
            var house2 = plant.Create <House>("appartment");

            Assert.That(house1.Color, Is.EqualTo("red"));
            Assert.That(house2.Color, Is.EqualTo("blue"));
        }
Ejemplo n.º 5
0
        public void Is_Event_Created_Called()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf(new House { Color = "blue", SquareFoot = 50 });
            plant.DefinePropertiesOf(new Person { FirstName = "Leo" });

            plant.BluePrintCreated += plant_BluePrintCreated;
            plant.Create<House>();
            plant.Create<Person>();
        }
Ejemplo n.º 6
0
        public void Should_increment_values_in_a_sequence_with_property_construction()
        {
            var testPlant = new BasePlant();

            testPlant.DefinePropertiesOf <Person>(new
            {
                FirstName = new Sequence <string>((i) => "FirstName" + i)
            });
            Assert.AreEqual("FirstName0", testPlant.Create <Person>().FirstName);
            Assert.AreEqual("FirstName1", testPlant.Create <Person>().FirstName);
        }
Ejemplo n.º 7
0
        public void Should_increment_values_in_a_sequence_with_ctor_construction()
        {
            var testPlant = new BasePlant();

            testPlant.DefineConstructionOf <House>(new
            {
                Color      = new Sequence <string>((i) => "Color" + i),
                SquareFoot = 10
            });
            Assert.AreEqual("Color0", testPlant.Create <House>().Color);
            Assert.AreEqual("Color1", testPlant.Create <House>().Color);
        }
Ejemplo n.º 8
0
        public void Should_Create_Variation_Of_Specified_Type()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new { FirstName = "" });
            plant.DefineVariationOf <Person>("My", new { FirstName = "My" });
            plant.DefineVariationOf <Person>("Her", new { FirstName = "Her" });

            Assert.IsInstanceOf(typeof(Person), plant.Create <Person>());
            Assert.IsInstanceOf(typeof(Person), plant.Create <Person>("My"));
            Assert.IsInstanceOf(typeof(Person), plant.Create <Person>("Her"));
        }
Ejemplo n.º 9
0
        public void Can_Create_Two_Different_House()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf(new House { Color = "blue", SquareFoot = 50 });
            plant.DefinePropertiesOf(new Person { FirstName = "Leo" });

            var house = plant.Create<House>();
            var redHouse = plant.Create(new House { Color = "red" });

            Assert.AreNotEqual(house, redHouse);
            Assert.AreNotEqual(house.Color, redHouse.Color);
        }
Ejemplo n.º 10
0
        public void Should_Create_Variation_With_Extension()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <House>(new House {
                Color = "blue"
            }, OnPropertyPopulation);
            plant.DefineVariationOf <House>("My", new House {
                Color = "My"
            }, OnPropertyPopulationVariatoion);

            Assert.AreEqual(plant.Create <House>().Persons.First().FirstName, "Pablo");
            Assert.AreEqual(plant.Create <House>("My").Persons.First().FirstName, "Pedro");
        }
Ejemplo n.º 11
0
        public void Should_Lazily_Evaluate_Delegate_Properties()
        {
            var    plant          = new BasePlant();
            string lazyMiddleName = null;

            plant.DefinePropertiesOf <Person>(new
            {
                MiddleName = new LazyProperty <string>(() => lazyMiddleName)
            });

            Assert.AreEqual(null, plant.Create <Person>().MiddleName);
            lazyMiddleName = "Johnny";
            Assert.AreEqual("Johnny", plant.Create <Person>().MiddleName);
        }
Ejemplo n.º 12
0
        public void SimpleRelationship()
        {
            var person = plant.Create <Person>();

            Assert.That(person.Name, Is.EqualTo("my name"));
            Assert.That(person.House.Color, Is.EqualTo("red"));
        }
Ejemplo n.º 13
0
        public void Should_Create_Instance_With_Requested_Properties()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new { FirstName = "" });
            Assert.AreEqual("James", plant.Create <Person>(new { FirstName = "James" }).FirstName);
        }
Ejemplo n.º 14
0
        public void Should_Set_User_Properties_That_Are_Not_Defaulted()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new { FirstName = "Barbara" });
            Assert.AreEqual("Brechtel", plant.Create <Person>(new { LastName = "Brechtel" }).LastName);
        }
Ejemplo n.º 15
0
        public void Should_Use_Default_Instance_Values()
        {
            var testPlant = new BasePlant();

            testPlant.DefinePropertiesOf <Person>(new { FirstName = "Barbara" });
            Assert.AreEqual("Barbara", testPlant.Create <Person>().FirstName);
        }
Ejemplo n.º 16
0
        public void Is_Event_Created_Called()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf(new House {
                Color = "blue", SquareFoot = 50
            });
            plant.DefinePropertiesOf(new Person {
                FirstName = "Leo"
            });

            plant.BluePrintCreated += plant_BluePrintCreated;
            plant.Create <House>();
            plant.Create <Person>();
            Assert.AreEqual(eventcounter, 2);
        }
Ejemplo n.º 17
0
        public void Should_Create_Objects_Via_Constructor()
        {
            var testPlant = new BasePlant();

            testPlant.DefineConstructionOf <Car>(new { Make = "Toyota" });
            Assert.AreEqual("Toyota", testPlant.Create <Car>().Make);
        }
Ejemplo n.º 18
0
        public void Should_Only_Set_Properties_Once()
        {
            var testPlant = new BasePlant();

            testPlant.DefinePropertiesOf <WriteOnceMemoryModule>(new { Value = 5000 });
            Assert.AreEqual(10, testPlant.Create <WriteOnceMemoryModule>(new { Value = 10 }).Value);
        }
Ejemplo n.º 19
0
        public void Should_Create_Instance_Of_Specified_Type()
        {
            var plant = new BasePlant();
              plant.DefinePropertiesOf<Person>(new { FirstName = "" });

              Assert.IsInstanceOf(typeof(Person), plant.Create<Person>());
        }
Ejemplo n.º 20
0
        public void Should_Throw_PropertyNotFound_Exception_When_Given_Invalid_Property()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new { Foo = "" });
            plant.Create <Person>();
        }
Ejemplo n.º 21
0
        public void Should_Create_Instance_With_Null_Value()
        {
            var testPlant = new BasePlant();

            testPlant.DefinePropertiesOf <Person>(new { FirstName = "Barbara", LastName = (string)null });
            Assert.IsNull(testPlant.Create <Person>().LastName);
        }
Ejemplo n.º 22
0
 public void Should_Call_AfterBuildCallback_After_Properties_Populated()
 {
     var testPlant = new BasePlant();
     testPlant.DefinePropertiesOf<Person>(new {FirstName = "Angus", LastName = "MacGyver"},
     (p) => p.FullName = p.FirstName + p.LastName);
     var builtPerson = testPlant.Create<Person>();
     Assert.AreEqual(builtPerson.FullName, "AngusMacGyver");
 }
Ejemplo n.º 23
0
        public void Is_Event_Created_Called()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf(new House()
            {
                Color = "blue", SquareFoot = 50
            });
            plant.DefinePropertiesOf(new Person()
            {
                FirstName = "Leo"
            });

            plant.BluePrintCreated += new BluePrintCreatedEventHandler(plant_BluePrintCreated);
            var house  = plant.Create <House>();
            var person = plant.Create <Person>();
        }
Ejemplo n.º 24
0
        public void Should_Override_Default_Constructor_Arguments()
        {
            var testPlant = new BasePlant();

            testPlant.DefineConstructionOf <House>(new { Color = "Red", SquareFoot = 3000 });

            Assert.AreEqual("Blue", testPlant.Create <House>(new { Color = "Blue" }).Color);
        }
Ejemplo n.º 25
0
        public void Should_Call_AfterBuildCallback_AfterConstructor_Population()
        {
            var testPlant = new BasePlant();
            testPlant.DefineConstructionOf<House>(new { Color = "Red", SquareFoot = 3000 },
            (h) => h.Summary = h.Color + h.SquareFoot);

            Assert.AreEqual("Blue3000", testPlant.Create<House>(new { Color = "Blue" }).Summary);
        }
Ejemplo n.º 26
0
        public void Should_Create_Instance_Of_Specified_Type()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new { FirstName = "" });

            Assert.IsInstanceOf(typeof(Person), plant.Create <Person>());
        }
Ejemplo n.º 27
0
        public void Should_Call_AfterBuildCallback_AfterConstructor_Population()
        {
            var testPlant = new BasePlant();

            testPlant.DefineConstructionOf <House>(new { Color = "Red", SquareFoot = 3000 },
                                                   (h) => h.Summary = h.Color + h.SquareFoot);

            Assert.AreEqual("Blue3000", testPlant.Create <House>(new { Color = "Blue" }).Summary);
        }
Ejemplo n.º 28
0
        public void Should_Not_Prefill_Relation_Defined()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf(new House {
                Color = "blue", SquareFoot = 50
            });
            plant.DefinePropertiesOf(new Person {
                FirstName = "Leo", HouseWhereILive = new House {
                    Color = "Violet"
                }
            });

            var house  = plant.Create <House>();
            var person = plant.Create <Person>();

            Assert.AreEqual("Violet", person.HouseWhereILive.Color);
        }
Ejemplo n.º 29
0
        public void Should_Create_Instance_With_Default_Properties_Specified_By_Instance()
        {
            var testPlant = new BasePlant();

            testPlant.DefinePropertiesOf(new Person {
                FirstName = "James"
            });
            Assert.AreEqual("James", testPlant.Create <Person>().FirstName);
        }
Ejemplo n.º 30
0
        public void Should_Call_AfterBuildCallback_After_Properties_Populated()
        {
            var testPlant = new BasePlant();

            testPlant.DefinePropertiesOf <Person>(new { FirstName = "Angus", LastName = "MacGyver" },
                                                  (p) => p.FullName = p.FirstName + p.LastName);
            var builtPerson = testPlant.Create <Person>();

            Assert.AreEqual(builtPerson.FullName, "AngusMacGyver");
        }
Ejemplo n.º 31
0
        public void Should_Prefill_Relation()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf(new House {
                Color = "blue", SquareFoot = 50
            });
            plant.DefinePropertiesOf(new Person {
                FirstName = "Leo"
            });

            var house  = plant.Create <House>();
            var person = plant.Create <Person>();

            Assert.IsNotNull(person.HouseWhereILive);
            Assert.AreEqual(house, person.HouseWhereILive);
            Assert.AreEqual(house.Color, person.HouseWhereILive.Color);
            Assert.AreEqual(house.SquareFoot, person.HouseWhereILive.SquareFoot);
        }
Ejemplo n.º 32
0
        public void Can_Create_Two_Different_House()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf(new House {
                Color = "blue", SquareFoot = 50
            });
            plant.DefinePropertiesOf(new Person {
                FirstName = "Leo"
            });

            var house    = plant.Create <House>();
            var redHouse = plant.Create(new House {
                Color = "red"
            });

            Assert.AreNotEqual(house, redHouse);
            Assert.AreNotEqual(house.Color, redHouse.Color);
        }
Ejemplo n.º 33
0
        public void Should_Create_Variation_Of_Specified_Type_With_Correct_Data()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new { FirstName = "" });
            plant.DefineVariationOf <Person>("My", new { FirstName = "My" });

            var person = plant.Create <Person>("My");

            Assert.AreEqual("My", person.FirstName);
        }
Ejemplo n.º 34
0
        public void Should_Throw_LazyPropertyHasWrongTypeException_When_Lazy_Property_Definition_Returns_Wrong_Type()
        {
            var plant = new BasePlant();

            plant.DefinePropertiesOf <Person>(new
            {
                MiddleName = new LazyProperty <int>(() => 5)
            });

            plant.Create <Person>();
        }
Ejemplo n.º 35
0
        public void Create_WhenVariationHasLazyPropertyOverwrittenByUser_DoesNotInvokeVariationLazyProperty()
        {
            var plant = new BasePlant();
            const string variationName = "Self";
            var wasVariantLazyPropertyAssigned = false;
            plant.DefinePropertiesOf<Person>(new { FirstName = "default" });
            plant.DefineVariationOf<Person>(variationName, new
            {
                FirstName = new LazyProperty<string>(() =>
                {
                    wasVariantLazyPropertyAssigned = true;
                    return "overwritten";
                })
            });

            plant.Create<Person>(new { FirstName = "UserDefined" }, variationName);

            Assert.IsFalse(wasVariantLazyPropertyAssigned);
        }
Ejemplo n.º 36
0
 public void Should_Send_Constructor_Arguments_In_Correct_Order()
 {
     var testPlant = new BasePlant();
     testPlant.DefineConstructionOf<Book>(new { Publisher = "Tor", Author = "Robert Jordan" });
     Assert.AreEqual("Tor", testPlant.Create<Book>().Publisher);
     Assert.AreEqual("Robert Jordan", testPlant.Create<Book>().Author);
 }
Ejemplo n.º 37
0
        public void Should_Prefill_Relation()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf(new House { Color = "blue", SquareFoot = 50 });
            plant.DefinePropertiesOf(new Person { FirstName = "Leo" });

            var house = plant.Create<House>();
            var person = plant.Create<Person>();

            Assert.IsNotNull(person.HouseWhereILive);
            Assert.AreEqual(house, person.HouseWhereILive);
            Assert.AreEqual(house.Color, person.HouseWhereILive.Color);
            Assert.AreEqual(house.SquareFoot, person.HouseWhereILive.SquareFoot);
        }
Ejemplo n.º 38
0
        public void Should_Override_Default_Constructor_Arguments()
        {
            var testPlant = new BasePlant();
            testPlant.DefineConstructionOf<House>(new { Color = "Red", SquareFoot = 3000 });

            Assert.AreEqual("Blue", testPlant.Create<House>(new { Color = "Blue" }).Color);
        }
Ejemplo n.º 39
0
 public void Should_Create_Instance_With_Requested_Properties_Specified_By_Instance()
 {
     var testPlant = new BasePlant();
     testPlant.DefinePropertiesOf(new Person { FirstName = "David" });
     Assert.AreEqual("James", testPlant.Create(new Person { FirstName = "James" }).FirstName);
 }
Ejemplo n.º 40
0
 public void Should_Throw_PropertyNotFound_Exception_When_Given_Invalid_Property()
 {
     var plant = new BasePlant();
     plant.DefinePropertiesOf<Person>(new { Foo = "" });
     plant.Create<Person>();
 }
Ejemplo n.º 41
0
 public void Should_increment_values_in_a_sequence_with_property_construction()
 {
     var testPlant = new BasePlant();
     testPlant.DefinePropertiesOf<Person>(new
     {
         FirstName = new Sequence<string>(i => "FirstName" + i)
     });
     Assert.AreEqual("FirstName0", testPlant.Create<Person>().FirstName);
     Assert.AreEqual("FirstName1", testPlant.Create<Person>().FirstName);
 }
Ejemplo n.º 42
0
 public void Should_increment_values_in_a_sequence_with_ctor_construction()
 {
     var testPlant = new BasePlant();
     testPlant.DefineConstructionOf<House>(new
     {
         Color = new Sequence<string>(i => "Color" + i),
         SquareFoot = 10
     });
     Assert.AreEqual("Color0", testPlant.Create<House>().Color);
     Assert.AreEqual("Color1", testPlant.Create<House>().Color);
 }
Ejemplo n.º 43
0
        public void Should_Create_Variation_With_Extension()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf(new House { Color = "blue" }, OnPropertyPopulation);
            plant.DefineVariationOf("My", new House { Color = "My" }, OnPropertyPopulationVariatoion);

            Assert.AreEqual(plant.Create<House>().Persons.First().FirstName, "Pablo");
            Assert.AreEqual(plant.Create<House>("My").Persons.First().FirstName, "Pedro");
        }
Ejemplo n.º 44
0
        public void Should_Create_Variation_Of_Specified_Type_With_Correct_Data()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf<Person>(new { FirstName = "" });
            plant.DefineVariationOf<Person>("My", new { FirstName = "My" });

            var person = plant.Create<Person>("My");
            Assert.AreEqual("My", person.FirstName);
        }
Ejemplo n.º 45
0
        public void Should_Create_Variation_Of_Specified_Type()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf<Person>(new { FirstName = "" });
            plant.DefineVariationOf<Person>("My", new { FirstName = "My" });
            plant.DefineVariationOf<Person>("Her", new { FirstName = "Her" });

            Assert.IsInstanceOf(typeof(Person), plant.Create<Person>());
            Assert.IsInstanceOf(typeof(Person), plant.Create<Person>("My"));
            Assert.IsInstanceOf(typeof(Person), plant.Create<Person>("Her"));
        }
Ejemplo n.º 46
0
 public void Should_Create_Instance_With_Null_Value()
 {
     var testPlant = new BasePlant();
     testPlant.DefinePropertiesOf<Person>(new { FirstName = "Barbara", LastName = (string)null });
     Assert.IsNull(testPlant.Create<Person>().LastName);
 }
Ejemplo n.º 47
0
 public void Should_Create_Objects_Via_Constructor()
 {
     var testPlant = new BasePlant();
     testPlant.DefineConstructionOf<Car>(new { Make = "Toyota" });
     Assert.AreEqual("Toyota", testPlant.Create<Car>().Make);
 }
Ejemplo n.º 48
0
 public void Should_Set_User_Properties_That_Are_Not_Defaulted()
 {
     var plant = new BasePlant();
     plant.DefinePropertiesOf<Person>(new { FirstName = "Barbara" });
     Assert.AreEqual("Brechtel", plant.Create<Person>(new { LastName = "Brechtel" }).LastName);
 }
Ejemplo n.º 49
0
        public void Should_Throw_LazyPropertyHasWrongTypeException_When_Lazy_Property_Definition_Returns_Wrong_Type()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf<Person>(new
            {
                MiddleName = new LazyProperty<int>(() => 5)
            });

            plant.Create<Person>();
        }
Ejemplo n.º 50
0
        public void Should_Lazily_Evaluate_Delegate_Properties()
        {
            var plant = new BasePlant();
            string lazyMiddleName = null;
            plant.DefinePropertiesOf<Person>(new
            {
                // ReSharper disable once AccessToModifiedClosure
                MiddleName = new LazyProperty<string>(() => lazyMiddleName)
            });

            Assert.AreEqual(null, plant.Create<Person>().MiddleName);
            lazyMiddleName = "Johnny";
            Assert.AreEqual("Johnny", plant.Create<Person>().MiddleName);
        }
Ejemplo n.º 51
0
 public void Should_Use_Default_Instance_Values()
 {
     var testPlant = new BasePlant();
     testPlant.DefinePropertiesOf<Person>(new { FirstName = "Barbara" });
     Assert.AreEqual("Barbara", testPlant.Create<Person>().FirstName);
 }
Ejemplo n.º 52
0
 public void Should_Load_Blueprints_From_Assembly()
 {
     var plant = new BasePlant().WithBlueprintsFromAssemblyOf<TestBlueprint>();
     Assert.AreEqual("Elaine", plant.Create<Person>().MiddleName);
 }
Ejemplo n.º 53
0
        public void Should_Not_Prefill_Relation_Defined()
        {
            var plant = new BasePlant();
            plant.DefinePropertiesOf(new House { Color = "blue", SquareFoot = 50 });
            plant.DefinePropertiesOf(new Person { FirstName = "Leo", HouseWhereILive = new House { Color = "Violet" } });

            plant.Create<House>();
            var person = plant.Create<Person>();

            Assert.AreEqual("Violet", person.HouseWhereILive.Color);
        }
Ejemplo n.º 54
0
 public void Should_Only_Set_Properties_Once()
 {
     var testPlant = new BasePlant();
     testPlant.DefinePropertiesOf<WriteOnceMemoryModule>(new { Value = 5000 });
     Assert.AreEqual(10, testPlant.Create<WriteOnceMemoryModule>(new { Value = 10 }).Value);
 }
 public void StaticId()
 {
     Assert.That(plant.Create <Customer>().Name, Is.EqualTo("Microsoft"));
     Assert.That(plant.Create <Customer>().Name, Is.EqualTo("Microsoft"));
     Assert.That(plant.Create <Customer>().Name, Is.EqualTo("Microsoft"));
 }
Ejemplo n.º 56
0
 public void Should_Create_Instance_With_Requested_Properties()
 {
     var plant = new BasePlant();
     plant.DefinePropertiesOf<Person>(new { FirstName = "" });
     Assert.AreEqual("James", plant.Create<Person>(new { FirstName = "James" }).FirstName);
 }