示例#1
0
        public void RecordFormatter_GivenNullFileReader_ThrowsNullReferenceExceptionOnFileRead()
        {
            sut.IRecordFormatter sut = new sut.RecordFormatter(null);
            Assert.Throws <NullReferenceException>(
                () => sut.FormatFile(string.Empty, string.Empty, false)
                );

            Assert.Throws <NullReferenceException>(
                () => sut.FormatFile(string.Empty, string.Empty, false, false)
                );
        }
示例#2
0
        public void FormatSubRecords_GivenRecordsAndDefaultLineEndingNormalization_ReturnsExpectedRecords(
            string[] records,
            string subRecordDelimiter,
            bool removeBlankRecords,
            IEnumerable <IEnumerable <string> > expectedRecords
            )
        {
            sut.IRecordFormatter sut = new sut.RecordFormatter(null);

            var result = sut.FormatSubRecords(records, subRecordDelimiter, removeBlankRecords);

            Assert.Equal(expectedRecords, result);
        }
示例#3
0
        public void RecordFormatter_Constructor_SetsFileReader()
        {
            var reader   = new Mock <IFileReader>();
            var expected = new string[] { "Record 1", "Record 2" };

            reader.Setup(r => r.ReadFile(It.IsAny <string>())).Returns("Record 1\nRecord 2");

            sut.IRecordFormatter sut = new sut.RecordFormatter(reader.Object);

            var actual = sut.FormatFile(string.Empty, "\n", false);

            Assert.Equal(expected, actual);
        }
示例#4
0
        public void FormatRecord_GivenRecords_ReturnsExpectedRecords(
            string records,
            string recordDelimiter,
            bool removeBlankRecords,
            bool normalizeLineEndings,
            string[] expectedRecords
            )
        {
            sut.IRecordFormatter sut = new sut.RecordFormatter(null);

            var result = sut.FormatRecord(records, recordDelimiter, removeBlankRecords, normalizeLineEndings);

            Assert.Equal(expectedRecords, result);
        }
示例#5
0
        public void FormatFile_GivenFilesAndDefaultLineEndingNormalization_ReturnsExpectedRecords(
            string fileContents,
            string recordDelimiter,
            bool removeBlankRecords,
            IEnumerable <string> expectedRecords
            )
        {
            var reader = new Mock <IFileReader>();

            reader
            .Setup(r => r.ReadFile(It.IsAny <string>()))
            .Returns(fileContents);
            sut.IRecordFormatter sut = new sut.RecordFormatter(reader.Object);

            var result = sut.FormatFile(string.Empty, recordDelimiter, removeBlankRecords);

            Assert.Equal(expectedRecords, result);
        }