Exemple #1
0
        public void CsvCleanserTest()
        {
            var gliders = new List <Glider>()
            {
                new Glider(" Puchacz", false),
                new Glider(" Pirat ", false)
            };

            var cleanser = new FileCsvCleanser <Glider>();
            var cleansed = cleanser.Cleanse(gliders);

            Assert.AreEqual("Puchacz", cleansed[0].Type);
            Assert.AreEqual("Pirat", cleansed[1].Type);

            Assert.Pass();
        }
Exemple #2
0
        public void FullEtlOperationTest()
        {
            // Define data extractor
            List <Glider> MapExtracted(List <List <string> > x) => x
            .Select(y =>
                    new Glider(y[0], Boolean.Parse(y[1])))
            .ToList();

            var extractor = new FileCsvExtractor <Glider>("../../../Data/gliders.csv", ';', MapExtracted);

            // Define data cleanser
            var cleanser = new FileCsvCleanser <Glider>();

            // Define data transformer
            List <Szybowiec> MapTransform(List <Glider> x) => x
            .Select(y => new Szybowiec(y.Type, y.HasEngine))
            .ToList();

            var transformer = new SimpleDataTransformer <Glider, Szybowiec>(MapTransform);

            // Define data loader
            var loader = new JsonFileLoader <Szybowiec>(_jsonPath);

            // ETL operation
            var processor = new ETLProcessor <Glider, Szybowiec>(extractor, cleanser, transformer, loader);
            var result    = processor.Process();

            Assert.AreEqual(true, result.Result);


            // Check output file
            var glidersJson = File.ReadAllText(_jsonPath);

            var glidersDeserialized = JsonConvert.DeserializeObject <List <Szybowiec> >(glidersJson);

            Assert.AreEqual("Puchacz", glidersDeserialized[0].Typ);
            Assert.AreEqual("Pirat", glidersDeserialized[1].Typ);
        }