/// <summary> /// Gets an array of random <see cref="byte"/> values. /// </summary> /// <param name="numberOfElements"> /// The number of random elements to get. /// </param> /// <param name="values"> /// Specifies if the values should be unique. /// </param> /// <returns> /// Returns an array of random <see cref="byte"/> values. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="numberOfElements"/> exceeds the maximum value of a <see cref="byte"/> /// and <paramref name="values"/> is equal to <c>Unique</c>. /// </exception> /// <remarks> /// If <paramref name="values"/> is equal to <see cref="ValueGeneration.UniqueValuesOnly"/>, /// then the value of <paramref name="numberOfElements"/> should be small relative to /// <see cref="byte.MaxValue"/>. The closer the ratio of <c>numberOfElements/byte.MaxValue</c> is to 1, /// the longer it will take for <c>GetByteValues</c> to produce a unique random set of values. /// </remarks> public byte[] GetByteValues(uint numberOfElements, ValueGeneration values) { if (values == ValueGeneration.UniqueValuesOnly && numberOfElements > byte.MaxValue) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, SecureRandom.ErrorTooManyUniqueElements, byte.MaxValue), "numberOfElements"); } var elements = new byte[numberOfElements]; if (values == ValueGeneration.DuplicatesAllowed) { this.Generator.GetBytes(elements); } else { var createdElementsCount = 0; while (createdElementsCount < numberOfElements) { var value = new byte[1]; this.Generator.GetBytes(value); if (!elements.Contains(value[0])) { elements[createdElementsCount] = value[0]; createdElementsCount++; } } } return(elements); }
private static Property CreateProperty(ValueGeneration valueGeneration) { var entityType = new Model().AddEntityType("Led"); var property = entityType.GetOrAddProperty("Zeppelin", typeof(Guid), shadowProperty: true); property.ValueGeneration = valueGeneration; return(property); }
private static Property CreateProperty(Type propertyType, ValueGeneration valueGeneration) { var entityType = new Model().AddEntityType("MyType"); var property = entityType.GetOrAddProperty("MyProperty", propertyType, shadowProperty: true); property.ValueGeneration = valueGeneration; return(property); }
private static StateEntry CreateStateEntry( EntityState entityState, ValueGeneration keyStrategy = ValueGeneration.None, ValueGeneration nonKeyStrategy = ValueGeneration.None) { var model = BuildModel(keyStrategy, nonKeyStrategy); var stateEntry = CreateConfiguration(model).Services.StateEntryFactory.Create( model.GetEntityType(typeof(T1).FullName), new T1 { Id = 1, Name = "Test" }); stateEntry.EntityState = entityState; return(stateEntry); }
private static IModel BuildModel(ValueGeneration keyStrategy, ValueGeneration nonKeyStrategy) { var model = new Entity.Metadata.Model(); var entityType = model.AddEntityType(typeof(T1)); var key = entityType.GetOrAddProperty("Id", typeof(int)); key.ValueGeneration = keyStrategy; key.Relational().Column = "Col1"; entityType.GetOrSetPrimaryKey(key); var nonKey = entityType.GetOrAddProperty("Name", typeof(string)); nonKey.Relational().Column = "Col2"; nonKey.ValueGeneration = nonKeyStrategy; return(model); }
/// <summary> /// Gets an array of random <see cref="int"/> values. /// </summary> /// <param name="numberOfElements"> /// The number of random elements to get. /// </param> /// <param name="values"> /// Specifies if the values should be unique. /// </param> /// <returns> /// Returns an array of random <see cref="int"/> values. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="numberOfElements"/> exceeds the maximum value of an <see cref="int"/> /// and <paramref name="values"/> is equal to <c>Unique</c>. /// </exception> /// <remarks> /// If <paramref name="values"/> is equal to <see cref="ValueGeneration.UniqueValuesOnly"/>, /// then the value of <paramref name="numberOfElements"/> should be small relative to /// <see cref="int.MaxValue"/>. The closer the ratio of <c>numberOfElements/int.MaxValue</c> is to 1, /// the longer it will take for <c>GetInt32Values</c> to produce a unique random set of values. /// </remarks> public int[] GetInt32Values(uint numberOfElements, ValueGeneration values) { if (values == ValueGeneration.UniqueValuesOnly && numberOfElements > int.MaxValue) { throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, SecureRandom.ErrorTooManyUniqueElements, int.MaxValue), "numberOfElements"); } var elements = new int[numberOfElements]; if (values == ValueGeneration.DuplicatesAllowed) { for (var i = 0; i < numberOfElements; i++) { elements[i] = this.Next(); } } else { var createdElementsCount = 0; while (createdElementsCount < numberOfElements) { var value = this.Next(); if (!elements.Contains(value)) { elements[createdElementsCount] = value; createdElementsCount++; } } } return(elements); }
internal MockRandomNumberGeneratorForGetByteValues(ValueGeneration values) : base() { this.Values = values; this.NextValue = 1; }
/// <summary> /// Gets an array of random <see cref="int"/> values between a given range. /// </summary> /// <param name="numberOfElements"> /// The number of random elements to get. /// </param> /// <param name="range"> /// Specifies a range to get values between. /// </param> /// <param name="values"> /// Specifies if the values should be unique. /// </param> /// <returns> /// Returns an array of random <see cref="int"/> values. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="numberOfElements"/> exceeds the difference between <c>range.End - range.Start</c> /// and <paramref name="values"/> is equal to <c>Unique</c>. /// </exception> /// <remarks> /// If <paramref name="values"/> is equal to <see cref="ValueGeneration.UniqueValuesOnly"/>, /// then the value of <paramref name="numberOfElements"/> should be small relative to /// the size of the range. The closer the ratio of <c>numberOfElements/(range.End - range.Start)</c> is to 1, /// the longer it will take for <c>GetInt32Values</c> to produce a unique random set of values. /// </remarks> public int[] GetInt32Values(uint numberOfElements, Range<int> range, ValueGeneration values) { if (this.disposed) { throw new ObjectDisposedException("SecureRandom"); } if (values == ValueGeneration.UniqueValuesOnly && numberOfElements > int.MaxValue) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SecureRandom.ErrorTooManyUniqueElements, int.MaxValue), "numberOfElements"); } var elements = new int[numberOfElements]; if (values == ValueGeneration.DuplicatesAllowed) { for (var i = 0; i < numberOfElements; i++) { elements[i] = this.Next(range.Start, range.End); } } else { var createdElementsCount = 0; while (createdElementsCount < numberOfElements) { var value = this.Next(range.Start, range.End); if (!elements.Contains(value)) { elements[createdElementsCount] = value; createdElementsCount++; } } } return elements; }
/// <summary> /// Gets an array of random <see cref="int"/> values. /// </summary> /// <param name="numberOfElements"> /// The number of random elements to get. /// </param> /// <param name="values"> /// Specifies if the values should be unique. /// </param> /// <returns> /// Returns an array of random <see cref="int"/> values. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="numberOfElements"/> exceeds the maximum value of an <see cref="int"/> /// and <paramref name="values"/> is equal to <c>Unique</c>. /// </exception> /// <remarks> /// If <paramref name="values"/> is equal to <see cref="ValueGeneration.UniqueValuesOnly"/>, /// then the value of <paramref name="numberOfElements"/> should be small relative to /// <see cref="int.MaxValue"/>. The closer the ratio of <c>numberOfElements/int.MaxValue</c> is to 1, /// the longer it will take for <c>GetInt32Values</c> to produce a unique random set of values. /// </remarks> public int[] GetInt32Values(uint numberOfElements, ValueGeneration values) { return this.GetInt32Values(numberOfElements, new Range<int>(0, int.MaxValue), values); }
/// <summary> /// Gets an array of random <see cref="byte"/> values. /// </summary> /// <param name="numberOfElements"> /// The number of random elements to get. /// </param> /// <param name="values"> /// Specifies if the values should be unique. /// </param> /// <returns> /// Returns an array of random <see cref="byte"/> values. /// </returns> /// <exception cref="ArgumentException"> /// Thrown if <paramref name="numberOfElements"/> exceeds the maximum value of a <see cref="byte"/> /// and <paramref name="values"/> is equal to <c>Unique</c>. /// </exception> /// <remarks> /// If <paramref name="values"/> is equal to <see cref="ValueGeneration.UniqueValuesOnly"/>, /// then the value of <paramref name="numberOfElements"/> should be small relative to /// <see cref="byte.MaxValue"/>. The closer the ratio of <c>numberOfElements/byte.MaxValue</c> is to 1, /// the longer it will take for <c>GetByteValues</c> to produce a unique random set of values. /// </remarks> public byte[] GetByteValues(uint numberOfElements, ValueGeneration values) { if (this.disposed) { throw new ObjectDisposedException("SecureRandom"); } if (values == ValueGeneration.UniqueValuesOnly && numberOfElements > byte.MaxValue) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, SecureRandom.ErrorTooManyUniqueElements, byte.MaxValue), "numberOfElements"); } var elements = new byte[numberOfElements]; if (values == ValueGeneration.DuplicatesAllowed) { this.Generator.GetBytes(elements); } else { var createdElementsCount = 0; while (createdElementsCount < numberOfElements) { var value = new byte[1]; this.Generator.GetBytes(value); if (!elements.Contains(value[0])) { elements[createdElementsCount] = value[0]; createdElementsCount++; } } } return elements; }
internal MockRandomNumberGeneratorForGetInt32Values(ValueGeneration values) : base() { this.Values = values; this.NextValue = 1; }