private static void WriteRecords(MockFileWriter fileWriter, string[] records) { for (var i = 0; i < records.Length; i++) { fileWriter.WriteRecord(records[i]); } }
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 void Dispose_AfterFileOpened_FileIsClosed() { var fileWriter = new MockFileWriter(this.FilePath); fileWriter.Open(); fileWriter.Dispose(); Assert.IsTrue(fileWriter.IsFileClosed); }
public void Open_ValidFilePath_FileIsOpened() { using (var fileWriter = new MockFileWriter(this.FilePath)) { fileWriter.Open(); Assert.IsTrue(fileWriter.IsFileOpen); } }
public void FileShare_None_FileIsNotShared() { using (var fileWriter = new MockFileWriter(this.FilePath)) { fileWriter.Open(); File.OpenRead(this.FilePath); } }
public void FileShare_ReadWrite_FileIsShared() { using (var fileWriter = new MockFileWriter(this.FilePath, fileShare: FileShare.ReadWrite)) { fileWriter.Open(); using (var file = File.Open(this.FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { } } }
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); } }