Exemplo n.º 1
0
 public void SetExpression_SetsAppropriateExpression()
 {
     _builder.Set(c => c.IntField, 10);
     _builder.Build <SimpleClass>();
     _builderMock.Verify(m => m.Build <SimpleClass>());
 }
Exemplo n.º 2
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.º 3
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.º 4
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()));
 }
Exemplo n.º 5
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)));
        }
Exemplo n.º 6
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++));
 }