Exemplo n.º 1
0
        public void GetSubregisterByName()
        {
            //Testdata
            Models.Register     r1           = NewRegister("RegisterName");
            Models.Register     r2           = NewRegister("ParentName");
            Models.Organization organization = NewOrganization("Kartverket");
            r2.owner            = organization;
            r1.parentRegisterId = r2.systemId;
            r1.parentRegister   = r2;

            List <Models.Register> registers = new List <Models.Register> {
                r1, r2
            };

            Models.Register register = new Models.Register();

            var registerService = new Mock <IRegisterService>();

            registerService.Setup(s => s.GetRegister(r1.parentRegister.seoname, r1.seoname)).Returns(r1);

            var controller = createController(url, registerService.Object, null);
            var result     = controller.GetSubregisterByName(r1.parentRegister.seoname, r1.seoname) as OkNegotiatedContentResult <Models.Api.Register>;

            Models.Api.Register registerApi = result.Content;
            registerApi.label.Should().Be("RegisterName");
        }
Exemplo n.º 2
0
        public void RegisterShouldContainParentRegisterWhenRegisterIsASubRegister()
        {
            Models.Register r1             = NewRegister("TestRegister");
            Models.Register parentRegister = NewRegister("Parent");
            r1.parentRegister       = parentRegister;
            r1.parentRegisterId     = parentRegister.systemId;
            r1.parentRegister.owner = NewOrganization("Kartverket");

            List <Models.Register> registers = new List <Models.Register> {
                r1, parentRegister
            };

            var registerService = new Mock <IRegisterService>();

            registerService.Setup(s => s.GetRegisters()).Returns(registers);
            var controller = createController(url, registerService.Object, null);
            var result     = controller.GetRegisters() as OkNegotiatedContentResult <List <Models.Api.Register> >;
            List <Models.Api.Register> actualListOfRegisters = result.Content;

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

            Models.Api.Register apiRegister = actualListOfRegisters[0];

            apiRegister.id.Should().Be("https://register.geonorge.no/parent/testregister");
        }
Exemplo n.º 3
0
 public InspireDatasetRegistery(Models.Api.Register register)
 {
     DocumentYear    = new Date();
     Memberstate     = "NO";
     MonitoringMD    = new MonitoringMD();
     Indicators      = new Indicators();
     InspireDatasets = GetInspireDatasets(register.containeditems);
 }
Exemplo n.º 4
0
        public void GetRegistersBySystemId()
        {
            //Testdata
            Models.Register r1 = NewRegister("Navn");

            var registerService = new Mock <IRegisterService>();

            registerService.Setup(s => s.GetRegisterBySystemId(r1.systemId)).Returns(r1);

            var controller = createController(url, registerService.Object, null);
            var result     = controller.GetSubregisterByName(null, r1.seoname, r1.systemId.ToString()) as OkNegotiatedContentResult <Models.Api.Register>;

            Models.Api.Register registerApi = result.Content;
            registerApi.label.Should().Be("Navn");
        }
Exemplo n.º 5
0
        private SyndicationItem BuildSyndicationRegister(Models.Api.Register u)
        {
            var item = new SyndicationItem()
            {
                Title           = new TextSyndicationContent(u.label),
                BaseUri         = new Uri(u.id),
                LastUpdatedTime = u.lastUpdated,
                Content         = new TextSyndicationContent(u.contentsummary),
                Id = u.id
            };

            item.Authors.Add(new SyndicationPerson()
            {
                Name = u.manager
            });
            return(item);
        }
Exemplo n.º 6
0
        private string GetGmlId(Models.Api.Register register)
        {
            var idArray = register.id.Split('/');

            if (idArray.Length > 4)
            {
                return(idArray[3] + "." + idArray[4]);
            }
            else if (idArray.Length == 4)
            {
                return(idArray[3]);
            }
            else
            {
                return(register.id);
            }
        }
Exemplo n.º 7
0
        private void BuildSKOSFeed(object models, Stream stream, string contenttype)
        {
            if (models is Models.Api.Register)
            {
                Models.Api.Register register = (Models.Api.Register)models;

                string targetNamespace = "";
                string nameSpace       = "";
                if (register.targetNamespace != null)
                {
                    nameSpace = register.targetNamespace;
                    if (register.targetNamespace.EndsWith("/"))
                    {
                        targetNamespace = register.targetNamespace + register.label;
                    }
                    else
                    {
                        targetNamespace = register.targetNamespace + "/" + register.label;
                    }
                }

                XNamespace ns    = "http://www.opengis.net/gml/3.2";
                XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance";
                XNamespace gmlNs = "http://www.opengis.net/gml/3.2";
                XElement   xdoc  =
                    new XElement(gmlNs + "Dictionary", new XAttribute(XNamespace.Xmlns + "xsi", xsiNs),
                                 new XAttribute(XNamespace.Xmlns + "gml", gmlNs),
                                 new XAttribute(xsiNs + "schemaLocation", "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"),
                                 new XAttribute(gmlNs + "id", register.id),
                                 new XElement(gmlNs + "description"),
                                 new XElement(gmlNs + "identifier",
                                              new XAttribute("codeSpace", nameSpace), register.label),

                                 from k in register.containeditems
                                 select new XElement(gmlNs + "dictionaryEntry", new XElement(gmlNs + "Definition", new XAttribute(gmlNs + "id", "_" + k.codevalue),
                                                                                             new XElement(gmlNs + "description", k.description),
                                                                                             new XElement(gmlNs + "identifier", new XAttribute("codeSpace", targetNamespace), k.codevalue),
                                                                                             new XElement(gmlNs + "name", k.label)
                                                                                             )));

                using (XmlWriter writer = XmlWriter.Create(stream))
                {
                    xdoc.WriteTo(writer);
                }
            }
        }
Exemplo n.º 8
0
        public void RegisterShouldNotContainParentRegisterWhenItIsATopLevelRegister()
        {
            Models.Register        r1        = NewRegister("TestRegister");
            List <Models.Register> registers = new List <Models.Register> {
                r1
            };

            var registerService = new Mock <IRegisterService>();

            registerService.Setup(s => s.GetRegisters()).Returns(registers);
            var controller = createController(url, registerService.Object, null);
            var result     = controller.GetRegisters() as OkNegotiatedContentResult <List <Models.Api.Register> >;
            List <Models.Api.Register> actualListOfRegisters = result.Content;

            actualListOfRegisters.Count.Should().Be(1);

            Models.Api.Register apiRegister = actualListOfRegisters[0];

            apiRegister.id.Should().Be("https://register.geonorge.no/testregister");
        }
Exemplo n.º 9
0
        public void GetRegistersByName()
        {
            //Testdata
            Models.Register r1 = NewRegister("Navn");
            Models.Register r2 = NewRegister("Navn2");
            Models.Register r3 = NewRegister("Navn3");

            List <Models.Register> registers = new List <Models.Register> {
                r1, r2, r3
            };

            var registerService = new Mock <IRegisterService>();

            registerService.Setup(s => s.GetRegisterByName(r1.seoname)).Returns(r1);

            var controller = createController(url, registerService.Object, null);
            var result     = controller.GetRegisterByName(r1.seoname) as OkNegotiatedContentResult <Models.Api.Register>;

            Models.Api.Register registerApi = result.Content;
            registerApi.label.Should().Be("Navn");
        }
Exemplo n.º 10
0
        private Models.Api.Register ConvertRegister(Models.Register item, FilterParameters filter = null)
        {
            string registerId = System.Web.Configuration.WebConfigurationManager.AppSettings["RegistryUrl"]; //uri.Scheme + "://" + uri.Authority;

            if (registerId.Substring(registerId.Length - 1, 1) == "/")
            {
                registerId = registerId.Remove(registerId.Length - 1);
            }
            string selectedDOKMunicipality = "";

            if (filter != null && !string.IsNullOrEmpty(filter.municipality))
            {
                Models.Organization org = _registerItemService.GetMunicipalityOrganizationByNr(filter.municipality);
                if (org != null)
                {
                    selectedDOKMunicipality = org.name;
                }
            }
            var tmp = new Models.Api.Register(item, registerId, selectedDOKMunicipality);

            return(tmp);
        }
Exemplo n.º 11
0
        public void RegisterManagerShouldNotBeNull()
        {
            Models.Register r1 = NewRegister("Navn");
            r1.manager = NewOrganization("Kartverket");

            List <Models.Register> registers = new List <Models.Register> {
                r1
            };

            var registerService = new Mock <IRegisterService>();

            registerService.Setup(s => s.GetRegisters()).Returns(registers);
            var controller = createController(url, registerService.Object, null);
            var result     = controller.GetRegisters() as OkNegotiatedContentResult <List <Models.Api.Register> >;
            List <Models.Api.Register> actualListOfRegisters = result.Content;

            actualListOfRegisters.Count.Should().Be(1);

            Models.Api.Register apiRegister = actualListOfRegisters[0];

            apiRegister.manager.Should().Be("Kartverket");
        }
Exemplo n.º 12
0
        private void BuildSKOSFeed(object models, Stream stream, string contenttype)
        {
            if (models is Models.Api.Register)
            {
                Models.Api.Register register = (Models.Api.Register)models;

                string targetNamespace = "";
                string nameSpace       = "";
                if (register.targetNamespace != null)
                {
                    nameSpace = register.targetNamespace;
                    if (register.targetNamespace.EndsWith("/"))
                    {
                        targetNamespace = register.targetNamespace + register.label;
                    }
                    else
                    {
                        targetNamespace = register.targetNamespace + "/" + register.label;
                    }
                }

                XNamespace ns    = "http://www.opengis.net/gml/3.2";
                XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance";
                XNamespace gmlNs = "http://www.opengis.net/gml/3.2";
                XElement   xdoc  =
                    new XElement(gmlNs + "Dictionary", new XAttribute(XNamespace.Xmlns + "xsi", xsiNs),
                                 new XAttribute(XNamespace.Xmlns + "gml", gmlNs),
                                 new XAttribute(xsiNs + "schemaLocation", "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"),
                                 new XAttribute(gmlNs + "id", GetGmlId(register)),
                                 new XElement(gmlNs + "description"),
                                 new XElement(gmlNs + "identifier",
                                              new XAttribute("codeSpace", register.id), register.label),

                                 from k in register.containeditems
                                 select new XElement(gmlNs + "dictionaryEntry", new XElement(gmlNs + "Definition", new XAttribute(gmlNs + "id", GetGmlId(k)),
                                                                                             new XElement(gmlNs + "metaDataProperty", new XElement(gmlNs + "GenericMetaData",
                                                                                                                                                   new XElement("status", new XAttribute(xsiNs + "type", "gml:StringOrRefType"), k.status),
                                                                                                                                                   GetValidTime(k, gmlNs))),
                                                                                             new XElement(gmlNs + "description", k.description),
                                                                                             new XElement(gmlNs + "identifier", new XAttribute("codeSpace", register.id), !string.IsNullOrEmpty(k.codevalue) ? k.codevalue : k.seoname),
                                                                                             new XElement(gmlNs + "name", k.label)
                                                                                             )));

                using (XmlWriter writer = XmlWriter.Create(stream))
                {
                    xdoc.WriteTo(writer);
                }
            }
            else if (models is Models.Api.Registeritem)
            {
                Models.Api.Registeritem register = (Models.Api.Registeritem)models;

                XNamespace ns    = "http://www.opengis.net/gml/3.2";
                XNamespace xsiNs = "http://www.w3.org/2001/XMLSchema-instance";
                XNamespace gmlNs = "http://www.opengis.net/gml/3.2";
                XElement   xdoc  =
                    new XElement(gmlNs + "Dictionary", new XAttribute(XNamespace.Xmlns + "xsi", xsiNs),
                                 new XAttribute(XNamespace.Xmlns + "gml", gmlNs),
                                 new XAttribute(xsiNs + "schemaLocation", "http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"),
                                 new XAttribute(gmlNs + "id", GetGmlId(register)),
                                 new XElement(gmlNs + "metaDataProperty", new XElement(gmlNs + "GenericMetaData",
                                                                                       new XElement("status", new XAttribute(xsiNs + "type", "gml:StringOrRefType"), register.status),
                                                                                       GetValidTime(register, gmlNs))),
                                 new XElement(gmlNs + "description", register.description),
                                 new XElement(gmlNs + "identifier", new XAttribute("codeSpace", GetCodespace(register)), register.codevalue),
                                 new XElement(gmlNs + "name", register.label)
                                 );

                using (XmlWriter writer = XmlWriter.Create(stream))
                {
                    xdoc.WriteTo(writer);
                }
            }
        }