protected override void Context()
        {
            _element = new XElement("Root",
                                    new XElement("Container1",
                                                 new XElement("Parameter1", new XAttribute(Constants.Serialization.Attribute.Dimension, "OldDim1")),
                                                 new XElement("Parameter2", new XAttribute(Constants.Serialization.Attribute.Dimension, "Dim1"))),
                                    new XElement("Container2",
                                                 new XElement("Parameter3", new XAttribute(Constants.Serialization.Attribute.Dimension, "OldDim2")),
                                                 new XElement("Parameter4", new XAttribute(Constants.Serialization.Attribute.Dimension, "Dim2"))));

            _dimensionMapper         = A.Fake <IDimensionMapper>();
            _parameterConverter      = A.Fake <IParameterConverter>();
            _usingFormulaConverter   = A.Fake <IUsingFormulaConverter>();
            _dataRepositoryConverter = A.Fake <IDataRepositoryConverter>();
            A.CallTo(() => _dimensionMapper.DimensionNameFor("OldDim1", false)).Returns("NewDim1");
            A.CallTo(() => _dimensionMapper.DimensionNameFor("Dim1", false)).Returns("Dim1");
            A.CallTo(() => _dimensionMapper.DimensionNameFor("OldDim2", false)).Returns("NewDim2");
            A.CallTo(() => _dimensionMapper.DimensionNameFor("Dim2", false)).Returns("Dim2");
            sut = new DimensionConverter(_dimensionMapper, _parameterConverter, _usingFormulaConverter, _dataRepositoryConverter);
        }
Exemple #2
0
        public void ConvertDimensionIn(XElement element)
        {
            //retrieve all elements with an attribute dimension
            var allDimensionAttributes = from child in element.DescendantsAndSelf()
                                         where child.HasAttributes
                                         let attr = child.Attribute(Constants.Serialization.Attribute.Dimension) ?? child.Attribute("dimension")
                                                    where attr != null
                                                    select attr;


            var allMappedDimensionIds = new HashSet <string>();

            foreach (var attribute in allDimensionAttributes)
            {
                string attributeValue = attribute.Value;
                int    id;
                if (int.TryParse(attribute.Value, out id))
                {
                    allMappedDimensionIds.Add(attributeValue);
                }
                else
                {
                    attribute.SetValue(_dimensionMapper.DimensionNameFor(attributeValue));
                }
            }


            var allMapAttributes = from child in element.Descendants(Constants.Serialization.STRING_MAP)
                                   let id = child.Attribute(Constants.Serialization.Attribute.ID)
                                            where allMappedDimensionIds.Contains(id.Value)
                                            select child.Attribute(Constants.Serialization.Attribute.STRING);

            foreach (var attribute in allMapAttributes)
            {
                attribute.SetValue(_dimensionMapper.DimensionNameFor(attribute.Value));
            }
        }