Ejemplo n.º 1
0
 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());
 }
Ejemplo n.º 2
0
        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())));
            }
        }
Ejemplo n.º 3
0
 public static DbaseFieldLength GenerateDbaseInt32LengthLessThan(this IFixture fixture,
                                                                 DbaseFieldLength maxLength)
 {
     using (var random = new PooledRandom())
     {
         return(new DbaseFieldLength(random.Next(maxLength.ToInt32())));
     }
 }
Ejemplo n.º 4
0
 public static DbaseFieldLength GenerateDbaseSingleLength(this IFixture fixture)
 {
     using (var random = new PooledRandom())
     {
         return(new DbaseFieldLength(random.Next(DbaseSingle.MinimumLength.ToInt32(),
                                                 DbaseSingle.MaximumLength.ToInt32())));
     }
 }
Ejemplo n.º 5
0
 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);
         }
     }));
 }
Ejemplo n.º 6
0
 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));
         }
     }));
 }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 10
0
        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)));
            }
        }
Ejemplo n.º 11
0
        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)));
            }
        }
Ejemplo n.º 12
0
        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());
                    }
                }
            }
        }