public void Read_detailed_file() { // Arrange var io = new AbaFileIO(); var data = new StringBuilder(); data.AppendLine("0 01WBC John Citizen 001234PAYROLL 300715 "); data.AppendLine("1000-000 00-1234N500000123456Citizen. John Michael 5550033890123456 999-999 43-2100COMMBANK 00012340"); data.AppendLine("7999-999 000012345600001234560000000000 000001 "); var path = Path.GetTempFileName(); using (var stream = File.CreateText(path)) stream.Write(data.ToString()); // Act var file = io.Read(path); // Assert Assert.IsNotNull(file); Assert.IsNotNull(file.DescriptiveRecord); Assert.IsNotNull(file.DetailRecords); Assert.AreEqual(1, file.DetailRecords.Count); Assert.IsNotNull(file.FileTotalRecord); File.Delete(path); }
public void Read_detailed_stream() { // Arrange var data = new StringBuilder(); data.AppendLine("0 01WBC John Citizen 001234PAYROLL 300715 "); data.AppendLine("1000-000 00-1234N500000123456Citizen. John Michael 5550033890123456 999-999 43-2100COMMBANK 00012340"); data.AppendLine("7999-999 000012345600001234560000000000 000001 "); var io = new AbaFileIO(); var stream = new MemoryStream(); var writer = new StreamWriter(stream) { AutoFlush = true }; writer.Write(data.ToString()); stream.Position = 0; var reader = new StreamReader(stream); // Act var file = io.Read(reader); // Assert Assert.IsNotNull(file); Assert.IsNotNull(file.DescriptiveRecord); Assert.IsNotNull(file.DetailRecords); Assert.AreEqual(1, file.DetailRecords.Count); Assert.IsNotNull(file.FileTotalRecord); }
public void Read_throws_on_incorrect_record_width() { // Arrange var data = new StringBuilder(); // Incorrect record widths. data.AppendLine("0 01NAB NAB 012345DE Returns 070905 "); data.AppendLine("2082-0014587999936130000042350OWEN MELISSA 693549 633-000118309999SUNNY-PEOPLE 06337999SOME SYSTEM091118 "); data.AppendLine("7999-999 000029678200000000000000296782 000010 "); var io = new AbaFileIO(); var stream = new MemoryStream(); var writer = new StreamWriter(stream) { AutoFlush = true }; writer.Write(data.ToString()); stream.Position = 0; var reader = new StreamReader(stream); // Act - done by assertion, below. // Assert Assert.That(() => io.Read(reader), Throws.Exception); }
public void Read_returns_stream() { // Arrange var data = new StringBuilder(); data.AppendLine("0 01NAB NAB 012345DE Returns 070905 "); data.AppendLine("2082-0014587999935130000018622THOMPSON SARAH 694609 062-184010479999SUNNY-PEOPLE 06337999"); data.AppendLine("2082-0014587999936130000042350OWEN MELISSA 693549 633-000118309999SUNNY-PEOPLE 06337999"); data.AppendLine("7999-999 000029678200000000000000296782 000010 "); var io = new AbaFileIO(); var stream = new MemoryStream(); var writer = new StreamWriter(stream) { AutoFlush = true }; writer.Write(data.ToString()); stream.Position = 0; var reader = new StreamReader(stream); // Act var file = io.Read(reader); // Assert Assert.IsNotNull(file); Assert.IsNotNull(file.DescriptiveRecord); Assert.IsNotNull(file.DetailRecords); Assert.AreEqual(2, file.DetailRecords.Count); Assert.IsTrue(file.DetailRecords.All(r => r is ReturnsDetailRecord)); Assert.AreEqual(ReturnCode.NoAccountOrIncorrectAccountNumber, ((ReturnsDetailRecord)file.DetailRecords[0]).ReturnCode); Assert.AreEqual(ReturnCode.ReferToCustomer, ((ReturnsDetailRecord)file.DetailRecords[1]).ReturnCode); Assert.IsNotNull(file.FileTotalRecord); }