<commit_before>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.IO;
using TableIO.PropertyMappers;

namespace TableIO.Tests
{
    [TestClass]
    public class TableFactoryTests
    {
        class Model
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public decimal Price { get; set; }
            public string Remarks { get; set; }
        }

        [TestMethod]
        public void ReadCsv()
        {
            using (var stmReader = new StreamReader("files\\Valid.csv"))
            {
                var csvReader = new TableFactory().CreateCsvReader<Model>(stmReader, true);
                var models = csvReader.Read();

                Assert.AreEqual(5, models.Count);

                var model = models[3];
                Assert.AreEqual(4, model.Id);
                Assert.AreEqual("name \"4\"", model.Name);
                Assert.AreEqual(4000, model.Price);
                Assert.AreEqual("remarks4\nremarks4", model.Remarks);
            }
        }

        [TestMethod]
        public void ReadCsv_ManualIndex()
        {
            var mapper = new ManualIndexPropertyMapper<Model>()
                .Map(m => m.Id, 2)
                .Map(m => m.Name, 3);

            using (var stmReader = new StreamReader("files\\Valid.csv"))
            {
                var csvReader = new TableFactory().CreateCsvReader<Model>(stmReader, true, propertyMapper:mapper);
                var models = csvReader.Read();

                Assert.AreEqual(5, models.Count);

                var model = models[3];

                Assert.AreEqual(4000, model.Id);
                Assert.AreEqual("remarks4\nremarks4", model.Name);
                // no set
                Assert.AreEqual(0, model.Price);
                Assert.AreEqual(null, model.Remarks);
            }
        }

        [TestMethod]
        public void CopyCsv()
        {
            IList<Model> models = null;
            using (var stmReader = new StreamReader("files\\Valid.csv"))
            {
                var csvReader = new TableFactory().CreateCsvReader<Model>(stmReader, true);
                models = csvReader.Read();<commit_msg>fix failed test<commit_after>﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.IO;
using TableIO.PropertyMappers;

namespace TableIO.Tests
{
    [TestClass]
    public class TableFactoryTests
    {
        class Model
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public decimal Price { get; set; }
            public string Remarks { get; set; }
        }

        [TestMethod]
        public void ReadCsv()
        {
            using (var stmReader = new StreamReader("files\\Valid.csv"))
            {
                var csvReader = new TableFactory().CreateCsvReader<Model>(stmReader, true);
                var models = csvReader.Read();

                Assert.AreEqual(5, models.Count);

                var model = models[3];
                Assert.AreEqual(4, model.Id);
                Assert.AreEqual("name \"4\"", model.Name);
                Assert.AreEqual(4000, model.Price);
                Assert.AreEqual("remarks4\r\nremarks4", model.Remarks);
            }
        }

        [TestMethod]
        public void ReadCsv_ManualIndex()
        {
            var mapper = new ManualIndexPropertyMapper<Model>()
                .Map(m => m.Id, 2)
                .Map(m => m.Name, 3);

            using (var stmReader = new StreamReader("files\\Valid.csv"))
            {
                var csvReader = new TableFactory().CreateCsvReader<Model>(stmReader, true, propertyMapper:mapper);
                var models = csvReader.Read();

                Assert.AreEqual(5, models.Count);

                var model = models[3];

                Assert.AreEqual(4000, model.Id);
                Assert.AreEqual("remarks4\r\nremarks4", model.Name);
                // no set
                Assert.AreEqual(0, model.Price);
                Assert.AreEqual(null, model.Remarks);
            }
        }

        [TestMethod]
        public void CopyCsv()
        {
            IList<Model> models = null;
            using (var stmReader = new StreamReader("files\\Valid.csv"))
            {
                var csvReader = new TableFactory().CreateCsvReader<Model>(stmReader, true);
                models = csvReader.Read();
{'fraction_non_alphanumeric': 0.10873440285204991, 'fraction_numerical': 0.009358288770053475, 'mean_word_length': 1.6114019778941244, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '807826', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1176, 'n_words': 259}