public void WriteOneHasExpectedResult() { var expectedHeader = _fixture.Create <DbaseFileHeader>(); var expectedRecord = _fixture.GenerateDbaseRecord(expectedHeader.Schema.Fields); using (var stream = new MemoryStream()) { using (var sut = new DbaseBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true))) { //Act sut.Write(expectedRecord); } // Assert stream.Position = 0; using (var reader = new BinaryReader(stream, Encoding.ASCII, true)) { var actualHeader = DbaseFileHeader.Read(reader); var actualRecord = new AnonymousDbaseRecord(actualHeader.Schema.Fields); actualRecord.Read(reader); var actualEndOfFile = reader.ReadByte(); Assert.Equal(expectedHeader, actualHeader); Assert.Equal(expectedRecord, actualRecord, new DbaseRecordEqualityComparer()); Assert.Equal(DbaseRecord.EndOfFile, actualEndOfFile); } } }
public void WriteOneRecordCanNotBeNull() { var expectedHeader = _fixture.Create <DbaseFileHeader>(); using (var stream = new MemoryStream()) { using (var sut = new DbaseBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true))) { Assert.Throws <ArgumentNullException>(() => sut.Write((DbaseRecord)null)); } } }
public void WritManyWhenDisposedHasExpectedResult() { var expectedHeader = _fixture.Create <DbaseFileHeader>(); var records = _fixture.GenerateDbaseRecords(expectedHeader.Schema.Fields, expectedHeader.RecordCount); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, true)) using (var sut = new DbaseBinaryWriter(expectedHeader, writer)) { //Act sut.Dispose(); Assert.Throws <ObjectDisposedException>(() => sut.Write(records)); } } }
public void WriteManyHasExpectedResult() { var expectedHeader = _fixture.Create <DbaseFileHeader>(); var expectedRecords = _fixture.GenerateDbaseRecords(expectedHeader.Schema.Fields, expectedHeader.RecordCount); using (var stream = new MemoryStream()) { using (var sut = new DbaseBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true))) { //Act foreach (var expectedRecord in expectedRecords) { sut.Write(expectedRecord); } } // Assert stream.Position = 0; using (var reader = new BinaryReader(stream, Encoding.ASCII, true)) { var actualHeader = DbaseFileHeader.Read(reader); var actualRecords = new DbaseRecord[actualHeader.RecordCount.ToInt32()]; for (var index = 0; index < actualRecords.Length; index++) { var actualRecord = new AnonymousDbaseRecord(actualHeader.Schema.Fields); actualRecord.Read(reader); actualRecords[index] = actualRecord; } var actualEndOfFile = reader.ReadByte(); Assert.Equal(expectedHeader, actualHeader); Assert.Equal(expectedRecords, actualRecords, new DbaseRecordEqualityComparer()); Assert.Equal(DbaseRecord.EndOfFile, actualEndOfFile); } } }