/// <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); }
/// <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)); }
/// <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)); }
/// <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); }
/// <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); }
/// <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()); }
/// <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)); }
/// <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>()); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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)); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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()); }
/// <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()); }