private static IDataGenerator <string> ResolveStringDataGenerator(IEnumerable <DataGenerationHint> hints) { int minLength = hints.Max <MinLengthHint, int>(-1); int maxLength = hints.Min <MaxLengthHint, int>(minLength); if (minLength == -1 && maxLength == -1) { return(PrimitiveGenerators.Sequence <string>()); } if (minLength == -1) { minLength = 0; } return(PrimitiveGenerators.StringSequence(minLength, maxLength)); }
private static IDataGenerator <byte[]> ResolveBinaryDataGenerator(IEnumerable <DataGenerationHint> hints) { int minLength = hints.Max <MinLengthHint, int>(-1); int maxLength = hints.Min <MaxLengthHint, int>(minLength); if (minLength == -1 && maxLength == -1) { return(PrimitiveGenerators.BinarySequence()); } if (minLength == -1) { minLength = 0; } return(PrimitiveGenerators.BinarySequence(minLength, maxLength)); }
/// <summary> /// Resolves data generator which generates random data. /// </summary> /// <param name="clrType">The type of the data.</param> /// <param name="random">Random number generator.</param> /// <param name="hints">Data generation hints.</param> /// <returns>The random data generator.</returns> public IDataGenerator ResolveRandomDataGenerator(Type clrType, IRandomNumberGenerator random, params DataGenerationHint[] hints) { ExceptionUtilities.CheckArgumentNotNull(clrType, "clrType"); ExceptionUtilities.CheckArgumentNotNull(random, "random"); ExceptionUtilities.CheckArgumentNotNull(hints, "hints"); ExceptionUtilities.CheckAllRequiredDependencies(this); bool isNullable; var originalClrType = clrType; if (clrType.IsGenericType() && clrType.GetGenericTypeDefinition() == typeof(Nullable <>)) { clrType = clrType.GetGenericArguments()[0]; isNullable = true; } else { isNullable = clrType.IsClass(); } if (hints.OfType <AllNullsHint>().Any()) { ExceptionUtilities.Assert(isNullable, "Cannot use all-nulls hint with non-nullable type. Type was: '{0}'", originalClrType); return(PrimitiveGenerators.Default(originalClrType)); } Func <IRandomNumberGenerator, DataGenerationHint[], bool, IDataGenerator> createDataGen; if (!this.dataGeneratorCreators.TryGetValue(clrType, out createDataGen)) { throw new TaupoNotSupportedException( string.Format(CultureInfo.InvariantCulture, "Creating data generator for the type '{0}' is not supported by this resolver.", clrType.FullName)); } return(createDataGen(random, hints, isNullable)); }