예제 #1
0
        public void DefaultMapper_NoPipeConverters_Map_Success()
        {
            // Use Case : I want to first combine a date and time field.  Then pipe
            // that result into the UTC converter along with the original data point.
            // Because PipedData is set to false then the end result should be two entries.
            // 1. Combined Date and Time
            // 2. Combined Date and Time converted to UTC.

            var converters = CreateConverters();

            var collector = new MockCollector(new MockLogger());

            collector.Configure(new CollectorConfiguration()
            {
                Id      = "1",
                Version = 2.0
            });

            var mapper = new DefaultMapper(new MockLogger(), collector);

            var leftSideMap1 = new Dictionary <string, List <string> >()
            {
                { "Date", new List <string>()
                  {
                      "DateTime"
                  } }
            };
            var leftSideMap2 = new Dictionary <string, List <string> >()
            {
                { "DateTime", new List <string>()
                  {
                      "DateTimeUTC"
                  } }
            };

            // Create the converters we are targeting
            var targetConverters = new List <SourceTargetConverter>();

            targetConverters.Add(new SourceTargetConverter()
            {
                Id = ID_CONVERTER_1, LeftSideMap = leftSideMap1, CombineInputOutput = false
            });
            targetConverters.Add(new SourceTargetConverter()
            {
                Id = ID_CONVERTER_2, LeftSideMap = leftSideMap2, CombineInputOutput = true
            });
            // Now create the targeted mapping
            var targetMappings = new List <SourceTargetMapping>();

            targetMappings.Add(new SourceTargetMapping()
            {
                PrimaryKey       = "Date",
                TargetConverters = targetConverters
            });
            // Finally create the mapper config and configure the mapper
            var mapperConfig = new MapperConfiguration()
            {
                Id                   = "1234",
                TransformerId        = "6678",
                SourceTargetMappings = targetMappings
            };

            mapper.Configure(mapperConfig, converters);

            mapper.Id.Should().Be("1234");
            mapper.TransformerId.Should().Be("6678");

            var dataRow = new EntityCollection();

            dataRow.Entities.Add("Date", "1/17/2018");
            dataRow.Entities.Add("Time", "15:46:07.000");

            var data = new List <IEntityCollection>();

            data.Add(dataRow);

            var convertedData = mapper.Map(data);

            convertedData.Should().NotBeNull();
            convertedData.Count.Should().Be(1);

            var entities = convertedData[0] as IEntityCollection;

            entities.Entities.Count.Should().Be(2);
            entities.Entities.ContainsKey("DateTimeUTC").Should().BeTrue();

            var dateTime         = DateTime.Parse(entities.Entities["DateTimeUTC"].ToString());
            var expectedDateTime = DateTime.Parse("1/17/2018 15:46:07.000");

            dateTime.Month.Should().Be(expectedDateTime.Month);
            dateTime.Day.Should().Be(expectedDateTime.Day);
            dateTime.Year.Should().Be(expectedDateTime.Year);
            dateTime.Hour.Should().Be(expectedDateTime.Hour);
            dateTime.Minute.Should().Be(expectedDateTime.Minute);
        }