public static string CreateRandomCookieName(Random rndGen, CreatorSettings creatorSettings)
 {
     return(PrimitiveCreator.CreateRandomString(rndGen, -1, Token, new CreatorSettings(creatorSettings)
     {
         MinStringLength = 1
     }));
 }
        public override object CreateInstanceOf(Type type, Random rndGen, CreatorSettings creatorSettings)
        {
            ulong ul;

            do
            {
                ul = PrimitiveCreator.CreateInstanceOfUInt64(rndGen, creatorSettings);
            }while (ul > long.MaxValue);

            return(ul);
        }
Example #3
0
 protected override string GenerateInternal()
 {
     return(PrimitiveCreator.CreateRandomString(
                this.Random,
                -1,
                this.CharToUse,
                new CreatorSettings(this.Settings)
     {
         MinStringLength = this.MinSize,
         MaxStringLength = this.MaxSize
     }));
 }
Example #4
0
        /// <summary>
        /// Creates an instance of the given type.
        /// </summary>
        /// <param name="type">The type to create an instance from.</param>
        /// <param name="rndGen">A random generator used to populate the instance.</param>
        /// <param name="creatorSettings">Settings used to create the object.  This is an optional parameter and a default CreatorSettings is
        /// created if none is passed in.</param>
        /// <returns>An instance of the given type.</returns>
        public static object CreateInstanceOf(Type type, Random rndGen, CreatorSettings creatorSettings = null)
        {
            if (creatorSettings == null)
            {
                creatorSettings = new CreatorSettings();
            }

            if (creatorSettings.CreatorSurrogate != null)
            {
                if (creatorSettings.CreatorSurrogate.CanCreateInstanceOf(type))
                {
                    return(creatorSettings.CreatorSurrogate.CreateInstanceOf(type, rndGen, creatorSettings));
                }
            }

            if (PrimitiveCreator.CanCreateInstanceOf(type))
            {
                return(PrimitiveCreator.CreatePrimitiveInstance(type, rndGen, creatorSettings));
            }
            else if (type.IsArray)
            {
                return(CreateInstanceOfArray(type, rndGen, creatorSettings));
            }
            else if (type.IsGenericType)
            {
                if (type.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    return(CreateInstanceOfNullableOfT(type, rndGen, creatorSettings));
                }

                if (type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
                {
                    return(CreateInstanceOfDictionaryOfKAndV(type, rndGen, creatorSettings));
                }

                if (HasInterface(type, typeof(ICollection <>)) || HasInterface(type, typeof(IList <>)))
                {
                    return(CreateInstanceOfListOfT(type, rndGen, creatorSettings));
                }
            }
            else if (type.IsEnum)
            {
                return(CreateInstanceOfEnum(type, rndGen));
            }
            else if (type == typeof(JToken))
            {
                return(JTokenInstanceCreator.CreateInstanceOfJToken(rndGen, creatorSettings));
            }
            else if (type == typeof(JValue))
            {
                return(JTokenInstanceCreator.CreateInstanceOfJValue(rndGen, creatorSettings));
            }
            else if (type == typeof(JObject))
            {
                return(JTokenInstanceCreator.CreateInstanceOfJObject(rndGen, creatorSettings));
            }
            else if (type == typeof(JArray))
            {
                return(JTokenInstanceCreator.CreateInstanceOfJArray(rndGen, creatorSettings));
            }
            else if (type == typeof(System.Net.Http.Headers.CookieHeaderValue))
            {
                return(CookieHeaderValueInstanceCreator.CreateInstanceOfCookieHeaderValue(rndGen, creatorSettings));
            }
            else if (type.IsPublic)
            {
                return(ComplexTypeInstanceCreator.CreateInstanceOf(type, rndGen, creatorSettings));
            }

            throw new ArgumentException("Cannot create instance of " + type.FullName);
        }
 public static string CreateRandomPath(Random rndGen, CreatorSettings creatorSettings)
 {
     return(PrimitiveCreator.CreateRandomString(rndGen, -1, PathValue, creatorSettings));
 }
 public static string CreateRandomCookieValue(Random rndGen, CreatorSettings creatorSettings)
 {
     return(PrimitiveCreator.CreateRandomString(rndGen, -1, CookieOctet, creatorSettings));
 }