public void WriteRecord_MultipleRecordsWithRecordFormatter_RecordsAreFormattedAndWritten() { var records = new string[] { "Line 1", "Line 2", "Line 3" }; var formattedRecords = new string[] { "Formatted Line 1", "Formatted Line 2", "Formatted Line 3" }; var recordFormatter = MockRepository.GenerateMock <IRecordFormatter>(); recordFormatter.Expect(x => x.Format(Arg <object> .Is.Equal(records[0]))).Return(formattedRecords[0]).Repeat.Once(); recordFormatter.Expect(x => x.Format(Arg <object> .Is.Equal(records[1]))).Return(formattedRecords[1]).Repeat.Once(); recordFormatter.Expect(x => x.Format(Arg <object> .Is.Equal(records[2]))).Return(formattedRecords[2]).Repeat.Once(); using (var fileWriter = new MockFileWriter(this.FilePath, recordFormatter)) { fileWriter.Open(); FileWriterTests.WriteRecords(fileWriter, records); } recordFormatter.VerifyAllExpectations(); FileWriterTests.AssertFileMatches(this.FilePath, formattedRecords); }
public static void Initialize(TestContext testContext) { FixedWidthBinaryFileReaderTests.TestContext = testContext; if (!Directory.Exists(FixedWidthBinaryFileReaderTests.TestFilesDirectory)) { Directory.CreateDirectory(FixedWidthBinaryFileReaderTests.TestFilesDirectory); } FileWriterTests.Cleanup(); }
public void WriteRecord_MultipleRecords_RecordsAreWritten() { var records = new string[] { "Line 1", "Line 2", "Line 3" }; using (var fileWriter = new MockFileWriter(this.FilePath)) { fileWriter.Open(); FileWriterTests.WriteRecords(fileWriter, records); } FileWriterTests.AssertFileMatches(this.FilePath, records); }
public void WriteRecord_RecordFormatterThrowsException_ExceptionIsPropogated() { var records = new string[] { "Line 1", "Line 2", "Line 3" }; var recordFormatter = MockRepository.GenerateMock <IRecordFormatter>(); recordFormatter.Stub(x => x.Format(Arg <object> .Is.Anything)).Throw(new InternalTestFailureException()); using (var fileWriter = new MockFileWriter(this.FilePath, recordFormatter)) { fileWriter.Open(); FileWriterTests.WriteRecords(fileWriter, records); } }