예제 #1
0
        public void CanReadWriteNullOrEmptyString(string value)
        {
            var sut = _fixture.Create <DbaseString>();

            sut.Value = value;

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

                    Assert.Equal(sut.Field, result.Field);
                    Assert.Equal(sut.Value, result.Value);
                }
            }
        }
예제 #2
0
        public void CanReadWriteNullString()
        {
            var sut = new DbaseString(
                new DbaseField(
                    _fixture.Create <DbaseFieldName>(),
                    DbaseFieldType.Character,
                    ByteOffset.Initial,
                    new DbaseFieldLength(5),
                    new DbaseDecimalCount(0)
                    ),
                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 DbaseString(sut.Field);
                    result.Read(reader);

                    Assert.Equal(sut.Field, result.Field);
                    Assert.Equal(sut.Value, result.Value);
                }
            }
        }
예제 #3
0
        public void CanNotReadPastEndOfStream()
        {
            var sut = _fixture.Create <DbaseString>();

            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 DbaseString(sut.Field);
                    Assert.Throws <EndOfStreamException>(() => result.Read(reader));
                }
            }
        }