Exemple #1
0
        private string GenerateRandomString(int minLength, int maxLength)
        {
            int characters = RandomStore.Next(minLength, maxLength);

            var result = new StringBuilder(characters);   // I seriously doubt this is faster.

            for (; characters > 0; characters--)
            {
                result.Append((char)RandomStore.Next(15, 125));
            }

            return(result.ToString());
        }
        /// <summary>
        /// Designed to use reflection to work out the type of a value passed to it then alter that value to something different, aimed at
        /// changing values for unit tests.  All that can be said is that the return value will not equal the entry value for supported simple types.
        /// </summary>
        /// <remarks>If the val object is of an unsupported type it is returned unchanged.</remarks>
        /// <param name="target">The value to change</param>
        /// <returns>A new value for the object val</returns>
        public object AlterValue(object target)
        {
            if (target == null)
            {
                return(null);
            }

            Type t = target.GetType();

            if (t == typeof(long))
            {
                return((long)target + 1);
            }
            if (t == typeof(uint))
            {
                return((uint)target + 1);
            }
            if (t == typeof(double))
            {
                return((double)target + 1);
            }
            if (t == typeof(int))
            {
                return((int)target + 1);
            }

            if (t == typeof(bool))
            {
                return(!(bool)target);   // Invert it for bools
            }
            if (t == typeof(string))
            {
                string s      = GenerateFriendlyString();
                int    length = RandomStore.Next(5);
                if (s.Length < length)
                {
                    length = s.Length;
                }
                return((string)target + s.Substring(0, length));
            }
            return(target);
        }