示例#1
0
        /// <summary>
        /// Adds many objects to a list using the provided function to create each object.
        /// </summary>
        /// <typeparam name="T">The type of object that is contained in the list.</typeparam>
        /// <param name="fixture">The fixture.</param>
        /// <param name="collection">
        /// The list to which the created objects will be added.
        /// </param>
        /// <param name="creator">
        /// The function that creates each object which is subsequently added to
        /// <paramref name="collection"/>.
        /// </param>
        /// <remarks>
        /// <para>
        /// The number of objects created and added is determined by
        /// <see cref="IFixture.RepeatCount"/>.
        /// </para>
        /// </remarks>
        /// <seealso cref="AddManyTo{T}(IFixture, ICollection{T})"/>
        /// <seealso cref="AddManyTo{T}(IFixture, ICollection{T}, int)"/>
        public static void AddManyTo <T>(this IFixture fixture, ICollection <T> collection, Func <T> creator)
        {
            if (fixture == null)
            {
                throw new ArgumentNullException(nameof(fixture));
            }

            collection.AddMany(creator, fixture.RepeatCount);
        }
示例#2
0
        /// <summary>
        /// Adds many anonymously created objects to a list.
        /// </summary>
        /// <typeparam name="T">The type of object that is contained in the list.</typeparam>
        /// <param name="fixture">The fixture.</param>
        /// <param name="collection">
        /// The list to which the anonymously created objects will be added.
        /// </param>
        /// <param name="repeatCount">The number of objects created and added.</param>
        /// <seealso cref="AddManyTo{T}(IFixture, ICollection{T})"/>
        /// <seealso cref="AddManyTo{T}(IFixture, ICollection{T}, Func{T})"/>
        public static void AddManyTo <T>(this IFixture fixture, ICollection <T> collection, int repeatCount)
        {
            if (fixture == null)
            {
                throw new ArgumentNullException(nameof(fixture));
            }

            collection.AddMany(fixture.Create <T>, repeatCount);
        }
        /// <summary>
        /// Adds many anonymously created objects to a list.
        /// </summary>
        /// <typeparam name="T">The type of object that is contained in the list.</typeparam>
        /// <param name="fixture">The fixture.</param>
        /// <param name="collection">
        /// The list to which the anonymously created objects will be added.
        /// </param>
        /// <param name="repeatCount">The number of objects created and added.</param>
        /// <seealso cref="AddManyTo{T}(IFixture, ICollection{T})"/>
        /// <seealso cref="AddManyTo{T}(IFixture, ICollection{T}, Func{T})"/>
        public static void AddManyTo <T>(this IFixture fixture, ICollection <T> collection, int repeatCount)
        {
            if (fixture == null)
            {
                throw new ArgumentNullException("fixture");
            }

            collection.AddMany(() => fixture.CreateAnonymous <T>(), repeatCount);
        }
示例#4
0
        public void AddMany_Null_Source_Throws_Exception()
        {
            ICollection <int?> source = null;
            var elements = new List <int?> {
                1, null, null, 2, null, 3
            };

            source.AddMany(elements);
            Assert.Fail();
        }
示例#5
0
 /// <summary>
 ///   Adds all the supplied toAdd to the end of the current collection.
 /// </summary>
 /// <typeparam name = "T"></typeparam>
 /// <param name = "col"></param>
 /// <param name = "items"></param>
 public static void AddMany <T>(this ICollection <T> col, params T[] items)
 {
     col.AddMany(items.AsEnumerable());
 }