Esempio n. 1
0
        public void NoOpConverter_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 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["XYZ"].Should().Equals("123");
        }
Esempio n. 2
0
        public void ConvertNoOp()
        {
            var t_Converter = new NoOpConverter();
            var t_NoOp      = t_Converter.Convert(new OperationDTO(0));

            t_NoOp.Should().BeOfType <NoOp>();
        }
Esempio n. 3
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();
            }
        }