Esempio n. 1
0
        public void NewLine()
        {
            // Arrange
            string[]        data     = { "asdf", "wxyz", "qwerty" + Environment.NewLine };
            Stream          stream   = new MemoryStream();
            string          expected = "asdf,wxyz,\"qwerty" + Environment.NewLine + "\"" + Environment.NewLine;
            CsvStreamWriter writer   = new CsvStreamWriter(stream);

            // Act
            writer.WriteRecord(data);
            writer.Flush();
            stream.Position = 0;
            string result = new StreamReader(stream).ReadToEnd();

            // Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 2
0
        public void TestStream()
        {
            var stream = StreamHelper.GenerateStream(string.Empty);

            using (var writer = new CsvStreamWriter <TestModel>(stream)) {
                var model = new TestModel()
                {
                    Name = "Doe, Jon",
                    Type = TestType.Attachment,
                    Cost = 50,
                    Id   = 1,
                    Date = DateTime.Now
                };
                writer.WriteLine(model);
                writer.Flush();

                var reader = new StreamReader(stream);
                var result = reader.ReadToEnd();

                Assert.AreEqual($"\"{model.Name}\",{model.Type},{model.Cost},{model.Id},{model.Date}\r\n", result);
            }
        }