Пример #1
0
        public void UpperCaseConverter_Convert_Success()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "ABC", new List <string>()
                      {
                          "XYZ"
                      } }
                },
                Properties = new Dictionary <string, string>()
            };
            var converter = new AllUpperCaseConverter();

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("ABC", "foobar");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            convertedPoint["XYZ"].Should().Equals("FOOBAR");
        }
Пример #2
0
        public void ConvertExternalImageWithCenterAlign()
        {
            var wikiText      = "{{ https://www.example-test.com/images/bla11/dokuwiki-128.png }}";
            var configuration = new ConverterConfiguration();

            configuration.ImageCenterAlignCssClass = "media-center";
            Assert.AreEqual("<img src=\"https://www.example-test.com/images/bla11/dokuwiki-128.png\" class=\"media-center\">", Converter.Convert(wikiText, configuration));
        }
Пример #3
0
        /// <summary>
        /// Extension method to register MConverter in app
        /// </summary>
        /// <param name="services">Service collection <see cref="IServiceCollection"/></param>
        /// <param name="config"><see cref="IMConverterConfiguration" configuration delegate/></param>
        /// <returns><see cref="IServiceCollection"/></returns>
        public static IServiceCollection AddMConverter(this IServiceCollection services, Action <IMConverterConfiguration> config)
        {
            var configuration = new ConverterConfiguration(services);

            config(configuration);

            return(services
                   .AddSingleton <IConverter>((x) => new Implementation.MConverter(x, configuration.Factory)));
        }
Пример #4
0
        public void ConvertWikiImageSimple()
        {
            var configuration = new ConverterConfiguration();

            configuration.ImagesBaseUrl = "http://www.testserver.test/images";
            var wikiText = "{{wiki:dokuwiki-128.png}}";

            Assert.AreEqual("<img src=\"http://www.testserver.test/images/dokuwiki-128.png\">", Converter.Convert(wikiText, configuration));
        }
Пример #5
0
        public void ConvertExternalImageWithRightAlignTitle()
        {
            var wikiText      = "{{ https://www.example-test.com/images/bla11/dokuwiki-128.png | Some title with czech charch řčš and dash -}}";
            var configuration = new ConverterConfiguration();

            configuration.ImageRightAlignCssClass = "media-right";
            Assert.AreEqual("<img src=\"https://www.example-test.com/images/bla11/dokuwiki-128.png\""
                            + " class=\"media-right\""
                            + " title=\"Some title with czech charch řčš and dash -\">", Converter.Convert(wikiText, configuration));
        }
Пример #6
0
 /// <summary>
 /// Configure the converter.
 /// </summary>
 /// <param name="config">The converter configuration.</param>
 public void Configure(ConverterConfiguration config)
 {
     _id = config.Id;
     _combineInputOutput = config.CombineInputOutput;
     _nestOutput         = config.NestOutput;
     _leftSideMap        = config.LeftSideMap;
     _properties         = config.Properties;
     _mapping            = config.Mapping;
     _pipedConverters    = config.PipedConverters;
 }
Пример #7
0
        public static string Convert(string wikiText, ConverterConfiguration configuration)
        {
            var nodesRenderer = new NodeListRenderer();

            nodesRenderer.ImagesBaseUrl            = configuration.ImagesBaseUrl;
            nodesRenderer.ImageLeftAlignCssClass   = configuration.ImageLeftAlignCssClass;
            nodesRenderer.ImageRightAlignCssClass  = configuration.ImageRightAlignCssClass;
            nodesRenderer.ImageCenterAlignCssClass = configuration.ImageCenterAlignCssClass;

            return(nodesRenderer.Render(new Parser().Parse(wikiText)));
        }
Пример #8
0
        public void VersionOneMapper_Map_Success()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "ABC", new List <string>()
                      {
                          "XYZ"
                      } }
                },
                Properties = new Dictionary <string, string>()
            };
            var converter = new AllUpperCaseConverter();

            converter.Configure(config);

            var converters = new Dictionary <string, IConverter>();

            converters.Add("ABC", converter);


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

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

            var mapper = new VersionOneMapper();

            mapper.Configure("1", null, "2", converters);

            mapper.Id.Should().Be("1");
            mapper.TransformerId.Should().Be("2");

            var dataPoint = new KeyValuePair <string, object>("ABC", "foobar");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var data = new List <IEntityCollection>();

            data.Add(dataRow);

            var convertedData = mapper.Map(data);

            convertedData.Should().NotBeNull();
        }
Пример #9
0
        private static ConverterConfiguration CopyConfig(ConverterConfiguration config)
        {
            var newConfig = new ConverterConfiguration()
            {
                Id          = config.Id,
                LeftSideMap = config.LeftSideMap,
                Type        = config.Type,
            };

            foreach (var key in config.Properties.Keys)
            {
                newConfig.Properties.Add(key, config.Properties[key]);
            }
            return(newConfig);
        }
Пример #10
0
        private static ConverterConfiguration CopyConfig(ConverterConfiguration config)
        {
            var newConfig = new ConverterConfiguration()
            {
                Id                 = config.Id,
                LeftSideMap        = config.LeftSideMap,
                CombineInputOutput = config.CombineInputOutput,
                DataType           = config.DataType,
                NestOutput         = config.NestOutput,
                Type               = config.Type
            };

            foreach (var key in config.Properties.Keys)
            {
                newConfig.Properties.Add(key, config.Properties[key]);
            }
            return(newConfig);
        }
Пример #11
0
        public void NoOpConverter_NoLeftSideMap_Convert_Success()
        {
            var config = new ConverterConfiguration()
            {
                Properties = new Dictionary <string, string>()
            };
            var converter = new NoOpConverter();

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("ABC", "123");
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);

            convertedPoint.Should().NotBeNull();
            convertedPoint["ABC"].Should().Equals("123");
        }
Пример #12
0
        public void NetworkConverter_Convert_Success()
        {
            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "MacAddress", new List <string>()
                      {
                          "NetworkCard"
                      } }
                },
                Properties = new Dictionary <string, string>()
            };

            config.Properties.Add("IP Address", "IPAddress");

            var converter = new NetworkConverter();

            converter.Configure(config);

            var macDataPoint = new KeyValuePair <string, object>("MacAddress", "00:11:22:33:44:55");
            var data         = new EntityCollection();

            data.Entities.Add(macDataPoint.Key, macDataPoint.Value);

            var ipDataPoint = new KeyValuePair <string, object>("IPAddress", "1.2.3.4");

            data.Entities.Add(ipDataPoint.Key, ipDataPoint.Value);

            var convertedPoints = converter.Convert(macDataPoint, data);

            convertedPoints.Should().NotBeNull();

            var networkCard = convertedPoints["NetworkCard"] as NetworkCard;

            networkCard.MacAddress.Should().Equals("00:11:22:33:44:55");
            networkCard.IPAddress.Should().Equals("1.2.3.4");
        }
Пример #13
0
        public void DateTimeUtcConverter_ExactFormatCases()
        {
            const string timeZoneId     = "50";
            const string dateTimeFormat = "HH:mm zzz";
            const string time           = "09:01+01:00";

            var config = new ConverterConfiguration()
            {
                LeftSideMap = new Dictionary <string, List <string> >()
                {
                    { "DateTime", new List <string>()
                      {
                          "DateTime"
                      } }
                },
                Properties = new Dictionary <string, string>()
                {
                    { "TimeZone", timeZoneId }, { "DateTimeFormat", dateTimeFormat }
                }
            };
            var converter = new DateTimeUtcConverter(new MockLogger());

            converter.Configure(config);

            var dataPoint = new KeyValuePair <string, object>("DateTime", time);
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var convertedPoint = converter.Convert(dataPoint, dataRow);
            var dateTime       = DateTime.ParseExact(time, dateTimeFormat, null, DateTimeStyles.AllowWhiteSpaces | DateTimeStyles.NoCurrentDateDefault);

            dateTime = dateTime.ToUniversalTime();
            var expectedValue = dateTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK");

            convertedPoint.Should().NotBeNull();
            Assert.AreEqual(expectedValue, convertedPoint["DateTime"].ToString());
        }
Пример #14
0
        private Dictionary <string, IConverter> CreateConverters()
        {
            var config1 = new ConverterConfiguration()
            {
                Id = ID_CONVERTER_1
            };
            var converter1 = new CombineDateTimeConverter(new MockLogger());

            converter1.Configure(config1);

            var config2 = new ConverterConfiguration()
            {
                Id = ID_CONVERTER_2
            };
            var converter2 = new DateTimeUtcConverter(new MockLogger());

            converter2.Configure(config2);

            var converters = new Dictionary <string, IConverter>();

            converters.Add(ID_CONVERTER_1, converter1);
            converters.Add(ID_CONVERTER_2, converter2);
            return(converters);
        }
Пример #15
0
        public void DictionaryMapper_Success()
        {
            var converters       = new Dictionary <string, IConverter>();
            var converterConfig1 = new ConverterConfiguration()
            {
                Id = ID_CONVERTER_1,
            };
            var converter1 = new AllUpperCaseConverter();

            converter1.Configure(converterConfig1);
            converters.Add(converter1.Id, converter1);

            var leftSideMap1 = new Dictionary <string, List <string> >()
            {
                { "FirstName", new List <string>()
                  {
                      "FirstName"
                  } }
            };

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

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

            targetMappings.Add(new SourceTargetMapping()
            {
                PrimaryKey       = "FirstName",
                TargetConverters = targetConverters
            });
            var mapperConfig = new MapperConfiguration()
            {
                Id                   = "1234",
                TransformerId        = "6678",
                SourceTargetMappings = targetMappings,
                DataType             = TYPE_MOCKUSER
            };
            var mapper = new DictionaryMapper();

            mapper.Configure(mapperConfig, converters);

            var dataToConvert = new Dictionary <string, object>()
            {
                { "FirstName", "Jane" },
                { "LastName", "Doe" },
                { "Email", "*****@*****.**" },
                { "LastLogin", "06-25-2018 09:03:45.123456" }
            };
            var dataPoint = new KeyValuePair <string, object>("AD User", dataToConvert);
            var dataRow   = new EntityCollection();

            dataRow.Entities.Add(dataPoint.Key, dataPoint.Value);

            var data = mapper.Map(new List <IEntityCollection> {
                dataRow
            });

            data.Count.Should().Be(1);
            var user = data[0] as MockUser;

            user.FirstName.Should().Be("JANE");
        }
Пример #16
0
 public CustomerBuilder(ConverterConfiguration configuration)
 {
     this.configuration = configuration;
 }
Пример #17
0
 public GroupsBuilder(ConverterConfiguration configuration)
 {
     this.configuration = configuration;
 }
Пример #18
0
        public void PipedConverters_PipedArray_Success()
        {
            // Use Case: A data point contains an array of objects (software items).
            // The PipedArrayConverter uses reflection to get each field, convert the field based on
            // the configured converters for the associated source target mapping.
            // The converter returns a dictionary of dictionaries based on an id.
            // The id is determined in the SourceTargetConverter property "ArrayKey".
            // The property "PrefixId" means to prefix the id with the "ArrayKey", i.e. "Id_XXX"
            // where XXX is the Id field of the software.
            var items = CreateMockSoftwareArray();
            var row   = new EntityCollection();

            row.Entities.Add("Items", items);

            var properties = new Dictionary <string, string>();

            properties.Add("ArrayKey", "Id");
            properties.Add("PrefixId", "true");

            var targetConverters = new List <SourceTargetConverter>();
            var mapping          = new SourceTargetMapping()
            {
                //PipeData = true,
                Properties       = properties,
                PrimaryKey       = "Items",
                TargetConverters = targetConverters
            };
            var noOpConverter = new NoOpConverter();
            var leftSideMap   = new Dictionary <string, List <string> >();

            leftSideMap.Add("Id", new List <string>()
            {
                "Id"
            });
            leftSideMap.Add("Title", new List <string>()
            {
                "Title"
            });
            leftSideMap.Add("DateTime", new List <string>()
            {
                "DateTime"
            });
            var noOpConfig = new ConverterConfiguration()
            {
                Id          = "1",
                LeftSideMap = leftSideMap
            };

            noOpConverter.Configure(noOpConfig);

            var converters = new List <IConverter>();

            converters.Add(noOpConverter);

            var converter = new PipedArrayConverter();

            converters.Add(converter);

            var config = new ConverterConfiguration()
            {
                Id              = "2",
                Mapping         = mapping,
                PipedConverters = converters,
                Properties      = properties
            };

            converter.Configure(config);
            var convertedData = converter.Convert(new KeyValuePair <string, object>("Items", items), row);

            convertedData.Count.Should().Be(2);

            foreach (var id in convertedData.Keys)
            {
                if (id.Contains("_pkAttrName"))
                {
                    continue;
                }
                var software  = convertedData[id] as List <object>;
                var software0 = software[0] as Dictionary <string, object>;
                software0["Id"].Should().Be("1");
                software0["Title"].Should().Be("Some Software Title #1");
                software0["DateTime"].Should().NotBeNull();
                var software1 = software[1] as Dictionary <string, object>;
                software1["Id"].Should().Be("2");
                software1["Title"].Should().Be("Some Software Title #2");
                software1["DateTime"].Should().NotBeNull();
            }
        }
Пример #19
0
 public Worker(ConverterConfiguration configuration)
 {
     this.configuration = configuration;
 }
Пример #20
0
        /// <summary>
        /// Convert a single data point.
        /// </summary>
        /// <param name="dataPoint">The data point to convert</param>
        /// <param name="dataRow">The associated row data points</param>
        /// <returns>A dictionary of converted data.</returns>
        public Dictionary <string, object> ConvertDataPoint(KeyValuePair <string, object> dataPoint, IEntityCollection dataRowIn)
        {
            Dictionary <string, object> result = null;
            var mapping = FindMapping(dataPoint.Key);

            if (mapping != null)
            {
                // make our local copy of the data row, we may need to manipulate it for nested conversions.
                var dataRow = new EntityCollection();
                foreach (var e in dataRowIn.Entities)
                {
                    dataRow.Entities.Add(e.Key, e.Value);
                }
                var converters = new List <IConverter>();
                // first configure all of the trageted converters,
                // this in case a piped converter wants to run the other converters internally
                foreach (var targetConverter in mapping.TargetConverters)
                {
                    if (Converters.ContainsKey(targetConverter.Id))
                    {
                        var mergedProperties = MergeProperties(Converters[targetConverter.Id].Properties, targetConverter.Properties);
                        mergedProperties = MergeProperties(mergedProperties, mapping.Properties);
                        var config = new ConverterConfiguration()
                        {
                            Id = targetConverter.Id,
                            CombineInputOutput = targetConverter.CombineInputOutput,
                            NestOutput         = targetConverter.NestOutput,
                            LeftSideMap        = targetConverter.LeftSideMap,
                            Properties         = mergedProperties,
                            PipedConverters    = converters,
                            Mapping            = mapping
                        };
                        IConverter converter = CollectorFactory.CloneConverter(Converters[targetConverter.Id]);
                        if (converter != null)
                        {
                            converter.Configure(config);
                            converters.Add(converter);
                        }
                    }
                }
                Dictionary <string, object> convertedDataPoints = null;
                foreach (var targetConverter in mapping.TargetConverters)
                {
                    IConverter converter = MatchTargetConverter(dataPoint.Key, targetConverter, converters);
                    if (converter != null)
                    {
                        Dictionary <string, object> convertedDataPointsOut = null;
                        if (convertedDataPoints != null)
                        {
                            convertedDataPointsOut = converter.Convert(convertedDataPoints, dataRow);
                        }
                        else
                        {
                            convertedDataPointsOut = converter.Convert(dataPoint, dataRow);
                            // If we need to combine input and output, and this is our first converter.
                            // Otherwise the data point will be lost.
                            if (targetConverter.CombineInputOutput)
                            {
                                convertedDataPoints = new Dictionary <string, object>();
                                convertedDataPoints.Add(dataPoint.Key, dataPoint.Value);
                            }
                        }
                        convertedDataPoints = CombineData(targetConverter.CombineInputOutput, convertedDataPoints, convertedDataPointsOut);
                        if (targetConverter.NestOutput)
                        {
                            convertedDataPointsOut = NestedConversion(convertedDataPoints, dataRow);
                            convertedDataPoints    = CombineData(targetConverter.CombineInputOutput, convertedDataPoints, convertedDataPointsOut);
                        }
                        if (!targetConverter.Pipe)
                        {
                            break;
                        }
                    }
                }
                result = convertedDataPoints;
            }
            return(result);
        }
Пример #21
0
 public ProductsBuilder(ConverterConfiguration configuration)
 {
     this.configuration = configuration;
 }
Пример #22
0
 public SellersBuilder(ConverterConfiguration configuration)
 {
     this.configuration = configuration;
 }