public void Open_ReadFlag_CSVReaderIsInstanciated()
        {
            var fileName = @"test_data\contacts.csv";
            var fake     = new FakeCSVReaderWriter();

            Assert.DoesNotThrow(() => fake.Open(fileName, CSVReaderWriter.Mode.Read));
            Assert.IsNotNull(fake.Reader);
        }
        public void Open_WriteFlag_CSVWriterIsInstanciated()
        {
            var fileName = @".\whatever.csv";
            var fake     = new FakeCSVReaderWriter();

            Assert.DoesNotThrow(() => fake.Open(fileName, CSVReaderWriter.Mode.Write));
            Assert.IsNotNull(fake.Writer);
        }
Exemplo n.º 3
0
        public void WriterWritesLines()
        {
            // Given a writer
            var textWriter = new StringWriter();
            var writer     = new FakeCSVReaderWriter(f => null,
                                                     f => textWriter);

            // When I write a TSV
            writer.Open("Arbitrary", CSVReaderWriter.Mode.Write);
            writer.Write("First", "Second");
            writer.Close();

            // Then the string is written
            Assert.Equal($"First\tSecond{Environment.NewLine}", textWriter.ToString());
        }
Exemplo n.º 4
0
        public void WritingNothingWritesNothing()
        {
            var textWriter = new StringWriter();
            // Given a writer
            var writer = new FakeCSVReaderWriter(f => null,
                                                 f => textWriter);

            // When I write an empty string
            writer.Open("Arbitrary", CSVReaderWriter.Mode.Write);
            writer.Write(null);
            writer.Close();

            // Then nothing is written
            Assert.True(string.IsNullOrEmpty(textWriter.ToString()));
        }
Exemplo n.º 5
0
        public void TooManyColumnsReadsFirstTwo()
        {
            // Given a reader
            var streamReader = $"First\tSecond\tThird\tFourth{Environment.NewLine}".ToStream();
            var reader       = new FakeCSVReaderWriter(f => streamReader, f => null);

            // When I read
            reader.Open("Arbitrary", CSVReaderWriter.Mode.Read);
            List <Tuple <string, string> > results = new List <Tuple <string, string> >();
            string first;
            string second;

            while (reader.Read(out first, out second))
            {
                results.Add(new Tuple <string, string>(first, second));
            }

            // Then the results are correct
            Assert.Equal(1, results.Count());
            Assert.Equal("First", results[0].Item1);
            Assert.Equal("Second", results[0].Item2);
        }