/// <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)); }
/// <summary> /// Registers that a writable property should not be assigned an /// automatic value as part of specimen post-processing. /// </summary> /// <typeparam name="TProperty"> /// The type of the property or field to ignore. /// </typeparam> /// <param name="propertyPicker"> /// An expression that identifies the property or field to be ignored. /// </param> /// <returns> /// An <see cref="IPostprocessComposer{T}"/> which can be used to /// further customize the post-processing of created specimens. /// </returns> public IPostprocessComposer <T> Without <TProperty>( Expression <Func <T, TProperty> > propertyPicker) { ExpressionReflector.VerifyIsNonNestedWritableMemberExpression(propertyPicker); var member = propertyPicker.GetWritableMember().Member; var graphWithAutoPropertiesNode = this.GetGraphWithAutoPropertiesNode(); return((NodeComposer <T>)ExcludeMemberFromAutoProperties(member, graphWithAutoPropertiesNode)); }
/// <summary> /// Registers that a writable property or field should be assigned an /// anonymous 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 /// should have a value /// assigned. /// </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) { ExpressionReflector.VerifyIsNonNestedWritableMemberExpression(propertyPicker); var targetToDecorate = this.FindFirstNode(n => n is NoSpecimenOutputGuard); return((NodeComposer <T>) this.ReplaceNodes( with: n => new Postprocessor( n, new BindingCommand <T, TProperty>(propertyPicker), CreateSpecification()), when: targetToDecorate.Equals)); }