Ejemplo n.º 1
0
        /// <summary>
        /// Creates a random <see langword="int"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="int"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static int AnyInt32(this IAnonymousData anon, int minimum, int maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, int.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((int)anon.AnyInt64(minimum, maximum, distribution));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a random <see langword="IEnumerable{T}"/> sequence of objects of the specified type.
        /// </summary>
        /// <typeparam name="T">The type of objects to create.</typeparam>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimumLength">The minimum length of the sequence.</param>
        /// <param name="maximumLength">The maximum length of the sequence.</param>
        /// <returns>A random <see langword="IEnumerable{T}"/> sequence of the specified type of objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static IEnumerable <T> AnyEnumerable <T>(this IAnonymousData anon, int minimumLength, int maximumLength)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            return(anon.AnyEnumerable(typeof(T), minimumLength, maximumLength).Cast <T>());
        }
Ejemplo n.º 3
0
        /////// <summary>
        /////// Returns a random item from the specified <see cref="Array"/>.
        /////// </summary>
        /////// <param name="anon">The anonymous data provider to use.</param>
        /////// <param name="array">The <see cref="Array"/>.</param>
        /////// <returns>A random item from the collection.</returns>
        ////public static object AnyItem(this IAnonymousData anon, Array array)
        ////{
        ////    var index = anon.AnyInt32(0, array.Length);
        ////    return array.GetValue(index);
        ////}

        private static IEnumerable AnyEnumerable(IAnonymousData anon, Type type, int length)
        {
            for (int i = 0; i < length; ++i)
            {
                yield return(anon.Any(type));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a random <see langword="IEnumerable"/> sequence of 0 to 20 objects of the specified type.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="type">The type of objects to create.</param>
        /// <returns>A random <see langword="IEnumerable"/> sequence of the specified type of objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="type"/> is <c>null</c>.</exception>
        public static IEnumerable AnyEnumerable(this IAnonymousData anon, Type type)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));

            return(anon.AnyEnumerable(type, 0, 20));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates an anonymous <see langword="byte"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="byte"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static byte AnyByte(this IAnonymousData anon, byte minimum, byte maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, double.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((byte)anon.AnyInt64(minimum, maximum, distribution));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a random <see langword="float"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="float"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static float AnySingle(this IAnonymousData anon, float minimum, float maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, float.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnySingle(minimum, maximum, Distribution.Uniform));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a random <see langword="long"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="long"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static long AnyInt64(this IAnonymousData anon, long minimum, long maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, long.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnyInt64(minimum, maximum, Distribution.Uniform));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a <see langword="long"/> value within the specified ranges using the specified factory
        /// and distribution algorithm.
        /// </summary>
        /// <param name="factory">The factory used to create the <see langword="long"/> value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <param name="ranges">The ranges the value must be within.</param>
        /// <returns>A random <see langword="long"/> value that falls within the specified ranges.</returns>
        public static long CreateLongFromRanges(IAnonymousData factory, Distribution distribution, params Range[] ranges)
        {
            Argument.NotNull(factory, nameof(factory));
            Argument.NotNull(ranges, nameof(ranges));

            if (ranges.Length == 0)
            {
                throw new ArgumentException("The ranges must not be empty.", nameof(ranges));
            }

            VerifyRanges(ranges);
            var length = ranges.Sum(r => r.Length);
            var index  = factory.AnyInt64(0, length - 1, distribution);

            for (var i = 0; i < ranges.Length; ++i)
            {
                if (index < ranges[i].Length)
                {
                    var result = ranges[i].Minimum + index;
                    Debug.Assert(result >= ranges[i].Minimum && result <= ranges[i].Maximum, "Invalid range value.");
                    return(result);
                }

                index -= ranges[i].Length;
            }

            throw new InvalidOperationException();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates an anonymous <see langword="char"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="char"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static char AnyChar(this IAnonymousData anon, char minimum, char maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, char.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((char)anon.AnyInt64(minimum, maximum, distribution));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a random <see langword="IEnumerable"/> sequence of 0 to 20 objects of the specified type.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="type">The type of objects to create.</param>
        /// <returns>A random <see langword="IEnumerable"/> sequence of the specified type of objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="type"/> is <c>null</c>.</exception>
        public static IEnumerable AnyEnumerable(this IAnonymousData anon, Type type)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));

            return(anon.AnyEnumerable(type, anon.GetMinimumItemCount(), anon.GetMaximumItemCount()));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates a random <see langword="decimal"/> value using a uniform distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="decimal"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static decimal AnyDecimal(this IAnonymousData anon, decimal minimum, decimal maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, decimal.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return((decimal)anon.AnyDouble((double)minimum, (double)maximum, distribution));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a random <see langword="TimeSpan"/> value within the specified range using a uniform
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <returns>A random <see langword="TimeSpan"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static TimeSpan AnyTimeSpan(this IAnonymousData anon, TimeSpan minimum, TimeSpan maximum)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, TimeSpan.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            return(anon.AnyTimeSpan(minimum, maximum, Distribution.Uniform));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a random <see langword="string"/> value with a length within the specified range using
        /// a uniform distribution algorithm for generating alpha characters.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimumLength">The minimum length.</param>
        /// <param name="maximumLength">The maximum length.</param>
        /// <returns>A random <see langword="string"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static string AnyString(this IAnonymousData anon, int minimumLength, int maximumLength)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            return(anon.AnyString(minimumLength, maximumLength, Distribution.Uniform));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Returns a random item from the specified collection.
        /// </summary>
        /// <typeparam name="T">The item type.</typeparam>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="collection">The collection.</param>
        /// <returns>A random item from the collection.</returns>
        public static T AnyItem <T>(this IAnonymousData anon, IEnumerable <T> collection)
        {
            var items = collection as IList <T> ?? collection.ToList();
            var index = anon.AnyInt32(0, items.Count);

            return(items[index]);
        }
Ejemplo n.º 15
0
        private static int GetMinimumItemCount(this IAnonymousData anon)
        {
            Argument.NotNull(anon, nameof(anon));

            var value = anon.GetValue(MinItemCountKey);

            return(value == null ? 1 : (int)value);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a random <see langword="string"/> value representing a first name.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="male">If set to <c>true</c> a male first name is created; otherwise, a female
        /// first name is created.</param>
        /// <returns>A random first name.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static string AnyFirstName(this IAnonymousData anon, bool male)
        {
            Argument.NotNull(anon, nameof(anon));

            var names = male ? MaleFirstNames : FemaleFirstNames;

            return(anon.AnyItem(names));
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Creates a random value of the specified <see cref="Enum"/> type using a uniform distribution
        /// algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="enumType">The <see cref="Enum"/> type.</param>
        /// <returns>A random value of the specified <see cref="Enum"/> type.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="enumType"/> is <c>null</c>.</exception>
        public static object AnyEnumValue(this IAnonymousData anon, Type enumType)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(enumType, nameof(enumType));
            Argument.IsEnumType(enumType, nameof(enumType));

            return(anon.AnyEnumValue(enumType, Distribution.Uniform));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Creates a random <see langword="TimeSpan"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="TimeSpan"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static TimeSpan AnyTimeSpan(this IAnonymousData anon, TimeSpan minimum, TimeSpan maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, TimeSpan.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            long ticks = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution);

            return(new TimeSpan(ticks));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a random <see langword="long"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="long"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static long AnyInt64(this IAnonymousData anon, long minimum, long maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, long.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var min = Math.Max(minimum, long.MinValue + 1);

            return(min + (long)(anon.AnyDouble(0, 1, distribution) * ((double)maximum - (double)min)));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Anies the specified predicate.
        /// </summary>
        /// <typeparam name="T">The type to create.</typeparam>
        /// <param name="anon">The anon.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        public static T Any <T>(
            this IAnonymousData anon,
            Predicate <T> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(predicate, nameof(predicate));

            return(anon.Any <T>(PopulateOption.None, 20, predicate));
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Creates a random <see langword="DateTime"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="DateTime"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static DateTime AnyDateTime(this IAnonymousData anon, DateTime minimum, DateTime maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, DateTime.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var ticks = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution);

            return(new DateTime(ticks));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Creates a random <see langword="IEnumerable"/> sequence of objects of the specified type.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="type">The type of objects to create.</param>
        /// <param name="minimumLength">The minimum length of the sequence.</param>
        /// <param name="maximumLength">The maximum length of the sequence.</param>
        /// <returns>A random <see langword="IEnumerable"/> sequence of the specified type of objects.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="type"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static IEnumerable AnyEnumerable(this IAnonymousData anon, Type type, int minimumLength, int maximumLength)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            int length = anon.AnyInt32(minimumLength, maximumLength);

            return(AnyEnumerable(anon, type, length));
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Creates a random <see langword="DateTimeOffset"/> value within the specified range using the specified
        /// distribution algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimum">The minimum value.</param>
        /// <param name="maximum">The maximum value.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="DateTimeOffset"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximum"/> is less than <paramref name="minimum"/>.</exception>
        public static DateTimeOffset AnyDateTimeOffset(this IAnonymousData anon, DateTimeOffset minimum, DateTimeOffset maximum, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximum, minimum, DateTimeOffset.MaxValue, nameof(maximum), "The maximum value must be greater than the minimum value.");

            var ticks  = anon.AnyInt64(minimum.Ticks, maximum.Ticks, distribution);
            var offset = Offsets[anon.AnyInt32(0, Offsets.Length)];

            return(new DateTimeOffset(ticks, offset));
        }
Ejemplo n.º 24
0
        private static string AnySimpleFullName(this IAnonymousData anon, bool male)
        {
            switch (anon.AnyInt32(0, 5))
            {
            case 0:
                return($"{anon.AnyFirstName(male)} {anon.AnyFirstName(male).Substring(0, 1)}. {anon.AnySurname()}");

            default:
                return($"{anon.AnyFirstName(male)} {anon.AnySurname()}");
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Anies the specified retry attempts.
        /// </summary>
        /// <typeparam name="T">The type to create.</typeparam>
        /// <param name="anon">The anon.</param>
        /// <param name="retryAttempts">The retry attempts.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        public static T Any <T>(
            this IAnonymousData anon,
            int retryAttempts,
            Predicate <T> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(predicate, nameof(predicate));
            Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts));

            return(anon.Any <T>(PopulateOption.None, retryAttempts, predicate));
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates a random value of the specified <see cref="Enum"/> type using the specified distribution
        /// algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="enumType">The <see cref="Enum"/> type.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random value of the specified <see cref="Enum"/> type.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/>, <paramref name="enumType"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="enumType"/> is not an enum type.</exception>
        public static object AnyEnumValue(this IAnonymousData anon, Type enumType, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(enumType, nameof(enumType));
            Argument.IsEnumType(enumType, nameof(enumType));

            var values = Enum.GetValues(enumType);
            var index  = anon.AnyInt32(0, values.Length, distribution);

            return(values.GetValue(index));
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Anies the specified type.
        /// </summary>
        /// <param name="anon">The anon.</param>
        /// <param name="type">The type.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        public static object Any(
            this IAnonymousData anon,
            Type type,
            Predicate <object> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));
            Argument.NotNull(predicate, nameof(predicate));

            return(anon.Any(type, PopulateOption.None, 20, predicate));
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Creates a random value of the specified <see cref="Enum"/> type using the specified distribution
        /// algorithm.
        /// </summary>
        /// <typeparam name="T">The <see cref="Enum"/> type</typeparam>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random value of the specified <see cref="Enum"/> type.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static T AnyEnumValue <T>(this IAnonymousData anon, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));

            var type = typeof(T);

            if (!type.IsEnum())
            {
                throw new InvalidOperationException("Generic parameter T must be an Enum type.");
            }

            return((T)anon.AnyEnumValue(type, distribution));
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Anies the specified type.
        /// </summary>
        /// <param name="anon">The anon.</param>
        /// <param name="type">The type.</param>
        /// <param name="retryAttempts">The retry attempts.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>An instance of the specified type.</returns>
        public static object Any(
            this IAnonymousData anon,
            Type type,
            int retryAttempts,
            Predicate <object> predicate)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(type, nameof(type));
            Argument.NotNull(predicate, nameof(predicate));
            Argument.InRange(retryAttempts, 0, int.MaxValue, nameof(retryAttempts));

            return(anon.Any(type, PopulateOption.None, retryAttempts, predicate));
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Creates a random <see langword="string"/> value with a length within the specified range using
        /// the specified distribution algorithm for generating alpha characters.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="minimumLength">The minimum length.</param>
        /// <param name="maximumLength">The maximum length.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random <see langword="string"/> value.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="maximumLength"/> is less than <paramref name="minimumLength"/>.</exception>
        public static string AnyString(this IAnonymousData anon, int minimumLength, int maximumLength, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.InRange(maximumLength, minimumLength, int.MaxValue, nameof(maximumLength), "The maximum length must be greater than the minimum length.");

            var length  = anon.AnyInt32(minimumLength, maximumLength);
            var builder = new StringBuilder(length);

            while (builder.Length < length)
            {
                builder.Append(anon.AnyAlphaChar(distribution));
            }

            return(builder.ToString());
        }