Пример #1
0
        public void CanReadWriteNull()
        {
            var sut = _fixture.Create <DbaseDecimal>();

            sut.Value = null;

            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 DbaseDecimal(sut.Field);
                    result.Read(reader);

                    Assert.Equal(sut.Field, result.Field);
                    Assert.Equal(sut.Value, result.Value);
                }
            }
        }
        public void CanReadWriteNull()
        {
            _fixture.CustomizeDbaseDecimalWithoutValue();
            var sut = _fixture.Create <DbaseDecimal>();

            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 DbaseDecimal(sut.Field);
                    result.Read(reader);

                    Assert.Equal(sut.Field, result.Field);
                    Assert.Throws <FormatException>(() => sut.Value);
                }
            }
        }
Пример #3
0
        public void CanReadWriteWithMaxDecimalCount()
        {
            var length       = DbaseDecimal.MaximumLength;
            var decimalCount = DbaseDecimal.MaximumDecimalCount;
            var sut          =
                new DbaseDecimal(
                    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 DbaseDecimal(sut.Field);
                        result.Read(reader);

                        Assert.Equal(sut.Field, result.Field);
                        Assert.Equal(sut.Value, result.Value);
                    }
                }
            }
        }
        public void CanNotReadPastEndOfStream()
        {
            var sut = _fixture.Create <DbaseDecimal>();

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
                {
                    writer.Write(_fixture.CreateMany <byte>(new Random().Next(0, sut.Field.Length.ToInt32())).ToArray());
                    writer.Flush();
                }

                stream.Position = 0;

                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var result = new DbaseDecimal(sut.Field);
                    Assert.Throws <EndOfStreamException>(() => result.Read(reader));
                }
            }
        }
Пример #5
0
        public void CanReadWriteNegative()
        {
            using (var random = new PooledRandom())
            {
                var sut = new DbaseDecimal(
                    new DbaseField(
                        _fixture.Create <DbaseFieldName>(),
                        DbaseFieldType.Number,
                        _fixture.Create <ByteOffset>(),
                        DbaseDecimal.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 DbaseDecimal(sut.Field);
                        result.Read(reader);

                        Assert.Equal(sut, result, new DbaseFieldValueEqualityComparer());
                    }
                }
            }
        }