public void CreateDoubleFieldReturnsExpectedResult()
        {
            var name                  = _fixture.Create <DbaseFieldName>();
            var length                = _fixture.GenerateDbaseDoubleLength();
            var decimalCount          = _fixture.GenerateDbaseDoubleDecimalCount(length);
            var positiveIntegerDigits = decimalCount != new DbaseDecimalCount(0)
                ? new DbaseIntegerDigits(length.ToInt32() - 1 - decimalCount.ToInt32())
                : new DbaseIntegerDigits(length.ToInt32());
            var negativeIntegerDigits = positiveIntegerDigits != new DbaseIntegerDigits(0)
                ? positiveIntegerDigits.Minus(new DbaseIntegerDigits(1))
                : new DbaseIntegerDigits(0);

            var result = DbaseField.CreateNumberField(
                name,
                length,
                decimalCount);

            Assert.Equal(name, result.Name);
            Assert.Equal(DbaseFieldType.Number, result.FieldType);
            Assert.Equal(ByteOffset.Initial, result.Offset);
            Assert.Equal(length, result.Length);
            Assert.Equal(decimalCount, result.DecimalCount);
            Assert.Equal(positiveIntegerDigits, result.PositiveIntegerDigits);
            Assert.Equal(negativeIntegerDigits, result.NegativeIntegerDigits);
        }
Esempio n. 2
0
 public FakeDbaseSchema()
 {
     Fields = new[]
     {
         DbaseField.CreateNumberField(new DbaseFieldName(nameof(Id)), new DbaseFieldLength(4), new DbaseDecimalCount(0))
     };
 }
        public void CreateDoubleFieldThrowsWhenDecimalCountGreaterThanZeroAndLengthSmallerThan3(int smallerThan3)
        {
            var name         = _fixture.Create <DbaseFieldName>();
            var length       = new DbaseFieldLength(smallerThan3);
            var decimalCount = new DbaseDecimalCount(1);

            Assert.Throws <ArgumentException>(() => DbaseField.CreateNumberField(
                                                  name,
                                                  length,
                                                  decimalCount));
        }
        public void CreateDoubleFieldThrowsWhenDecimalCountGreaterThanOrEqualToLength(int plus)
        {
            var name         = _fixture.Create <DbaseFieldName>();
            var length       = _fixture.GenerateDbaseDoubleLength();
            var decimalCount = new DbaseDecimalCount(length.ToInt32()).Plus(new DbaseDecimalCount(plus));

            Assert.Throws <ArgumentException>(() => DbaseField.CreateNumberField(
                                                  name,
                                                  length,
                                                  decimalCount));
        }
        public void AcceptsInt16ValueReturnsExpectedResult(int length, short value, bool accepted)
        {
            var sut = new DbaseNumber(
                DbaseField.CreateNumberField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length),
                    new DbaseDecimalCount(0)
                    ));

            var result = sut.AcceptsValue(value);

            Assert.Equal(accepted, result);
        }
        public void TrySetValueAsNullableInt16ReturnsExpectedResult(int length, short?value, bool expected)
        {
            var sut = new DbaseNumber(
                DbaseField.CreateNumberField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length),
                    new DbaseDecimalCount(0)
                    ));

            var result = sut.TrySetValueAsNullableInt16(value);

            Assert.Equal(expected, result);
        }
        public void TryGetValueAsInt32ReturnsExpectedResult(int length, double?value, bool gotten, int gottenValueAsInt32)
        {
            var sut = new DbaseNumber(
                DbaseField.CreateNumberField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length),
                    new DbaseDecimalCount(0)
                    ), value);

            var result = sut.TryGetValueAsInt32(out var valueAsInt32);

            Assert.Equal(gotten, result);
            Assert.Equal(gottenValueAsInt32, valueAsInt32);
        }
        public void SetValueAsNullableInt16ReturnsExpectedResult(int length, short?value, bool expected)
        {
            var sut = new DbaseNumber(
                DbaseField.CreateNumberField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length),
                    new DbaseDecimalCount(0)
                    ));

            if (!expected)
            {
                Assert.Throws <FormatException>(() =>
                {
                    sut.ValueAsNullableInt16 = value;
                });
            }
            else
            {
                sut.ValueAsNullableInt16 = value;
            }
        }
        public void GetValueAsNullableInt16ReturnsExpectedResult(int length, double?value, bool gotten, short?gottenValueAsInt16)
        {
            var sut = new DbaseNumber(
                DbaseField.CreateNumberField(
                    _fixture.Create <DbaseFieldName>(),
                    new DbaseFieldLength(length),
                    new DbaseDecimalCount(0)
                    ), value);

            if (!gotten)
            {
                Assert.Throws <FormatException>(() =>
                {
                    var _ = sut.ValueAsNullableInt16;
                });
            }
            else
            {
                var result = sut.ValueAsNullableInt16;
                Assert.Equal(gottenValueAsInt16, result);
            }
        }