/// <summary> /// Registers that a writable property should be assigned to the result of calling /// the specified factory function as part of specimen post-processing. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <typeparam name="TProperty">The type of the property.</typeparam> /// <param name="composer">The composer.</param> /// <param name="property">The property.</param> /// <param name="factory">The factory.</param> /// <returns></returns> public static IPostprocessComposer <TModel> With <TModel, TProperty>(this IPostprocessComposer <TModel> composer, Expression <Func <TModel, TProperty> > property, Func <TProperty> factory) { var info = property.GetProperty(); return(composer.Without(property).Do(x => info.SetValue(x, factory()))); }
private IPostprocessComposer <Ticket> AddTagCustomisation( IFixture _, IPostprocessComposer <Ticket> ticket, string reason) => ticket .Without(y => y.Tags) .Do(y => y.Tags = new List <string> { $"pending_middleware_{reason.ToLower()}" });
public static IPostprocessComposer <T> WithoutBaseProperties <T>(this IPostprocessComposer <T> builder) where T : BaseModel <int> { return(builder .Without(x => x.Id) .Without(x => x.CreatedBy) .Without(x => x.CreatedOn) .Without(x => x.UpdatedOn) .Without(x => x.UpdatedBy) .Without(x => x.DeletedOn) .Without(x => x.DeletedBy)); }
/// <summary> /// Registers that a writable string property and normalized equivalent should be assigned to the result of calling /// the specified factory function as part of specimen post-processing. /// </summary> /// <typeparam name="TModel">The type of the model.</typeparam> /// <param name="composer">The composer.</param> /// <param name="property">The property.</param> /// <param name="normalizedProperty">The normalized property.</param> /// <param name="factory">The factory.</param> /// <returns></returns> public static IPostprocessComposer <TModel> WithNormalized <TModel>(this IPostprocessComposer <TModel> composer, Expression <Func <TModel, string> > property, Expression <Func <TModel, string> > normalizedProperty, Func <Faker, string> factory) { var faker = new Faker(); var info = property.GetProperty(); var normalizedInfo = normalizedProperty.GetProperty(); return(composer.Without(property).Without(normalizedProperty).Do(x => { var value = factory(faker); info.SetValue(x, value); normalizedInfo.SetValue(x, value.Normalize().ToUpper()); })); }
// When escalating tickets agents use a macro that adds a tagged // comment to the ticket. The extra tag and comment occur in the // same audit event as the "pending" tag. private static IPostprocessComposer <Ticket> EscalateCommentCustomisation( IFixture fixture, IPostprocessComposer <Ticket> ticket) => ticket .Without(y => y.Id) .Do(ticket => { ticket.Id = fixture.Create <long>(); var comment = fixture.Create <AuditedComment>(); comment.Escalate(); var zendesk = fixture.Create <FakeZendeskApi>(); zendesk.AddComments(ticket, new[] { comment }); });
public IPostprocessComposer <T> Without <TProperty>(Expression <Func <T, TProperty> > propertyPicker) => _builder = _builder.Without(propertyPicker);