示例#1
0
 private static void WriteRecords(MockFileWriter fileWriter, string[] records)
 {
     for (var i = 0; i < records.Length; i++)
     {
         fileWriter.WriteRecord(records[i]);
     }
 }
示例#2
0
        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);
        }
示例#3
0
        public void Dispose_AfterFileOpened_FileIsClosed()
        {
            var fileWriter = new MockFileWriter(this.FilePath);

            fileWriter.Open();
            fileWriter.Dispose();

            Assert.IsTrue(fileWriter.IsFileClosed);
        }
示例#4
0
        public void Open_ValidFilePath_FileIsOpened()
        {
            using (var fileWriter = new MockFileWriter(this.FilePath))
            {
                fileWriter.Open();

                Assert.IsTrue(fileWriter.IsFileOpen);
            }
        }
示例#5
0
        public void FileShare_None_FileIsNotShared()
        {
            using (var fileWriter = new MockFileWriter(this.FilePath))
            {
                fileWriter.Open();

                File.OpenRead(this.FilePath);
            }
        }
示例#6
0
        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))
                {
                }
            }
        }
示例#7
0
        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);
        }
示例#8
0
        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);
            }
        }