public void It_should_produce_specified_number_of_instances(int targetCount)
        {
            var generatorNode = new GeneratorNode <Person>(targetCount);

            var instances = generatorNode.GenerateInstances();

            instances.Should().HaveCount(targetCount);
        }
        public void It_should_produce_one_instance_if_no_target_count_is_specified()
        {
            var generatorNode = new GeneratorNode <Person>();

            var instances = generatorNode.GenerateInstances();

            instances.Should().HaveCount(1);
        }
        public void It_should_accept_a_custom_constructor_function()
        {
            var generatorNode = new GeneratorNode <Person>();

            var persons = generatorNode.GenerateInstances(customConstructor: () => new Person {
                FirstName = "John", LastName = "Doe"
            });

            foreach (var person in persons)
            {
                person.FirstName.Should().Be("John");
                person.LastName.Should().Be("Doe");
            }
        }
        public void It_should_apply_default_transforms()
        {
            var generatorNode = new GeneratorNode <Person>(3);

            var transform1 =
                new NotGuardedTransform <Person>(new FuncTransform <Person, string>(x => x.FirstName = "Martha"));
            var transform2 =
                new NotGuardedTransform <Person>(new FuncTransform <Person, string>(x => x.LastName = "Kane"));
            var persons = generatorNode.GenerateInstances(new[] { transform1, transform2 });

            foreach (var person in persons)
            {
                person.FirstName.Should().Be("Martha");
                person.LastName.Should().Be("Kane");
            }
        }
        public void It_should_apply_transforms()
        {
            var generatorNode = new GeneratorNode <Person>(3);

            generatorNode.AddTransform(
                new FuncTransform <Person, string>(x => x.FirstName = "Martha"),
                new AlwaysApplyTransformSpecification()
                );

            var persons = generatorNode.GenerateInstances();

            foreach (var person in persons)
            {
                person.FirstName.Should().Be("Martha");
            }
        }
        public void It_should_apply_default_transforms_before_normal_transforms()
        {
            var generatorNode = new GeneratorNode <Person>(3);

            generatorNode.AddTransform(
                new FuncTransform <Person, string>(x => x.FirstName = "Jonathan"),
                new AlwaysApplyTransformSpecification()
                );

            var transform1 =
                new NotGuardedTransform <Person>(new FuncTransform <Person, string>(x => x.FirstName = "Martha"));
            var transform2 =
                new NotGuardedTransform <Person>(new FuncTransform <Person, string>(x => x.LastName = "Kane"));
            var persons = generatorNode.GenerateInstances(new[] { transform1, transform2 });

            foreach (var person in persons)
            {
                person.FirstName.Should().Be("Jonathan");
                person.LastName.Should().Be("Kane");
            }
        }
        public void It_should_apply_transforms_with_guards()
        {
            var generatorNode = new GeneratorNode <Person>(5);

            generatorNode.AddTransform(
                new FuncTransform <Person, string>(x => x.FirstName = "Martha"),
                new ApplyTransformToFirstInstancesSpecification(countToApply: 2, targetCount: 5)
                );
            generatorNode.AddTransform(
                new FuncTransform <Person, string>(x => x.FirstName = "Mirage"),
                new ApplyTransformToLastInstancesSpecification(countToApply: 2, targetCount: 5)
                );

            var persons = generatorNode
                          .GenerateInstances(customConstructor: () => new Person {
                FirstName = "Anne"
            })
                          .ToArray();

            var firstNames = persons.Select(x => x.FirstName);

            firstNames.Should().BeEquivalentTo("Martha", "Martha", "Anne", "Mirage", "Mirage");
        }