Exemplo n.º 1
0
        protected void AddTranformation(BaseTransformation transformation)
        {
            int id = transformation.Instruction == null ? 0 : transformation.Instruction.ID;

            if (transformations[id] == null)
            {
                transformations[id] = new List <BaseTransformation>();
            }

            transformations[id].Add(transformation);
        }
Exemplo n.º 2
0
        public void DirectMappingWorks()
        {
            DirectMapping mapper = new DirectMapping("X");

            BaseTransformation[]        transformations = new BaseTransformation[] { };
            SingleMapping               fullMapping     = new SingleMapping(mapper, transformations);
            Dictionary <string, object> inputRow        = new Dictionary <string, object>();

            inputRow.Add("X", "a");
            object expected = "a";
            object actual   = fullMapping.GetValue(inputRow);

            Assert.AreEqual(expected, actual, "Direct transformation didn't extract correct value");
        }
Exemplo n.º 3
0
        private void CountTransformation(BaseTransformation transformation)
        {
            var name = transformation.Name;

            if (!transformationsCounts.TryGetValue(name, out Counter counter))
            {
                counter = new Counter($"Transform-{name}");

                transformationsCounts.Add(name, counter);
                Register(counter);
            }

            counter.Increment();
        }
Exemplo n.º 4
0
        public void DateMappingWorks()
        {
            TemplateMapping             mapper        = new TemplateMapping("$[Date] $[Time]");
            ConvertToDateTransformation dateTransform = new ConvertToDateTransformation("yyyy/MM/dd HH:mm:ss", false);

            BaseTransformation[]        transformations = new BaseTransformation[] { dateTransform };
            SingleMapping               fullMapping     = new SingleMapping(mapper, transformations);
            Dictionary <string, object> inputRow        = new Dictionary <string, object>();

            inputRow.Add("Date", "2017/12/14");
            inputRow.Add("Time", "12:13:00");
            object expected = new DateTime(2017, 12, 14, 12, 13, 0);
            object actual   = fullMapping.GetValue(inputRow);

            Assert.AreEqual(expected, actual, "Date transformation didn't extract correct value");
        }
Exemplo n.º 5
0
        public void FullMappingWorks()
        {
            DirectMapping mapper = new DirectMapping("Y");

            BaseTransformation[] transformations = new BaseTransformation[] { };
            SingleMapping        singleMapping   = new SingleMapping(mapper, transformations);
            FullMapping          fullMapping     = new FullMapping();

            fullMapping.AddMapping("Z", singleMapping);
            Dictionary <string, object> inputRow = new Dictionary <string, object>();

            inputRow.Add("X", "a");
            inputRow.Add("Y", "b");
            Dictionary <string, object> expected = new Dictionary <string, object>();

            expected.Add("Z", "b");
            Dictionary <string, object> actual = fullMapping.GetRow(inputRow);

            CollectionAssert.AreEqual(expected, actual, "Full mapping didn't work as expected");
        }