public void globally_set_behaviors_should_be_overridable()
    {
        var instance = MagicFactory.For <ClassA>()
                       .WithBehavior(new DoNotFillBehavior())
                       .Build();

        instance.DateTimeProperty.Should().Be(default);
Exemplo n.º 2
0
        public void Should_create_instance_with_default_values()
        {
            var factory = MagicFactory.For <Person>();

            var person = factory.Build();

            person.FirstName.Should().BeNull();
            person.LastName.Should().BeNull();
            person.Age.Should().Be(0);
        }
Exemplo n.º 3
0
        public static IEnumerable <object[]> FactoriesWithNullableFillingDisabled()
        {
            var customizedBehavior = new FillWithEmptyValuesBehavior(options => options.FillNullables = false);

            return(new List <object[]>
            {
                new object[] { new CustomerFactory(customizedBehavior) },
                new object[] { MagicFactory.For <Customer>().WithBehavior(customizedBehavior) }
            });
        }
Exemplo n.º 4
0
        public static IEnumerable <object[]> FactoriesWithDefaultBehavior()
        {
            var customizedBehavior = new FillWithEmptyValuesBehavior();

            return(new List <object[]>
            {
                new object[] { new CustomerFactory(customizedBehavior) },
                new object[] { MagicFactory.For <Customer>().WithBehavior(customizedBehavior) }
            });
        }
            public static IEnumerable <object[]> FactoriesWithDefaultBehavior()
            {
                var behavior = new FillWithSequentialValuesBehavior();

                return(new List <object[]>
                {
                    new object[] { new CustomerFactory(behavior) },
                    new object[] { MagicFactory.For <Customer>().WithBehavior(behavior) }
                });
            }
Exemplo n.º 6
0
        public void Should_produce_an_instance_using_custom_constructor()
        {
            var product = MagicFactory.For <Product>()
                          .UsingConstructor(() => new Product("MAG-7", "Shotgun"))
                          .With(x => x.Description = "South Africa, 1995")
                          .Build();

            product.Name.Should().Be("MAG-7");
            product.Category.Should().Be("Shotgun");
            product.Description.Should().Be("South Africa, 1995");
        }
    public void globally_set_behaviors_should_be_used_in_new_factories()
    {
        var instances = MagicFactory.For <ClassA>().Many(2).Build().ToArray();

        instances[0].DateTimeProperty.Should().Be(2.September(2020));
        instances[0].NullableDateTimeProperty.Should().BeNull("FillNullables option is set to false");
        instances[0].B.Should().BeNull("Recursive option is set to false");
        instances[1].DateTimeProperty.Should().Be(2.September(2020).At(1.Hours()));
        instances[1].NullableDateTimeProperty.Should().BeNull("FillNullables option is set to false");
        instances[1].B.Should().BeNull("Recursive option is set to false");
    }
Exemplo n.º 8
0
        public void Should_allow_customization()
        {
            var factory = MagicFactory.For <Person>();

            var person = factory
                         .With(x => x.FirstName = "Martha")
                         .With(x => x.LastName  = "Kent")
                         .With(x => x.Age       = 60)
                         .Build();

            person.FirstName.Should().Be("Martha");
            person.LastName.Should().Be("Kent");
            person.Age.Should().Be(60);
        }
Exemplo n.º 9
0
    public void should_execute_callback_through_ICustomizeOneBuildOne()
    {
        string shipName = null;

        Action <Ship> saveShipName           = ship => shipName = ship.Name;
        ICustomizeOneBuildOne <Ship> factory = MagicFactory.For <Ship>()
                                               .With(x => x.Name = "Mary");

        factory
        .Do(saveShipName)
        .Build();

        shipName.Should().Be("Mary");
    }
Exemplo n.º 10
0
    public void should_execute_callbacks_in_order()
    {
        string shipNameBefore = null;
        string shipNameAfter  = null;

        MagicFactory.For <Ship>()
        .Do(x => shipNameBefore = x.Name)
        .With(x => x.Name       = "Mary")
        .Do(x => shipNameAfter  = x.Name)
        .Build();

        shipNameBefore.Should().BeNull();
        shipNameAfter.Should().Be("Mary");
    }
Exemplo n.º 11
0
        public void Should_produce_multiple_instances_using_custom_constructor()
        {
            var products = MagicFactory.For <Product>()
                           .UsingConstructor(() => new Product("MAG-7", "Shotgun"))
                           .Many(2)
                           .Plus(2)
                           .Build()
                           .ToArray();

            products.Should().HaveCount(4);
            foreach (var product in products)
            {
                product.Name.Should().Be("MAG-7");
                product.Category.Should().Be("Shotgun");
            }
        }
            public static IEnumerable <object[]> FactoriesWithRecursionDisabled()
            {
                var customizedBehavior = new FillWithSequentialValuesBehavior(options =>
                {
                    options.Recursive = false;
                });

                return(new List <object[]>
                {
                    new object[] { new CustomerFactory(customizedBehavior) },
                    new object[] { MagicFactory.For <Customer>()
                                   .WithBehavior(new FillWithSequentialValuesBehavior(options =>
                                                                                      options.Recursive = false)
                                                 ) }
                });
            }
            public static IEnumerable <object[]> FactoriesWithDefaultBehavior()
            {
                var customizedBehavior = new FillWithSequentialValuesBehavior(options =>
                {
                    options.DateTimeOptions = new DateTimeSequenceOptions
                    {
                        StartDate          = 25.December(2020).At(22.Hours()),
                        DateTimeIncrements = DateTimeIncrements.Hours
                    };
                });

                return(new List <object[]>
                {
                    new object[] { new CustomerFactory(customizedBehavior) },
                    new object[] { MagicFactory.For <Customer>().WithBehavior(customizedBehavior) }
                });
            }
Exemplo n.º 14
0
    public void should_execute_callback_through_ICustomizeManyBuildMany()
    {
        string shipName = null;
        var    counter  = 0;

        Action <Ship> saveShipName = ship =>
        {
            shipName = ship.Name;
            counter++;
        };
        ICustomizeManyBuildMany <Ship> factory = MagicFactory.For <Ship>()
                                                 .Many(2)
                                                 .With(x => x.Name = "Mary");

        factory
        .Do(saveShipName)
        .Build()
        .ToArray();

        shipName.Should().Be("Mary");
        counter.Should().Be(2);
    }
Exemplo n.º 15
0
    public void should_execute_callback_through_ICustomizeOneBuildManyWithNavigation()
    {
        string shipName = null;
        var    counter  = 0;

        Action <Ship> saveShipName = ship =>
        {
            shipName = ship.Name;
            counter++;
        };
        ICustomizeOneBuildManyWithNavigation <Ship> factory = MagicFactory.For <Ship>()
                                                              .One()
                                                              .PlusOne()
                                                              .With(x => x.Name = "Mary");

        factory
        .Do(saveShipName)
        .Build()
        .ToArray();

        shipName.Should().Be("Mary");
        counter.Should().Be(1, "the first generator node does not configure a configure");
    }