/// <summary> /// Add a given value into the selected list type /// Other entries may already be present in the list /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TList>"/> /// </param> /// <param name="value"> /// A <see cref="TElement"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TList>"/> /// </returns> public static ITypedBuilder <TList> AddEntry <TList, TElement>(this ITypedBuilder <TList> builder, TElement value) where TList : IList <TElement> { return(builder.Do(x => { var list = (IList <TElement>)x; list.Add(value); })); }
/// <summary> /// Add a given value into the selected member's list /// Other entries may already be present in the list /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TType>"/> /// </param> /// <param name="expression"> /// A <see cref="Expression<Func<TType, TList>>"/> /// </param> /// <param name="value"> /// A <see cref="TElement"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TType>"/> /// </returns> public static ITypedBuilder <TType> AddEntry <TType, TList, TElement>(this ITypedBuilder <TType> builder, Expression <Func <TType, TList> > expression, TElement value) where TList : IList <TElement> { var getter = expression.Compile(); return(builder.Do(x => { var list = (IList <TElement>)getter(x); list.Add(value); })); }
public static ITypedBuilder WithContent <TContent>(this ITypedBuilder builder, Func <TContent> contentFactory, Encoding encoding, string mediaType) { if (contentFactory == null) { throw new ArgumentNullException(nameof(contentFactory)); } builder.WithConfiguration(s => { s.WithDefiniteContentType(typeof(TContent)); if (!typeof(IEmptyRequest).IsAssignableFrom(typeof(TContent))) { s.ContentFactory = () => contentFactory(); } }); builder.Advanced.WithContentEncoding(encoding); builder.Advanced.WithMediaType(mediaType); return(builder); }
/// <summary> /// Set the value of a member from a specified list of options (repeats allowed) /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TObj>"/> /// </param> /// <param name="property"> /// A <see cref="Expression<Func<TObj, TReturnType>>"/> /// </param> /// <param name="entries"> /// A <see cref="IEnumerable<TReturnType>"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TObj>"/> /// </returns> public static ITypedBuilder <TObj> SetFromCollection <TObj, TReturnType>(this ITypedBuilder <TObj> builder, Expression <Func <TObj, TReturnType> > property, IEnumerable <TReturnType> entries) { return(builder.Set(property, (o, b, s) => s.Random.OneFromList(entries))); }
/// <summary> /// Simple factory overload that populates a member with the given result of the parameterless getter /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TObj>"/> /// </param> /// <param name="property"> /// A <see cref="Expression<Func<TObj, TReturnType>>"/> /// </param> /// <param name="getter"> /// A <see cref="Func<TReturnType>"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TObj>"/> /// </returns> public static ITypedBuilder <TObj> Set <TObj, TReturnType>(this ITypedBuilder <TObj> builder, Expression <Func <TObj, TReturnType> > property, Func <TReturnType> getter) { return(builder.Set(property, (o, b, s) => getter())); }
public static Task SendAsync(this ITypedBuilder builder) { return(builder.SendAsync(CancellationToken.None)); }
public void SetUp() { _builderMock = new Mock <IConfiguredBuilder>(); _builder = new TypedBuilder <SimpleClass>(_builderMock.Object, false); }
public static ITypedBuilder KeyedDecoration(this ITypedBuilder builder, object serviceKey, Type serviceType) => Register(builder, new KeyedService(serviceKey, serviceType));
public static ITypedBuilder AsDelete(this ITypedBuilder builder) { return(builder.Advanced.WithMethod(HttpMethod.Delete)); }
/// <summary> /// Add a given key / value pair into the selected member's dictionary /// Other key and value pairs may already exist /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TType>"/> /// </param> /// <param name="expression"> /// A <see cref="Expression<Func<TType, TDictType>>"/> /// </param> /// <param name="key"> /// A <see cref="TKey"/> /// </param> /// <param name="value"> /// A <see cref="TElement"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TType>"/> /// </returns> public static ITypedBuilder <TType> AddEntry <TType, TDictType, TKey, TElement>(this ITypedBuilder <TType> builder, Expression <Func <TType, TDictType> > expression, TKey key, TElement value) where TDictType : IDictionary <TKey, TElement> { var getter = expression.Compile(); return(builder.Do(x => { var dict = (IDictionary <TKey, TElement>)getter(x); dict[key] = value; })); }
public static ITypedBuilder WithDefaultResult <TResult>(this ITypedBuilder builder, TResult result) { return(builder.WithDefaultResult(() => result)); }
public static ITypedBuilder WithContent <TContent>(this ITypedBuilder builder, TContent content, Encoding encoding, string mediaType) { return(builder.WithContent(() => content, encoding, mediaType)); }
public static ITypedBuilder WithContent <TContent>(this ITypedBuilder builder, Func <TContent> contentFactory, Encoding encoding) { return(builder.WithContent(contentFactory, encoding, null)); }
public static ITypedBuilder WithContent <TContent>(this ITypedBuilder builder, TContent content, Encoding encoding) { return(builder.WithContent(content, encoding, null)); }
public static ITypedBuilder WithContent <TContent>(this ITypedBuilder builder, TContent content) { return(builder.WithContent(content, null, null)); }
public static ITypedBuilder AsPatch(this ITypedBuilder builder) { return(builder.Advanced.WithMethod(new HttpMethod("PATCH"))); }
/// <summary> /// Set the member with a constructed instance of one of the specified types /// A random type is selected each time a member is constructed /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TObj>"/> /// </param> /// <param name="property"> /// A <see cref="Expression<Func<TObj, TReturnType>>"/> /// </param> /// <param name="types"> /// A <see cref="Type[]"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TObj>"/> /// </returns> public static ITypedBuilder <TObj> SetAsType <TObj, TReturnType>(this ITypedBuilder <TObj> builder, Expression <Func <TObj, TReturnType> > property, params Type[] types) { return(builder.Set(property, (o, b, s) => (TReturnType)b.Build(s.Random.OneFromList((IEnumerable <Type>)types)))); }
public static ITypedBuilder NamedDecoration <TService>(this ITypedBuilder builder, string serviceName) => Register(builder, new KeyedService(serviceName, typeof(TService)));
/// <summary> /// Add a given key / value pair into the selected dictionary type /// Other key and value pairs may already exist /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TDictType>"/> /// </param> /// <param name="key"> /// A <see cref="TKey"/> /// </param> /// <param name="value"> /// A <see cref="TElement"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TDictType>"/> /// </returns> public static ITypedBuilder <TDictType> AddEntry <TDictType, TKey, TElement>(this ITypedBuilder <TDictType> builder, TKey key, TElement value) where TDictType : IDictionary <TKey, TElement> { return(builder.Do(x => x[key] = value)); }
public static ITypedBuilder TypedDecoration(this ITypedBuilder builder, Type serviceType) => Register(builder, new TypedService(serviceType));
public static ITypedBuilder TypedDecoration <TService>(this ITypedBuilder builder) => Register(builder, new TypedService(typeof(TService)));
public static ITypedBuilder AsPost(this ITypedBuilder builder) { return(builder.Advanced.WithMethod(HttpMethod.Post)); }
public static ITypedBuilder KeyedDecoration <TService>(this ITypedBuilder builder, object serviceKey) => Register(builder, new KeyedService(serviceKey, typeof(TService)));
/// <summary> /// Set the member with a sequentially increasing number starting from 0 /// This number is not reset when a new build session is started /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TObj>"/> /// </param> /// <param name="property"> /// A <see cref="Expression<Func<TObj, System.Int32>>"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TObj>"/> /// </returns> public static ITypedBuilder <TObj> SetConsecutiveInt <TObj>(this ITypedBuilder <TObj> builder, Expression <Func <TObj, int> > property) { return(builder.SetConsecutiveInt(property, 0)); }
public static ITypedBuilder NamedDecoration(this ITypedBuilder builder, string serviceName, Type serviceType) => Register(builder, new KeyedService(serviceName, serviceType));
/// <summary> /// Set the member with a sequentially increasing number starting from the specified starting point /// This number is not reset when a new build session is started /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TObj>"/> /// </param> /// <param name="property"> /// A <see cref="Expression<Func<TObj, System.Int32>>"/> /// </param> /// <param name="startIndex"> /// Starting number to commence number from. The first created object receives this value /// A <see cref="System.Int32"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TObj>"/> /// </returns> public static ITypedBuilder <TObj> SetConsecutiveInt <TObj>(this ITypedBuilder <TObj> builder, Expression <Func <TObj, int> > property, int startIndex) { return(builder.Set(property, (obj, buildr, session) => startIndex++)); }
private static ITypedBuilder Register(ITypedBuilder builder, IServiceWithType service) { DecoratorRegistrator.Register(builder, service); return(builder); }
/// <summary> /// Numbers sibling items with the same immediate parent with a sequentially increasing number starting from 0 /// This number is reset to 0 every new parent object, and remembers the last number used for a given parent hierarchy /// </summary> /// <param name="builder"> /// A <see cref="ITypedBuilder<TObj>"/> /// </param> /// <param name="property"> /// A <see cref="Expression<Func<TObj, System.Int32>>"/> /// </param> /// <returns> /// A <see cref="ITypedBuilder<TObj>"/> /// </returns> public static ITypedBuilder <TObj> SetSiblingConsecutiveInt <TObj>(this ITypedBuilder <TObj> builder, Expression <Func <TObj, int> > property) { var sequence = Sequences.SiblingConsecutiveInt(); return(builder.Set <int>(property, (o, b, s) => sequence.Next(o, b, s))); }
private static void ApplyConfigurations(IEnumerable <IBuilderConfiguration <ITypedBuilder> > configurations, ITypedBuilder builder) { if (configurations == null) { return; } foreach (var configuration in configurations) { configuration.Configure(builder); } }
public static Task <TResult> ResultAsync <TResult>(this ITypedBuilder builder) { return(builder.ResultAsync <TResult>(CancellationToken.None)); }