public void CanReadWriteWithMaxDecimalCount() { var length = DbaseNumber.MaximumLength; var decimalCount = DbaseNumber.MaximumDecimalCount; var sut = new DbaseNumber( 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 DbaseNumber(sut.Field); result.Read(reader); Assert.Equal(sut.Field, result.Field); Assert.Equal(sut.Value, result.Value); } } } }
public void WritesExcessDecimalsAsZero() { var length = _fixture.GenerateDbaseDoubleLength(); var decimalCount = _fixture.GenerateDbaseDoubleDecimalCount(length); var sut = new DbaseNumber( new DbaseField( _fixture.Create <DbaseFieldName>(), DbaseFieldType.Number, _fixture.Create <ByteOffset>(), length, decimalCount ), 0.0); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, true)) { sut.Write(writer); writer.Flush(); } stream.Position = 0; if (decimalCount.ToInt32() == 0) { Assert.Equal( "0".PadLeft(length.ToInt32()), Encoding.ASCII.GetString(stream.ToArray())); } else { Assert.Equal( new string(' ', length.ToInt32() - decimalCount.ToInt32() - 2) + "0." + new string('0', decimalCount.ToInt32()), Encoding.ASCII.GetString(stream.ToArray()) ); } } }
public void CanReadWriteNegative() { using (var random = new PooledRandom()) { var sut = new DbaseNumber( new DbaseField( _fixture.Create <DbaseFieldName>(), DbaseFieldType.Number, _fixture.Create <ByteOffset>(), DbaseNumber.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 DbaseNumber(sut.Field); result.Read(reader); Assert.Equal(sut, result, new DbaseFieldValueEqualityComparer()); } } } }