public static void CustomizeDbaseString(this IFixture fixture) { fixture.Customize <DbaseString>( customization => customization .FromFactory <int>( value => { using (var random = new PooledRandom(value)) { var length = new DbaseFieldLength(random.Next(0, 255)); return(new DbaseString( new DbaseField( fixture.Create <DbaseFieldName>(), DbaseFieldType.Character, fixture.Create <ByteOffset>(), length, new DbaseDecimalCount(0) ), new string('a', random.Next(0, length.ToInt32())))); } } ) .OmitAutoProperties()); }
public static DbaseFieldLength GenerateDbaseSingleLengthBetween(this IFixture fixture, DbaseFieldLength minLength, DbaseFieldLength maxLength) { if (minLength < DbaseSingle.MinimumLength || minLength > DbaseSingle.MaximumLength) { throw new ArgumentOutOfRangeException(nameof(minLength), $"The minimum length needs to be between {DbaseSingle.MinimumLength} and {DbaseSingle.MaximumLength}."); } if (maxLength < DbaseSingle.MinimumLength || maxLength > DbaseSingle.MaximumLength) { throw new ArgumentOutOfRangeException(nameof(maxLength), $"The maximum length needs to be between {DbaseSingle.MinimumLength} and {DbaseSingle.MaximumLength}."); } if (minLength > maxLength) { throw new ArgumentOutOfRangeException(nameof(minLength), $"The minimum length {minLength} needs to be less than or equal to the maximum length {maxLength}."); } using (var random = new PooledRandom()) { return(new DbaseFieldLength(random.Next(minLength.ToInt32(), maxLength.ToInt32()))); } }
public static DbaseFieldLength GenerateDbaseInt32LengthLessThan(this IFixture fixture, DbaseFieldLength maxLength) { using (var random = new PooledRandom()) { return(new DbaseFieldLength(random.Next(maxLength.ToInt32()))); } }
public static DbaseFieldLength GenerateDbaseSingleLength(this IFixture fixture) { using (var random = new PooledRandom()) { return(new DbaseFieldLength(random.Next(DbaseSingle.MinimumLength.ToInt32(), DbaseSingle.MaximumLength.ToInt32()))); } }
public static IPostprocessComposer <T> FromFactory <T>(this IFactoryComposer <T> composer, Func <Random, T> factory) { return(composer.FromFactory <int>(value => { using (var random = new PooledRandom(value)) { return factory(random); } })); }
public static IPostprocessComposer <T> FromNumberGenerator <T>(this IFactoryComposer <T> composer, Func <DbaseFieldNumberGenerator, T> factory) { return(composer.FromFactory <int>(value => { using (var random = new PooledRandom(value)) { return factory(new DbaseFieldNumberGenerator(random)); } })); }
public static DbaseFieldLength GenerateDbaseInt16Length(this IFixture fixture, DbaseFieldType fieldType) { using (var random = new PooledRandom()) { if (fieldType == DbaseFieldType.Number) { return(new DbaseFieldLength(random.Next(DbaseDouble.MaximumLength.ToInt32()))); } return(new DbaseFieldLength(random.Next(DbaseSingle.MaximumLength.ToInt32()))); } }
public void ResetHasExpectedResult() { using (var random = new PooledRandom()) { var sut = _fixture.Create <DbaseNumber>(); sut.Value = new DbaseFieldNumberGenerator(random).GenerateAcceptableValue(sut); sut.Reset(); Assert.Null(sut.Value); } }
public void ResetHasExpectedResult() { using (var random = new PooledRandom()) { var sut = _fixture.Create <DbaseDecimal>(); sut.Value = new DbaseFieldNumberGenerator(random).GenerateAcceptableValue(sut); sut.Reset(); Assert.False(sut.HasValue); Assert.Throws <FormatException>(() => sut.Value); } }
public static DbaseDecimalCount GenerateDbaseSingleDecimalCount(this IFixture fixture, DbaseFieldLength length) { if (length < DbaseSingle.MinimumLength || length > DbaseSingle.MaximumLength) { throw new ArgumentOutOfRangeException(nameof(length), $"The length needs to be between {DbaseSingle.MinimumLength} and {DbaseSingle.MaximumLength}."); } using (var random = new PooledRandom()) { return(new DbaseDecimalCount(random.Next(1, Math.Min(DbaseSingle.MaximumDecimalCount.ToInt32(), length.ToInt32()) - 2))); } }
public static DbaseFieldLength GenerateDbaseDoubleLengthLessThan(this IFixture fixture, DbaseFieldLength maxLength) { if (maxLength < DbaseDouble.MinimumLength || maxLength > DbaseDouble.MaximumLength) { throw new ArgumentOutOfRangeException(nameof(maxLength), $"The maximum length needs to be between {DbaseDouble.MinimumLength} and {DbaseDouble.MaximumLength}."); } using (var random = new PooledRandom()) { return(new DbaseFieldLength(random.Next(DbaseDouble.MinimumLength.ToInt32(), maxLength.ToInt32() + 1))); } }
public static DbaseDecimalCount GenerateDbaseDoubleDecimalCount(this IFixture fixture, DbaseDecimalCount minimum, DbaseFieldLength length) { if (length > DbaseDouble.MaximumLength) { throw new ArgumentOutOfRangeException(nameof(length), $"The length ({length}) can not exceed the maximum length ({DbaseDouble.MaximumLength})."); } using (var random = new PooledRandom()) { return(new DbaseDecimalCount(random.Next(minimum.ToInt32(), Math.Min(DbaseDouble.MaximumDecimalCount.ToInt32() + 1, length.ToInt32()) - 2))); } }
public void CanReadWriteWithMaxDecimalCount() { var length = DbaseNumber.MaximumLength; var decimalCount = DbaseNumber.MaximumDecimalCount; var sut = new DbaseNumber( new DbaseField( _fixture.Create <DbaseFieldName>(), DbaseFieldType.Number, _fixture.Create <ByteOffset>(), length, decimalCount ) ); using (var random = new PooledRandom()) { sut.Value = new DbaseFieldNumberGenerator(random) .GenerateAcceptableValue(sut); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, true)) { sut.Write(writer); writer.Flush(); } stream.Position = 0; using (var reader = new BinaryReader(stream, Encoding.ASCII, true)) { var result = new DbaseNumber(sut.Field); result.Read(reader); Assert.Equal(sut.Field, result.Field); Assert.Equal(sut.Value, result.Value); } } } }
public void CanReadWriteNegative() { using (var random = new PooledRandom()) { var sut = new DbaseNumber( new DbaseField( _fixture.Create <DbaseFieldName>(), DbaseFieldType.Number, _fixture.Create <ByteOffset>(), DbaseNumber.NegativeValueMinimumLength, new DbaseDecimalCount(1) ) ); sut.Value = new DbaseFieldNumberGenerator(random) .GenerateAcceptableValue(sut); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, true)) { sut.Write(writer); writer.Flush(); } stream.Position = 0; using (var reader = new BinaryReader(stream, Encoding.ASCII, true)) { var result = new DbaseNumber(sut.Field); result.Read(reader); Assert.Equal(sut, result, new DbaseFieldValueEqualityComparer()); } } } }