Beispiel #1
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);
                }
            }
        }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
0
        public void Inspect(DbaseString value)
        {
            var length = new Generator <DbaseFieldLength>(_fixture)
                         .First(specimen => specimen <= value.Field.Length);

            switch (_random.Next() % 2)
            {
            case 0:
                value.Value = null;
                break;

            case 1:
                if (value.Field.Length != new DbaseFieldLength(0))
                {
                    var generated = _fixture.Create <string>();
                    value.Value = generated.Substring(0, Math.Min(generated.Length, length.ToInt32()));
                }
                else
                {
                    value.Value = string.Empty;
                }

                break;
            }
        }
Beispiel #4
0
        public void AcceptsStringValueReturnsExpectedResult(int length, string value, bool accepted)
        {
            var sut = new DbaseString(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ));

            var result = sut.AcceptsValue(value);

            Assert.Equal(accepted, result);
        }
Beispiel #5
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));
                }
            }
        }
Beispiel #6
0
 public void Inspect(DbaseString value)
 {
     HashCode = value.Value != null
         ? value.Value.GetHashCode()
         : 0;
 }
Beispiel #7
0
 public void Inspect(DbaseString value)
 {
     Value = value.Value;
 }
Beispiel #8
0
 public void Inspect(DbaseString value)
 {
     Comparer = new DelegatingDbaseFieldValueEqualityComparer <DbaseString>(
         new DbaseStringEqualityComparer());
 }
Beispiel #9
0
 public void Visit(DbaseString value)
 {
     HashCode = value.Value?.GetHashCode() ?? 0;
 }