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 PropertiesReturnExpectedValues() { var header = _fixture.Create <DbaseFileHeader>(); using (var writer = new BinaryWriter(new MemoryStream())) using (var sut = new DbaseBinaryWriter(header, writer)) { Assert.Same(header, sut.Header); Assert.Same(writer, sut.Writer); } }
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 DisposeHasExpectedResult() { var expectedHeader = _fixture.Create <DbaseFileHeader>(); using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, false)) using (var sut = new DbaseBinaryWriter(expectedHeader, writer)) { //Act sut.Dispose(); Assert.Throws <ObjectDisposedException>(() => writer.Write(_fixture.Create <byte>())); } } }
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); } } }