Ejemplo n.º 1
0
        /// <summary>
        /// Sets the default randomizer for all simple types.
        /// </summary>
        private void SetDefaultRandomizer()
        {
            var mnemonic           = new MnemonicString(1);
            var doublePlugin       = new DoubleRange();
            var dateTimeRandomizer = new DateTimeRange(new DateTime(1970, 1, 1));
            var uriRandomizer      = new RandomUri();

            this.TypeToRandomFunc[typeof(string)]    = mnemonic.GetValue;
            this.TypeToRandomFunc[typeof(bool)]      = () => Random.Next(0, 2) == 1;
            this.TypeToRandomFunc[typeof(bool?)]     = () => new RandomListItem <bool?>(true, false, null).GetValue();
            this.TypeToRandomFunc[typeof(short)]     = () => (short)Random.Next(-32767, 32767);
            this.TypeToRandomFunc[typeof(short?)]    = () => (short)Random.Next(-32767, 32767);
            this.TypeToRandomFunc[typeof(int)]       = () => Random.Next();
            this.TypeToRandomFunc[typeof(int?)]      = () => Random.Next();
            this.TypeToRandomFunc[typeof(long)]      = () => Random.NextLong();
            this.TypeToRandomFunc[typeof(long?)]     = () => Random.NextLong();
            this.TypeToRandomFunc[typeof(float)]     = () => (float)doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(float?)]    = () => (float?)doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(double)]    = () => doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(double?)]   = () => doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(decimal)]   = () => (decimal)Random.Next();
            this.TypeToRandomFunc[typeof(decimal?)]  = () => (decimal)Random.Next();
            this.TypeToRandomFunc[typeof(Guid)]      = () => Guid.NewGuid();
            this.TypeToRandomFunc[typeof(Guid?)]     = () => Guid.NewGuid();
            this.TypeToRandomFunc[typeof(DateTime)]  = () => dateTimeRandomizer.GetValue();
            this.TypeToRandomFunc[typeof(DateTime?)] = () => dateTimeRandomizer.GetValue();
            this.TypeToRandomFunc[typeof(byte)]      = () => (byte)Random.Next();
            this.TypeToRandomFunc[typeof(byte?)]     = () => (byte?)Random.Next();
            this.TypeToRandomFunc[typeof(char)]      = () => (char)Random.Next();
            this.TypeToRandomFunc[typeof(char?)]     = () => (char)Random.Next();
            this.TypeToRandomFunc[typeof(ushort)]    = () => (ushort)Random.Next();
            this.TypeToRandomFunc[typeof(ushort?)]   = () => (ushort)Random.Next();
            this.TypeToRandomFunc[typeof(uint)]      = () => (uint)Random.Next();
            this.TypeToRandomFunc[typeof(uint?)]     = () => (uint)Random.Next();
            this.TypeToRandomFunc[typeof(ulong)]     = () => (ulong)Random.Next();
            this.TypeToRandomFunc[typeof(ulong?)]    = () => (ulong)Random.Next();
            this.TypeToRandomFunc[typeof(IntPtr)]    = () => default(IntPtr);
            this.TypeToRandomFunc[typeof(IntPtr?)]   = () => default(IntPtr);
            this.TypeToRandomFunc[typeof(TimeSpan)]  = () => new TimeSpan(Random.Next());
            this.TypeToRandomFunc[typeof(TimeSpan?)] = () => new TimeSpan(Random.Next());
            this.TypeToRandomFunc[typeof(Uri)]       = () => uriRandomizer.GetValue();
#if !NETSTANDARD1_0
            this.TypeToRandomFunc[typeof(ArrayList)] = () => ((IRandomizerPlugin <ArrayList>) new Collectionizer <string, MnemonicString>()).GetValue();
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets the default randomizer for all simple types.
        /// </summary>
        private void SetDefaultRandomizer()
        {
            var mnemonic           = new MnemonicString(20);
            var doublePlugin       = new DoubleRange();
            var dateTimeRandomizer = new DateTimeRange(new DateTime(1970, 1, 1));

            this.TypeToRandomFunc[typeof(string)]    = mnemonic.GetValue;
            this.TypeToRandomFunc[typeof(bool)]      = () => Random.Next(0, 2) == 1;
            this.TypeToRandomFunc[typeof(bool?)]     = () => new RandomListItem <bool?>(true, false, null).GetValue();
            this.TypeToRandomFunc[typeof(short)]     = () => (short)Random.Next(-32767, 32767);
            this.TypeToRandomFunc[typeof(short?)]    = () => (short)Random.Next(-32767, 32767);
            this.TypeToRandomFunc[typeof(int)]       = () => Random.Next();
            this.TypeToRandomFunc[typeof(int?)]      = () => Random.Next();
            this.TypeToRandomFunc[typeof(long)]      = () => Random.NextLong();
            this.TypeToRandomFunc[typeof(long?)]     = () => Random.NextLong();
            this.TypeToRandomFunc[typeof(float)]     = () => (float)doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(float?)]    = () => (float?)doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(double)]    = () => doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(double?)]   = () => doublePlugin.GetValue();
            this.TypeToRandomFunc[typeof(decimal)]   = () => (decimal)Random.Next();
            this.TypeToRandomFunc[typeof(decimal?)]  = () => (decimal)Random.Next();
            this.TypeToRandomFunc[typeof(Guid)]      = () => Guid.NewGuid();
            this.TypeToRandomFunc[typeof(Guid?)]     = () => Guid.NewGuid();
            this.TypeToRandomFunc[typeof(DateTime)]  = () => dateTimeRandomizer.GetValue();
            this.TypeToRandomFunc[typeof(DateTime?)] = () => dateTimeRandomizer.GetValue();
            this.TypeToRandomFunc[typeof(byte)]      = () => (byte)Random.Next();
            this.TypeToRandomFunc[typeof(byte?)]     = () => (byte?)Random.Next();
            this.TypeToRandomFunc[typeof(char)]      = () => (char)Random.Next();
            this.TypeToRandomFunc[typeof(char?)]     = () => (char)Random.Next();
            this.TypeToRandomFunc[typeof(ushort)]    = () => (ushort)Random.Next();
            this.TypeToRandomFunc[typeof(ushort?)]   = () => (ushort)Random.Next();
            this.TypeToRandomFunc[typeof(uint)]      = () => (uint)Random.Next();
            this.TypeToRandomFunc[typeof(uint?)]     = () => (uint)Random.Next();
            this.TypeToRandomFunc[typeof(ulong)]     = () => (ulong)Random.Next();
            this.TypeToRandomFunc[typeof(ulong?)]    = () => (ulong)Random.Next();
            this.TypeToRandomFunc[typeof(IntPtr)]    = () => default(IntPtr);
            this.TypeToRandomFunc[typeof(IntPtr?)]   = () => default(IntPtr);
            this.TypeToRandomFunc[typeof(TimeSpan)]  = () => new TimeSpan(Random.Next());
            this.TypeToRandomFunc[typeof(TimeSpan?)] = () => new TimeSpan(Random.Next());
        }