public void CanReadWriteNullOrEmptyString(string value)
        {
            var sut = _fixture.Create <DbaseCharacter>();

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

                    Assert.Equal(sut.Field, result.Field);
                    Assert.Equal(sut.Value, result.Value);
                }
            }
        }
        public void CanReadWriteNullString()
        {
            var sut = new DbaseCharacter(
                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 DbaseCharacter(sut.Field);
                    result.Read(reader);

                    Assert.Equal(sut.Field, result.Field);
                    Assert.Equal(sut.Value, result.Value);
                }
            }
        }
        public void AcceptsDateTimeOffsetValueReturnsExpectedResult(int length, DbaseCharacterOptions options, DateTimeOffset value, bool accepted)
        {
            var sut = new DbaseCharacter(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ), options: options);

            var result = sut.AcceptsValue(value);

            Assert.Equal(accepted, result);
        }
        public void AcceptsStringValueReturnsExpectedResult(int length, string value, bool accepted)
        {
            var sut = new DbaseCharacter(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ));

            var result = sut.AcceptsValue(value);

            Assert.Equal(accepted, result);
        }
        public void TryGetValueAsDateTimeOffsetReturnsExpectedResult(int length, DbaseCharacterOptions options, string value, bool gotten, DateTimeOffset gottenValueAsDateTimeOffset)
        {
            var sut = new DbaseCharacter(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ), value, options);

            var result = sut.TryGetValueAsDateTimeOffset(out var valueAsDateTime);

            Assert.Equal(gotten, result);
            Assert.Equal(gottenValueAsDateTimeOffset, valueAsDateTime);
        }
        public void TrySetValueAsNullableDateTimeOffsetReturnsExpectedResult(int length, DbaseCharacterOptions options,
                                                                             DateTimeOffset?value, bool expected)
        {
            var sut = new DbaseCharacter(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ), options: options);

            var result = sut.TrySetValueAsNullableDateTimeOffset(value);

            Assert.Equal(expected, result);
        }
        public void Visit(DbaseCharacter value)
        {
            var length = new Generator <DbaseFieldLength>(_fixture)
                         .First(specimen => specimen <= value.Field.Length);

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

            case 1:
                var generated = _fixture.Create <string>();
                value.Value = generated.Substring(0, Math.Min(generated.Length, length.ToInt32()));
                break;

            case 2:
                value.Value = string.Empty;
                break;
            }
        }
        public void SetValueAsNullableDateTimeOffsetReturnsExpectedResult(int length, DbaseCharacterOptions options,
                                                                          DateTimeOffset?value, bool expected)
        {
            var sut = new DbaseCharacter(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ), options: options);

            if (!expected)
            {
                Assert.Throws <FormatException>(() =>
                {
                    sut.ValueAsNullableDateTimeOffset = value;
                });
            }
            else
            {
                sut.ValueAsNullableDateTimeOffset = value;
            }
        }
        public void CanNotReadPastEndOfStream()
        {
            var sut = _fixture.Create <DbaseCharacter>();

            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 DbaseCharacter(sut.Field);
                    Assert.Throws <EndOfStreamException>(() => result.Read(reader));
                }
            }
        }
        public void GetValueAsNullableDateTimeOffsetReturnsExpectedResult(int length, DbaseCharacterOptions options,
                                                                          string value, bool gotten, DateTimeOffset?gottenValueAsDateTimeOffset)
        {
            var sut = new DbaseCharacter(
                DbaseField.CreateCharacterField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length)
                    ), value, options);

            if (!gotten)
            {
                Assert.Throws <FormatException>(() =>
                {
                    var _ = sut.ValueAsNullableDateTimeOffset;
                });
            }
            else
            {
                var result = sut.ValueAsNullableDateTimeOffset;
                Assert.Equal(gottenValueAsDateTimeOffset, result);
            }
        }
Beispiel #11
0
 public void Visit(DbaseCharacter value)
 {
     HashCode = value.Value?.GetHashCode() ?? 0;
 }
Beispiel #12
0
 public void Visit(DbaseCharacter value)
 {
     Comparer = new DelegatingDbaseFieldValueEqualityComparer <DbaseCharacter>(
         new DbaseCharacterEqualityComparer());
 }