예제 #1
0
        /// <summary>
        /// Create an <see cref="IList{T}"/> with properties populated with random values.
        /// </summary>
        /// <typeparam name="T">The type of the instance for which properties are to be updated.</typeparam>
        /// <param name="randomValueProvider">The <see cref="RandomValueProvider"/>.</param>
        /// <param name="count">The desired <see cref="IList{T}"/> count.</param>
        /// <param name="maximumDepth">Optional maximum "depth" of "child" class instances to create.</param>
        /// <param name="callback">Optional "callback" function to perform additional property assignments.</param>
        /// <returns>New <see cref="IList{T}"/>.</returns>
        // ReSharper disable once UnusedMember.Global
        // ReSharper disable once InconsistentNaming
        public static IList <T> IListOf <T>(
            RandomValueProvider randomValueProvider,
            int count,
            int?maximumDepth    = null,
            Action <T> callback = null)
        {
            var populater = new Populater();

            if (maximumDepth.HasValue)
            {
                populater.MaximumDepth = maximumDepth.Value;
            }

            List <T> items = populater.CreateIEnumerableOf <T>(count, randomValueProvider).ToList();

            if (callback != null)
            {
                foreach (T item in items)
                {
                    callback(item);
                }
            }

            return(items);
        }
예제 #2
0
 /// <summary>
 /// Create an <see cref="IEnumerable{T}"/> with properties populated with random values.
 /// </summary>
 /// <typeparam name="T">The type of the instance for which properties are to be updated.</typeparam>
 /// <param name="randomValueProvider">The <see cref="RandomValueProvider"/>.</param>
 /// <param name="count">The desired <see cref="IEnumerable{T}"/> count.</param>
 /// <param name="maximumDepth">Optional maximum "depth" of "child" class instances to create.</param>
 /// <param name="callback">Optional "callback" function to perform additional property assignments.</param>
 /// <returns>New <see cref="IEnumerable{T}"/>.</returns>
 // ReSharper disable once UnusedMember.Global
 // ReSharper disable once InconsistentNaming
 public static IEnumerable <T> IEnumerableOf <T>(
     RandomValueProvider randomValueProvider,
     int count,
     int?maximumDepth    = null,
     Action <T> callback = null) where T : class
 {
     return(ArrayOf(randomValueProvider, count, maximumDepth, callback));
 }
예제 #3
0
        /// <summary>
        /// Populate existing instance of <typeparamref name="T"/> with random values.
        /// </summary>
        /// <typeparam name="T">The instance type.</typeparam>
        /// <param name="instance">The instance.</param>
        /// <param name="randomValueProvider">The <see cref="RandomValueProvider"/> instance.</param>
        /// <param name="maximumDepth">Optional maximum "depth" of "child" class instances to create (default value is 5).</param>
        /// <returns>Populated instance of <typeparamref name="T"/>.</returns>
        public static T ValuesFor <T>(T instance, RandomValueProvider randomValueProvider, int?maximumDepth = null) where T : class
        {
            var populater = new Populater();

            if (maximumDepth.HasValue)
            {
                populater.MaximumDepth = maximumDepth.Value;
            }

            return(populater.Populate(instance, randomValueProvider));
        }
예제 #4
0
        /// <summary>
        /// Create <see cref="List{T}"/> and populate with test data.
        /// </summary>
        /// <typeparam name="T">The class type.</typeparam>
        /// <param name="count">The desired list count.</param>
        /// <param name="callback">Optional "callback" function to perform additional property assignments.</param>
        /// <returns>The created and populated <see cref="List{T}"/>.</returns>
        public virtual List <T> CreateRandomListOf <T>(int count, Action <T> callback = null)
        {
            var valueProvider = new RandomValueProvider();

            List <T> items = Enumerable.Range(1, count).Select(_ => CreateAndPopulate <T>(valueProvider)).ToList();

            if (callback != null)
            {
                foreach (T item in items)
                {
                    callback(item);
                }
            }

            return(items);
        }
예제 #5
0
        /// <summary>
        /// Create an instance of the specified type and populate its properties with random values.
        /// </summary>
        /// <typeparam name="T">The type of the instance for which properties are to be updated.</typeparam>
        /// <param name="randomValueProvider">The <see cref="RandomValueProvider"/>.</param>
        /// <param name="maximumDepth">Optional maximum "depth" of "child" class instances to create (default value is 5).</param>
        /// <param name="callback">Optional "callback" function to perform additional property assignments.</param>
        /// <returns>New instance.</returns>
        public static T InstanceOf <T>(
            RandomValueProvider randomValueProvider,
            int?maximumDepth    = null,
            Action <T> callback = null) where T : class
        {
            var populater = new Populater();

            if (maximumDepth.HasValue)
            {
                populater.MaximumDepth = maximumDepth.Value;
            }

            var instance = populater.CreateAndPopulate <T>(randomValueProvider);

            callback?.Invoke(instance);

            return(instance);
        }
예제 #6
0
 /// <summary>
 /// Get random <see cref="float"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="float"/> value.</returns>
 public static float Float(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetFloat());
 }
예제 #7
0
 /// <summary>
 /// Get random <see cref="string"/> value.
 /// </summary>
 /// <param name="prefix">optional string prefix.</param>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="string"/> value.</returns>
 public static string String(string prefix = null, RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetString(prefix));
 }
예제 #8
0
 /// <summary>
 /// Get random <see cref="Enum"/> value.
 /// </summary>
 /// <typeparam name="TEnum">The <see cref="Enum"/> type.</typeparam>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <typeparamref name="TEnum"/> value.</returns>
 public static TEnum EnumValue <TEnum>(RandomValueProvider randomValueProvider = null) where TEnum : Enum
 {
     return((randomValueProvider ?? _randomValueProvider).GetEnum <TEnum>());
 }
예제 #9
0
 /// <summary>
 /// Get random <see cref="ushort"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="ushort"/> value.</returns>
 public static ushort UShort(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetUShort());
 }
예제 #10
0
 /// <summary>
 /// Get random <see cref="ulong"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="ulong"/> value.</returns>
 public static ulong ULong(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetULong());
 }
예제 #11
0
 /// <summary>
 /// Get random <see cref="uint"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="uint"/> value.</returns>
 public static uint UInt(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetUInt());
 }
예제 #12
0
 /// <summary>
 /// Get random <see cref="sbyte"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="sbyte"/> value.</returns>
 public static sbyte SByte(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetSByte());
 }
예제 #13
0
 /// <summary>
 /// Create an instance of the specified type and populate its properties with random values.
 /// </summary>
 /// <typeparam name="T">The type of the instance for which properties are to be updated.</typeparam>
 /// <param name="randomValueProvider">The <see cref="RandomValueProvider"/>.</param>
 /// <param name="callback">"Callback" function to perform additional property assignments.</param>
 /// <returns>New instance.</returns>
 public static T InstanceOf <T>(RandomValueProvider randomValueProvider, Action <T> callback) where T : class
 {
     return(InstanceOf(randomValueProvider, (int?)null, callback));
 }
예제 #14
0
 /// <summary>
 /// Get random <see cref="Guid"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="Guid"/> value.</returns>
 public static Guid Guid(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetGuid());
 }
예제 #15
0
 /// <summary>
 /// Get random <see cref="double"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="double"/> value.</returns>
 public static double Double(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetDouble());
 }
예제 #16
0
 /// <summary>
 /// Get random <see cref="decimal"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="decimal"/> value.</returns>
 public static decimal Decimal(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetDecimal());
 }
예제 #17
0
 /// <summary>
 /// Get random <see cref="DateTime"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="DateTime"/> value.</returns>
 public static DateTime DateTime(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetDateTime());
 }
예제 #18
0
 /// <summary>
 /// Get random <see cref="char"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="char"/> value.</returns>
 public static char Char(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetChar());
 }
예제 #19
0
 /// <summary>
 /// Get random <see cref="bool"/> value.
 /// </summary>
 /// <param name="randomValueProvider">(Optional) <see cref="RandomValueProvider"/> override.</param>
 /// <returns>Random <see cref="bool"/> value.</returns>
 public static bool Bool(RandomValueProvider randomValueProvider = null)
 {
     return((randomValueProvider ?? _randomValueProvider).GetBool());
 }