コード例 #1
0
        public void Constructs_with_negative_count_should_throw_exception()
        {
            var generator = new RandomStockStringGenerator
            {
                Values = new[] { "A", "B", "C", "D" },
                Count = -1
            };

            Assert.Throws<GenerationException>(() => generator.Run().Cast<string>().ToArray());
        }
コード例 #2
0
        public void Generate_sequence_ok()
        {
            var generator = new RandomStockStringGenerator
            {
                Values = new[] { "A", "B", "C", "D" },
                Count = 8
            };

            var values = generator.Run().Cast<string>().ToArray();
            Assert.Count(8, values);
            Assert.Multiple(() =>
            {
                foreach (string value in values)
                {
                    Assert.Contains<string>(new[] { "A", "B", "C", "D" }, value);
                }
            });
        }
コード例 #3
0
            /// <summary>
            /// Returns an enumeration of random strings from a pre-existing stock of values.
            /// </summary>
            /// <param name="count">The number of strings to generate.</param>
            /// <param name="stock">A stock of preset values.</param>
            /// <param name="seed">A seed value to initialize the random number generator.</param>
            /// <returns>An enumeration of random string values.</returns>
            /// <exception cref="GenerationException">Thrown if the specified parameters are inconsistent or invalid.</exception>
            public static IEnumerable<string> Strings(int count, RandomStringStock stock, int seed)
            {
                var generator = new RandomStockStringGenerator
                {
                    Count = count,
                    Values = RandomStringStockInfo.FromStock(stock).GetItems(),
                    Seed = seed,
                };

                foreach (string value in generator.Run())
                    yield return value;
            }