Exemple #1
0
        public void WBDSD_HierarchicalCodeList()
        {
            // load the DSD
            string dsdPath = Utility.GetPath("lib\\DSD_WB.xml");

            var dsd = StructureMessage.Load(dsdPath);

            // create hierarchical code list and add it to the DSD
            var hlist = new HierarchicalCodeList("MDG_Regions", "MDG");

            hlist.Name["en"] = "MDG Regions";
            dsd.HierarchicalCodeLists.Add(hlist);

            // get REF_AREA code list from the DSD and add it to the hierarchical code list
            var refAreaCodeList = dsd.CodeLists.Where(codeList => codeList.Id == "CL_REF_AREA_MDG").Single();

            hlist.AddCodeList(refAreaCodeList, "REF_AREA_MDG");

            // get parent country code
            var MDG_DEVELOPED = refAreaCodeList.Where(code => code.Id == "MDG_DEVELOPED").Single();

            // child country codes
            string[] ids          = new[] { "ALB", "AND", "AUS", "AUT", "BEL", "BIH", "BMU", "BGR", "HRV", "CAN", "CZE", "DNK", "EST", "FRO", "FIN", "FRA", "DEU", "GRC", "HUN", "ISL", "IRL", "ITA", "JPN", "LVA", "LIE", "LTU", "LUX", "MKD", "MLT", "MCO", "MNE", "NLD", "NZL", "NOR", "POL", "PRT", "ROU", "SVK", "SMR", "SVN", "SRB", "ESP", "SWE", "CHE", "GBR", "USA" };
            var      countryCodes = (from c in refAreaCodeList
                                     join cid in ids on c.Id.ToString() equals cid
                                     select c).ToList();

            // create hirarchy with parent code and child code and add it to
            // the hierarchical code list
            var hierarchy = new Hierarchy("Developed_Countries", new CodeRef(MDG_DEVELOPED, countryCodes));

            hierarchy.Name["en"] = "Developed Countries";
            hlist.Add(hierarchy);

            // create another hierarchy and add it to the hierarchical code list
            var MDG_NAFR = refAreaCodeList.Where(code => code.Id == "MDG_NAFR").Single();

            ids = new[] { "DZA", "EGY", "LBY", "MAR", "TUN" };

            countryCodes = (from c in refAreaCodeList
                            join cid in ids on c.Id.ToString() equals cid
                            select c).ToList();

            hierarchy            = new Hierarchy("MDG_NAFR", new CodeRef(MDG_NAFR, () => countryCodes));
            hierarchy.Name["en"] = "MDG Northern Africa Countries";
            hlist.Add(hierarchy);

            // save the DSD
            dsd.Save(Utility.GetPath("lib\\DSD_WB2.xml"));

            string messageText = dsd.ToString();

            var doc = XDocument.Parse(messageText);

            using (var reader = doc.CreateReader())
                Assert.IsTrue(MessageValidator.ValidateXml(reader));
        }
Exemple #2
0
        public HierarchyMap(HierarchicalCodeList hcl)
        {
            Map <bool?>(o => o.IsFinal ? true : (bool?)null).ToAttribute("isFinal", false)
            .Set(v => _hierarchy.IsFinal = v.Value)
            .Converter(new NullableBooleanConverter());

            Map(o => o.Root).ToElement("CodeRef", true)
            .Set(v => _hierarchy.Root = v)
            .ClassMap(() => new CodeRefMap(hcl));
        }
Exemple #3
0
        public void Create_HierarchicalList()
        {
            var countryCL = GetCountryCodeList();
            var regionsCL = GetRegionsCodeList();

            var hList = new HierarchicalCodeList(new InternationalString("en", "Europe"), "HCL_Europe", "SDMX");

            hList.AddCodeList(countryCL, "countryCLAlias");
            hList.AddCodeList(regionsCL, "RegionsAlias");

            Hierarchy hierarchy = new Hierarchy("id",
                                                new CodeRef(regionsCL.Get("Europe"),
                                                            new CodeRef(countryCL.Get("Germany")),
                                                            new CodeRef(countryCL.Get("UK"))));

            hList.Add(hierarchy);

            Assert.IsNotNull(hList);
            Assert.AreEqual("Europe", hList.Name["en"]);
            //Assert.AreEqual( Id("HCL_Europe"), hList.Id);
            //Assert.AreEqual(new Id("SDMX"), hList.AgencyId);
            //Assert.AreEqual(2, hList.CodeListRefs.Count());
            //var codeListRef = hList.CodeListRefs.ElementAt(0);
            //Assert.AreEqual(new Id("CL_Country"), codeListRef.Id);
            //Assert.AreEqual(new Id("SDMX"), codeListRef.AgencyId);
            //Assert.AreEqual(new Id("countryCLAlias"), codeListRef.Alias);

            //codeListRef = hList.CodeListRefs.ElementAt(1);
            //Assert.AreEqual(new Id("CL_Regions"), codeListRef.Id);
            //Assert.AreEqual(new Id("SDMX"), codeListRef.AgencyId);
            //Assert.AreEqual(new Id("RegionsAlias"), codeListRef.Alias);

            Assert.AreEqual(1, hList.Count());
            var hirchy = hList.ElementAt(0);

            //Assert.AreEqual(new Id("id"), hirchy.Id);
            Assert.AreEqual(3, hirchy.GetCodeRefs().Count());

            foreach (var codeRef in hirchy.GetCodeRefs())
            {
                Assert.IsNotNull(codeRef.CodeListRef);
                Assert.IsNotNull(codeRef.CodeListRef.Alias);
                Assert.IsTrue(codeRef.CodeListRef.Alias == "countryCLAlias" || codeRef.CodeListRef.Alias == "RegionsAlias");
            }

            var europeCode = hirchy.GetCodeRefs().Where(i => i.CodeId == "Europe").Single();

            Assert.IsNull(europeCode.Parent);
            var germany = hirchy.GetCodeRefs().Where(i => i.CodeId == "Germany").Single();
            var uk      = hirchy.GetCodeRefs().Where(i => i.CodeId == "UK").Single();

            Assert.AreSame(germany.Parent, europeCode);
            Assert.AreSame(uk.Parent, europeCode);
        }
Exemple #4
0
        public void HierarchicalList_InvalidAlias()
        {
            var hList     = new HierarchicalCodeList(new InternationalString("en", "Europe"), "HCL_Europe", "SDMX");
            var countryCL = GetCountryCodeList();
            var regionsCL = GetRegionsCodeList();

            // don't add the country code list to the hierarchy in order to throw the exception
            //hList.AddCodeList(countryCL, "countryCLAlias");
            hList.AddCodeList(regionsCL, "RegionsAlias");

            Hierarchy hierarchy = new Hierarchy("id",
                                                new CodeRef(regionsCL.Get("Europe"),
                                                            new CodeRef(countryCL.Get("Germany")),
                                                            new CodeRef(countryCL.Get("UK"))));

            Assert.Throws <SDMXException>(() => hList.Add(hierarchy));
        }
Exemple #5
0
        public CodeRefMap(HierarchicalCodeList hierarchicalCodeList)
        {
            // URN is generaged so we never need to set it manually
            Map <Uri>(o => null).ToSimpleElement("URN", false)
            //.Set(v => urn = v)
            .Converter(new UriConverter());

            Map(o => o.CodeListRef.Alias).ToSimpleElement("CodelistAliasRef", true)
            .Set(v => codeRef.CodeListRef = GetCodeListRef(hierarchicalCodeList, v))
            .Converter(new IdConverter());

            Map(o => o.CodeId).ToSimpleElement("CodeID", true)
            .Set(v => codeRef.CodeId = v)
            .Converter(new IdConverter());

            MapCollection(o => o.Children).ToElement("CodeRef", false)
            .Set(v => codeRef.Add(v))
            .ClassMap(() => new CodeRefMap(hierarchicalCodeList));

            // ignored
            Map(o => o.LevelRef).ToSimpleElement("LevelRef", false)
            .Converter(new IdConverter());

            // ignored
            Map(o => o.NodeAliasId).ToSimpleElement("NodeAliasID", false)
            .Converter(new IdConverter());

            Map(o => o.Version).ToSimpleElement("Version", false)
            .Set(v => codeRef.Version = v)
            .Converter(new StringConverter());

            Map(o => o.ValidFrom).ToSimpleElement("ValidFrom", false)
            .Set(v => codeRef.ValidFrom = v)
            .Converter(new TimePeriodConverter());

            Map(o => o.ValidTo).ToSimpleElement("ValidTo", false)
            .Set(v => codeRef.ValidTo = v)
            .Converter(new TimePeriodConverter());
        }
Exemple #6
0
 private CodeListRef GetCodeListRef(HierarchicalCodeList hierarchicalCodeList, Id alias)
 {
     return(hierarchicalCodeList.CodeListRefs.Where(c => c.Alias == alias).Single());
 }
Exemple #7
0
        public void Create_HierarchicalList()
        {
            var countryCL = GetCountryCodeList();
            var regionsCL = GetRegionsCodeList();

            var hList = new HierarchicalCodeList(new InternationalString("en", "Europe"), "HCL_Europe", "SDMX");
            hList.AddCodeList(countryCL, "countryCLAlias");
            hList.AddCodeList(regionsCL, "RegionsAlias");

            Hierarchy hierarchy = new Hierarchy("id",
               new CodeRef(regionsCL.Get("Europe"),
                   new CodeRef(countryCL.Get("Germany")),
                   new CodeRef(countryCL.Get("UK"))));

            hList.Add(hierarchy);

            Assert.IsNotNull(hList);
            Assert.AreEqual("Europe", hList.Name["en"]);
            //Assert.AreEqual( Id("HCL_Europe"), hList.Id);
            //Assert.AreEqual(new Id("SDMX"), hList.AgencyId);
            //Assert.AreEqual(2, hList.CodeListRefs.Count());
            //var codeListRef = hList.CodeListRefs.ElementAt(0);
            //Assert.AreEqual(new Id("CL_Country"), codeListRef.Id);
            //Assert.AreEqual(new Id("SDMX"), codeListRef.AgencyId);
            //Assert.AreEqual(new Id("countryCLAlias"), codeListRef.Alias);

            //codeListRef = hList.CodeListRefs.ElementAt(1);
            //Assert.AreEqual(new Id("CL_Regions"), codeListRef.Id);
            //Assert.AreEqual(new Id("SDMX"), codeListRef.AgencyId);
            //Assert.AreEqual(new Id("RegionsAlias"), codeListRef.Alias);

            Assert.AreEqual(1, hList.Count());
            var hirchy = hList.ElementAt(0);
            //Assert.AreEqual(new Id("id"), hirchy.Id);
            Assert.AreEqual(3, hirchy.GetCodeRefs().Count());

            foreach (var codeRef in hirchy.GetCodeRefs())
            {
                Assert.IsNotNull(codeRef.CodeListRef);
                Assert.IsNotNull(codeRef.CodeListRef.Alias);
                Assert.IsTrue(codeRef.CodeListRef.Alias == "countryCLAlias" || codeRef.CodeListRef.Alias == "RegionsAlias");
            }

            var europeCode = hirchy.GetCodeRefs().Where(i => i.CodeId == "Europe").Single();
            Assert.IsNull(europeCode.Parent);
            var germany = hirchy.GetCodeRefs().Where(i => i.CodeId == "Germany").Single();
            var uk = hirchy.GetCodeRefs().Where(i => i.CodeId == "UK").Single();
            Assert.AreSame(germany.Parent, europeCode);
            Assert.AreSame(uk.Parent, europeCode);
        }
Exemple #8
0
        public void HierarchicalList_InvalidAlias()
        {
            var hList = new HierarchicalCodeList(new InternationalString("en", "Europe"), "HCL_Europe", "SDMX");
            var countryCL = GetCountryCodeList();
            var regionsCL = GetRegionsCodeList();

            // don't add the country code list to the hierarchy in order to throw the exception
            //hList.AddCodeList(countryCL, "countryCLAlias");
            hList.AddCodeList(regionsCL, "RegionsAlias");

            Hierarchy hierarchy = new Hierarchy("id",
                new CodeRef(regionsCL.Get("Europe"),
                    new CodeRef(countryCL.Get("Germany")),
                    new CodeRef(countryCL.Get("UK"))));

            Assert.Throws<SDMXException>(() => hList.Add(hierarchy));
        }
Exemple #9
0
        public void WBDSD_HierarchicalCodeList()
        {
            // load the DSD
            string dsdPath = Utility.GetPath("lib\\DSD_WB.xml");

            var dsd = StructureMessage.Load(dsdPath);
            
            // create hierarchical code list and add it to the DSD
            var hlist = new HierarchicalCodeList("MDG_Regions", "MDG");
            hlist.Name["en"] = "MDG Regions";
            dsd.HierarchicalCodeLists.Add(hlist);

            // get REF_AREA code list from the DSD and add it to the hierarchical code list
            var refAreaCodeList = dsd.CodeLists.Where(codeList => codeList.Id == "CL_REF_AREA_MDG").Single();
            hlist.AddCodeList(refAreaCodeList, "REF_AREA_MDG");

            // get parent country code
            var MDG_DEVELOPED = refAreaCodeList.Where(code => code.Id == "MDG_DEVELOPED").Single();

            // child country codes
            string[] ids = new[] { "ALB", "AND", "AUS", "AUT", "BEL", "BIH", "BMU", "BGR", "HRV", "CAN", "CZE", "DNK", "EST", "FRO", "FIN", "FRA", "DEU", "GRC", "HUN", "ISL", "IRL", "ITA", "JPN", "LVA", "LIE", "LTU", "LUX", "MKD", "MLT", "MCO", "MNE", "NLD", "NZL", "NOR", "POL", "PRT", "ROU", "SVK", "SMR", "SVN", "SRB", "ESP", "SWE", "CHE", "GBR", "USA" };
            var countryCodes = (from c in refAreaCodeList
                                join cid in ids on c.Id.ToString() equals cid
                                select c).ToList();

            // create hirarchy with parent code and child code and add it to
            // the hierarchical code list
            var hierarchy = new Hierarchy("Developed_Countries", new CodeRef(MDG_DEVELOPED, countryCodes));
            hierarchy.Name["en"] = "Developed Countries";
            hlist.Add(hierarchy);

            // create another hierarchy and add it to the hierarchical code list
            var MDG_NAFR = refAreaCodeList.Where(code => code.Id == "MDG_NAFR").Single();

            ids = new[] { "DZA", "EGY", "LBY", "MAR", "TUN" };

            countryCodes = (from c in refAreaCodeList
                            join cid in ids on c.Id.ToString() equals cid
                            select c).ToList();

            hierarchy = new Hierarchy("MDG_NAFR", new CodeRef(MDG_NAFR, () => countryCodes));
            hierarchy.Name["en"] = "MDG Northern Africa Countries";
            hlist.Add(hierarchy);

            // save the DSD
            dsd.Save(Utility.GetPath("lib\\DSD_WB2.xml"));

            string messageText = dsd.ToString();

            var doc = XDocument.Parse(messageText); 
            using (var reader = doc.CreateReader())
                Assert.IsTrue(MessageValidator.ValidateXml(reader));
        }