Exemplo n.º 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);
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
        }