/// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            var composedBuilder =
                CompositeSpecimenBuilder.ComposeIfMultiple(builders);

            return(new AutoPropertiesTarget(composedBuilder));
        }
Beispiel #2
0
        /// <summary>
        /// Registers that a writable property or field should be assigned a
        /// specific value as part of specimen post-processing.
        /// </summary>
        /// <typeparam name="TProperty">
        /// The type of the property of field.
        /// </typeparam>
        /// <param name="propertyPicker">
        /// An expression that identifies the property or field that will have
        /// <paramref name="value"/> assigned.
        /// </param>
        /// <param name="value">
        /// The value to assign to the property or field identified by
        /// <paramref name="propertyPicker"/>.
        /// </param>
        /// <returns>
        /// An <see cref="IPostprocessComposer{T}"/> which can be used to
        /// further customize the post-processing of created specimens.
        /// </returns>
        public IPostprocessComposer <T> With <TProperty>(
            Expression <Func <T, TProperty> > propertyPicker, TProperty value)
        {
            var graphWithoutSeedIgnoringRelay =
                this.WithoutSeedIgnoringRelay();

            var container = FindContainer(graphWithoutSeedIgnoringRelay);

            var graphWithProperty = graphWithoutSeedIgnoringRelay.ReplaceNodes(
                with: n => n.Compose(
                    new ISpecimenBuilder[]
            {
                new Postprocessor <T>(
                    CompositeSpecimenBuilder.ComposeIfMultiple(n),
                    new BindingCommand <T, TProperty>(propertyPicker, value),
                    CreateSpecification()),
                new SeedIgnoringRelay()
            }),
                when: container.Equals);

            return((NodeComposer <T>)graphWithProperty.ReplaceNodes(
                       with: n => n.Compose(
                           new []
            {
                new Omitter(
                    new EqualRequestSpecification(
                        propertyPicker.GetWritableMember().Member,
                        new MemberInfoEqualityComparer()))
            }
                           .Concat(n)),
                       when: n => n is NodeComposer <T>));
        }
        /// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            var composedBuilder =
                CompositeSpecimenBuilder.ComposeIfMultiple(builders);

            return(new BehaviorRoot(composedBuilder));
        }
        /// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            var composedBuilder =
                CompositeSpecimenBuilder.ComposeIfMultiple(builders);

            return(new CustomizationNode(composedBuilder));
        }
        /// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            var composedBuilder =
                CompositeSpecimenBuilder.ComposeIfMultiple(builders);

            return(new ResidueCollectorNode(composedBuilder));
        }
Beispiel #6
0
        /// <summary>
        /// Looks for the AutoProperties postprocessor in the current graph.
        /// If postprocessor is missing, it's created in inactive state.
        /// </summary>
        private NodeComposer <T> GetGraphWithAutoPropertiesNode()
        {
            var existingNode = FindAutoPropertiesNode(this);

            if (existingNode != null)
            {
                return(this);
            }

            var g      = WithoutSeedIgnoringRelay(this);
            var filter = FindContainer(g);

            // Create AutoProperties node in inactive state
            return((NodeComposer <T>)g.ReplaceNodes(
                       with: n => n.Compose(
                           new ISpecimenBuilder[]
            {
                new Postprocessor(
                    CompositeSpecimenBuilder.ComposeIfMultiple(n),
                    new AutoPropertiesCommand(typeof(T)),
                    new FalseRequestSpecification()),
                new SeedIgnoringRelay()
            }),
                       when: filter.Equals));
        }
Beispiel #7
0
        /// <summary>
        /// Registers that a writable property or field should be assigned a
        /// specific value as part of specimen post-processing.
        /// </summary>
        /// <typeparam name="TProperty">
        /// The type of the property of field.
        /// </typeparam>
        /// <param name="propertyPicker">
        /// An expression that identifies the property or field that will have
        /// <paramref name="value"/> assigned.
        /// </param>
        /// <param name="value">
        /// The value to assign to the property or field identified by
        /// <paramref name="propertyPicker"/>.
        /// </param>
        /// <returns>
        /// An <see cref="IPostprocessComposer{T}"/> which can be used to
        /// further customize the post-processing of created specimens.
        /// </returns>
        public IPostprocessComposer <T> With <TProperty>(
            Expression <Func <T, TProperty> > propertyPicker, TProperty value)
        {
            ExpressionReflector.VerifyIsNonNestedWritableMemberExpression(propertyPicker);

            var graphWithAutoPropertiesNode   = this.GetGraphWithAutoPropertiesNode();
            var graphWithoutSeedIgnoringRelay = WithoutSeedIgnoringRelay(graphWithAutoPropertiesNode);

            var container = FindContainer(graphWithoutSeedIgnoringRelay);

            var graphWithProperty = graphWithoutSeedIgnoringRelay.ReplaceNodes(
                with: n => n.Compose(
                    new ISpecimenBuilder[]
            {
                new Postprocessor(
                    CompositeSpecimenBuilder.ComposeIfMultiple(n),
                    new BindingCommand <T, TProperty>(propertyPicker, value),
                    CreateSpecification()),
                new SeedIgnoringRelay()
            }),
                when: container.Equals);

            var member = propertyPicker.GetWritableMember().Member;

            return((NodeComposer <T>)ExcludeMemberFromAutoProperties(member, graphWithProperty));
        }
        /// <inheritdoc />
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            if (builders == null)
            {
                throw new ArgumentNullException(nameof(builders));
            }

            return(new DataAnnotationsSupportNode(CompositeSpecimenBuilder.ComposeIfMultiple(builders)));
        }
        /// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            if (builders == null)
            {
                throw new ArgumentNullException(nameof(builders));
            }

            var composedBuilder = CompositeSpecimenBuilder.ComposeIfMultiple(builders);

            return(new ResidueCollectorNode(composedBuilder));
        }
        /// <summary>Composes the supplied builders.</summary>
        /// <param name="builders">The builders to compose.</param>
        /// <returns>
        /// A new <see cref="ISpecimenBuilderNode" /> instance containing
        /// <paramref name="builders" /> as child nodes.
        /// </returns>
        public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
        {
            if (builders == null)
            {
                throw new ArgumentNullException(nameof(builders));
            }

            var composedBuilder = CompositeSpecimenBuilder.ComposeIfMultiple(builders);

            return(new AutoPropertiesTarget(composedBuilder));
        }
Beispiel #11
0
 private static NodeComposer <T> WithDoNode(
     Action <T> action,
     ISpecimenBuilderNode graph,
     ISpecimenBuilderNode container)
 {
     return((NodeComposer <T>)graph.ReplaceNodes(
                with: n => n.Compose(
                    new[]
     {
         new Postprocessor <T>(
             CompositeSpecimenBuilder.ComposeIfMultiple(n),
             new ActionSpecimenCommand <T>(action))
     }),
                when: container.Equals));
 }
Beispiel #12
0
        /// <summary>
        /// Enables auto-properties for a type of specimen.
        /// </summary>
        /// <returns>
        /// An <see cref="IPostprocessComposer{T}"/> which can be used to
        /// further customize the post-processing of created specimens.
        /// </returns>
        public IPostprocessComposer <T> WithAutoProperties()
        {
            var g = this.WithoutSeedIgnoringRelay();

            var filter = FindContainer(g);

            return((NodeComposer <T>)g.ReplaceNodes(
                       with: n => ((FilteringSpecimenBuilder)n).Compose(
                           new ISpecimenBuilder[]
            {
                new Postprocessor <T>(
                    CompositeSpecimenBuilder.ComposeIfMultiple(n),
                    new AutoPropertiesCommand <T>(),
                    CreateSpecification()),
                new SeedIgnoringRelay()
            }),
                       when: filter.Equals));
        }
 /// <inheritdoc />
 public ISpecimenBuilderNode Compose(IEnumerable <ISpecimenBuilder> builders)
 {
     return(new DataAnnotationsSupportNode(CompositeSpecimenBuilder.ComposeIfMultiple(builders)));
 }