Exemplo n.º 1
0
 /// <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);
     }));
 }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 4
0
 /// <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)));
 }
Exemplo n.º 5
0
 /// <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));
 }
Exemplo n.º 7
0
 public void SetUp()
 {
     _builderMock = new Mock <IConfiguredBuilder>();
     _builder     = new TypedBuilder <SimpleClass>(_builderMock.Object, false);
 }
Exemplo n.º 8
0
 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));
 }
Exemplo n.º 10
0
        /// <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")));
 }
Exemplo n.º 17
0
 /// <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))));
 }
Exemplo n.º 18
0
 public static ITypedBuilder NamedDecoration <TService>(this ITypedBuilder builder, string serviceName) => Register(builder, new KeyedService(serviceName, typeof(TService)));
Exemplo n.º 19
0
 /// <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));
 }
Exemplo n.º 20
0
 public static ITypedBuilder TypedDecoration(this ITypedBuilder builder, Type serviceType) => Register(builder, new TypedService(serviceType));
Exemplo n.º 21
0
 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));
 }
Exemplo n.º 23
0
 public static ITypedBuilder KeyedDecoration <TService>(this ITypedBuilder builder, object serviceKey) => Register(builder, new KeyedService(serviceKey, typeof(TService)));
Exemplo n.º 24
0
 /// <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));
 }
Exemplo n.º 25
0
 public static ITypedBuilder NamedDecoration(this ITypedBuilder builder, string serviceName, Type serviceType) => Register(builder, new KeyedService(serviceName, serviceType));
Exemplo n.º 26
0
 /// <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++));
 }
Exemplo n.º 27
0
 private static ITypedBuilder Register(ITypedBuilder builder, IServiceWithType service)
 {
     DecoratorRegistrator.Register(builder, service);
     return(builder);
 }
Exemplo n.º 28
0
        /// <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));
 }