Ejemplo n.º 1
0
        public void CreateReturnsUniqueNumbersOnMultipleCallAsynchronously(long[] limits)
        {
            // Arrange
            int iterations     = 5;
            int completed      = 0;
            var done           = new ManualResetEvent(false);
            var min            = (int)limits.Min();
            var max            = (int)limits.Max();
            int repeatCount    = ((max - min) + 1) / iterations;
            int expectedResult = repeatCount * iterations;
            var dummyContext   = new DelegatingSpecimenContext();
            var sut            = new RandomNumericSequenceGenerator(limits);
            // Act
            var numbers = new int[iterations][];

            for (int i = 0; i < iterations; i++)
            {
                ThreadPool.QueueUserWorkItem(index =>
                {
                    numbers[(int)index] =
                        Enumerable
                        .Range(0, repeatCount)
                        .Select(x => sut.Create(typeof(int), dummyContext))
                        .Cast <int>()
                        .ToArray();

                    if (Interlocked.Increment(ref completed) == iterations)
                    {
                        done.Set();
                    }
                }, i);
            }
            done.WaitOne();
            int result = numbers.SelectMany(x => x).Distinct().Count();

            // Assert
            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 2
0
        public void CreateWhenLimitIsReachedStartsFromTheBeginning(long[] limits)
        {
            // Fixture setup
            var dummyContext = new DelegatingSpecimenContext();
            var min          = (int)limits.Min();
            var max          = (int)limits.Max();
            int repeatCount  = (max - min) + 1;
            var sut          = new RandomNumericSequenceGenerator(limits);
            // Exercise system and verify outcome
            var expectedResult = Enumerable.Range(min, repeatCount).ToArray();

            for (int iteration = 0; iteration < 3; iteration++)
            {
                var result = Enumerable
                             .Range(0, repeatCount)
                             .Select(i => sut.Create(typeof(int), dummyContext))
                             .Cast <int>()
                             .OrderBy(x => x);

                Assert.True(expectedResult.SequenceEqual(result));
            }
            // Teardown
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RandomOptionGenerator"/> class.
 /// </summary>
 public RandomOptionGenerator()
 {
     _randomizer = new RandomNumericSequenceGenerator((byte)OptionType.Text, (byte)OptionType.Numeric);
 }