Пример #1
0
        public void WriteRecord_OneRecordWithRecordFormatter_RecordIsFormattedAndWritten()
        {
            var records = new string[]
            {
                "Record 1"
            };

            var formattedRecords = new string[]
            {
                "Formatted Record 1"
            };

            var writeRecord     = new Action <System.IO.StreamWriter, object>((sr, r) => sr.WriteLine(r));
            var recordFormatter = MockRepository.GenerateMock <IRecordFormatter>();

            recordFormatter.Expect(x => x.Format(Arg <object> .Is.Equal(records[0]))).Return(formattedRecords[0]).Repeat.Once();

            using (var stream = new MemoryStream())
                using (var streamWriter = new MockStreamWriter(stream, writeRecord, recordFormatter))
                {
                    streamWriter.Open();

                    foreach (var record in records)
                    {
                        streamWriter.WriteRecord(record);
                    }

                    streamWriter.Commit();

                    StreamWriterTests.AssertStreamContentMatchesRecords(stream, formattedRecords);
                }

            recordFormatter.VerifyAllExpectations();
        }
Пример #2
0
        public void WriteRecord_TwoRecords_RecordsAreWritten()
        {
            var records = new string[]
            {
                "Record 1",
                "Record 2"
            };

            var writeRecord = new Action <System.IO.StreamWriter, object>((sr, r) => sr.WriteLine(r));

            using (var stream = new MemoryStream())
                using (var streamWriter = new MockStreamWriter(stream, writeRecord))
                {
                    streamWriter.Open();

                    foreach (var record in records)
                    {
                        streamWriter.WriteRecord(record);
                    }

                    streamWriter.Commit();

                    StreamWriterTests.AssertStreamContentMatchesRecords(stream, records);
                }
        }