Пример #1
0
        internal static object GetRandomValue(FieldType type)
        {
            switch (type)
            {
            case FieldType.LongText:
                return(RndUtilities.NextString(RndUtilities.Next(0, 1024 * 1024)));    // max 1 MB

            case FieldType.FixedLengthText:
                return(RndUtilities.NextString(RndUtilities.Next(0, 451)));

            case FieldType.Date:
                return(new DateTime(RndUtilities.Next(1000, 9000), RndUtilities.Next(1, 13), RndUtilities.Next(1, 28)));

            case FieldType.Number:
                // TODO: determine range
                //return (decimal)rnd.NextDouble() * (decimal)Math.Pow(10, rnd.Next(29));
                //return rnd.NextDecimal();
                return(RndUtilities.NextInt32());

            case FieldType.Code:
                return(GetTestCodeValue());

            default:
                throw new NotImplementedException($"Missing random generator for type: {type.ToString()}");
            }
        }
Пример #2
0
        internal static Stream GenerateRandomStream(int?length = null)
        {
            length = length ?? rnd.Next(1, maxFileSize);
            var stream = new MemoryStream();

            using var writer = new StreamWriter(stream, leaveOpen: true);
            writer.Write(RndUtilities.NextString(length.Value));
            writer.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            return(stream);
        }
Пример #3
0
 internal static File GetRandomFile(long documentId, FileType type, int index = 1)
 {
     return(new File()
     {
         FileName = RndUtilities.NextString(100),
         DocumentId = documentId,
         DocumentIdentifier = RndUtilities.NextString(10),
         Index = index,
         Size = RndUtilities.Next(1024, 1024 * 1024),
         Type = type
     });
 }
Пример #4
0
 internal static Field GetRandomField(FieldType type, string?name = null)
 {
     name = name ?? $"Field_{RndUtilities.NextInt32()}";
     return(new Field(name: name)
     {
         Description = $"Description of {name}",
         Type = type,
         IsBuiltIn = RndUtilities.NextBool(),
         IsIncludeInTextSearch = RndUtilities.NextBool(),
         IsRelational = RndUtilities.NextBool(),
         IsRequiredOnCodeSets = RndUtilities.NextBool(),
         IsComputed = RndUtilities.NextBool(),
         CodeConfiguration = type == FieldType.Code ? GetTestCodeConfiguration() : null
     });
 }