private static ISpecimenBuilderNode WithoutSeedIgnoringRelay(ISpecimenBuilderNode graph) { var g = graph.ReplaceNodes( with: n => CompositeSpecimenBuilder.UnwrapIfSingle( n.Compose(n.Where(b => !(b is SeedIgnoringRelay)))), when: n => n.OfType <SeedIgnoringRelay>().Any()); return(g); }
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)); }
/// <summary> /// Adjusts the AutoProperties postprocessor and changes rule to avoid the specified member population. /// If AutoProperties node is missing, nothing is done. /// </summary> private static ISpecimenBuilderNode ExcludeMemberFromAutoProperties(MemberInfo member, ISpecimenBuilderNode graph) { var autoPropertiesNode = FindAutoPropertiesNode(graph); if (autoPropertiesNode == null) { return(graph); } var currentSpecification = ((AutoPropertiesCommand)autoPropertiesNode.Command).Specification; var newRule = new InverseRequestSpecification( new EqualRequestSpecification( member, new MemberInfoEqualityComparer())); // Try to make specification list flat if possible IRequestSpecification specification; if (currentSpecification is TrueRequestSpecification) { specification = newRule; } else if (currentSpecification is AndRequestSpecification andSpec) { specification = new AndRequestSpecification(andSpec.Specifications.Concat(new[] { newRule })); } else { specification = new AndRequestSpecification(currentSpecification, newRule); } return(graph.ReplaceNodes( with: _ => new Postprocessor( autoPropertiesNode.Builder, new AutoPropertiesCommand(typeof(T), specification), autoPropertiesNode.Specification), when: autoPropertiesNode.Equals)); }