コード例 #1
0
        public void TestAddUriStructureOkController()
        {
            ConfigJsonHandler       configJsonHandler      = new ConfigJsonHandler();
            ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler);
            SchemaController        schemaController       = new SchemaController(configJsonHandler, schemaConfigOperations);
            UriStructure            newUriStructure        = CreateUriStructureExample("newUriExample");
            ResourcesClass          newResourcesClass      = CreateResourceClassExample("newUriExample", "rsp", "pipaon");
            List <ResourcesClass>   lista = new List <ResourcesClass>();

            lista.Add(newResourcesClass);
            InfoUriStructure structure = new InfoUriStructure();

            structure.ResourcesClass = lista;
            structure.UriStructure   = newUriStructure;
            var result = schemaController.AddUriStructure(structure);

            if (result is BadRequestObjectResult)
            {
                Assert.True(false);
            }
            else
            {
                Assert.True(true);
            }
        }
コード例 #2
0
 public void TestAddUriStructureOk()
 {
     try
     {
         ConfigJsonHandler          configJsonHandler          = new ConfigJsonHandler();
         SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler);
         CreateBackUpConfig();
         UriStructureGeneral uriSchema         = configJsonHandler.GetUrisConfig();
         UriStructure        newUriStructure   = CreateUriStructureExample("newUriExample");
         ResourcesClass      newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon");
         int oldResourcesClassesCount          = uriSchema.ResourcesClasses.Count;
         int oldUriStructuresCount             = uriSchema.UriStructures.Count;
         configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass);
         schemaConfigFileOperations.SaveConfigJson();
         ConfigJsonHandler   configJsonHandler2 = new ConfigJsonHandler();
         UriStructureGeneral uriSchema2         = configJsonHandler2.GetUrisConfig();
         RestoreBackUpConfig();
         configJsonHandler2.LoadConfigJson();
         Assert.True(oldResourcesClassesCount + 1 == uriSchema2.ResourcesClasses.Count && oldUriStructuresCount + 1 == uriSchema2.UriStructures.Count);
     }
     catch (Exception)
     {
         RestoreBackUpConfig();
     }
 }
コード例 #3
0
        public async void TestUriPublicationOK()
        {
            ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
            var parsedJson = configJsonHandler.GetUrisConfig();

            Assert.True(parsedJson != null);
        }
コード例 #4
0
 public void TestDeleteUriStructureOk()
 {
     try
     {
         ConfigJsonHandler          configJsonHandler          = new ConfigJsonHandler();
         SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler);
         CreateBackUpConfig();
         UriStructureGeneral uriSchema = configJsonHandler.GetUrisConfig();
         int oldResourcesClassesCount  = uriSchema.ResourcesClasses.Count;
         int oldUriStructuresCount     = uriSchema.UriStructures.Count;
         if (configJsonHandler.ExistUriStructure("uriPublicationStructure"))
         {
             configJsonHandler.DeleteUriStructureInfo("uriPublicationStructure");
             schemaConfigFileOperations.SaveConfigJson();
             ConfigJsonHandler   configJsonHandler2 = new ConfigJsonHandler();
             UriStructureGeneral uriSchema2         = configJsonHandler2.GetUrisConfig();
             RestoreBackUpConfig();
             Assert.True(oldResourcesClassesCount == uriSchema2.ResourcesClasses.Count + 1 && oldUriStructuresCount == uriSchema2.UriStructures.Count + 1);
         }
         else
         {
             Assert.True(false);
         }
     }
     catch (Exception)
     {
         RestoreBackUpConfig();
     }
 }
コード例 #5
0
        public void TestAddUriStructureFailUriStructureBadInfoException()
        {
            ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
            UriStructure      newUriStructure   = CreateUriStructureExample("newUriExample");
            ResourcesClass    newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "");

            Assert.Throws <UriStructureBadInfoException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass));
        }
コード例 #6
0
        public void TestUriPublicationFail()
        {
            Dictionary <string, string> queryString = new Dictionary <string, string>();

            queryString.Add("identifier", "123d");
            ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
            UriFormer         uriFormer         = new UriFormer(configJsonHandler.GetUrisConfig());

            Assert.Throws <ParametersNotConfiguredException>(() => uriFormer.GetURI("publication", queryString));
        }
コード例 #7
0
        public bool SaveConfigFile(IFormFile formFile)
        {
            var memoryStream = new MemoryStream();

            formFile.CopyTo(memoryStream);
            byte[] bytes = memoryStream.ToArray();
            string texto = Encoding.UTF8.GetString(bytes);
            UriStructureGeneral uriStructureGeneral = ReaderConfigJson.Read(texto);

            return(ConfigJsonHandler.IsCorrectFormedUriStructure(uriStructureGeneral));
        }
コード例 #8
0
        public void TestGetSchemaFileData()
        {
            ConfigJsonHandler          configJsonHandler          = new ConfigJsonHandler();
            SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler);
            var bytesSchema               = schemaConfigFileOperations.GetFileSchemaData();
            var bytesAsString             = Encoding.UTF8.GetString(bytesSchema);
            UriStructureGeneral uriSchema = JsonConvert.DeserializeObject <UriStructureGeneral>(bytesAsString);
            bool correctGenerated         = uriSchema != null && uriSchema.Base != null && uriSchema.Characters != null && uriSchema.ResourcesClasses != null && uriSchema.ResourcesClasses.Count > 0 && uriSchema.UriStructures != null && uriSchema.UriStructures.Count > 0;

            Assert.True(correctGenerated);
        }
コード例 #9
0
        public void TestUriResearcherOK()
        {
            Dictionary <string, string> queryString = new Dictionary <string, string>();

            queryString.Add("identifier", "123d");
            ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
            UriFormer         uriFormer         = new UriFormer(configJsonHandler.GetUrisConfig());
            string            uri           = uriFormer.GetURI("AcademicDegree", queryString);
            string            uriResultante = "http://graph.um.es/res/academic-degree/123d";

            Assert.True(uriResultante.Equals(uri));
        }
コード例 #10
0
        public void TestUriRdfTypeOK()
        {
            Dictionary <string, string> queryString = new Dictionary <string, string>();

            queryString.Add("identifier", "123d");
            ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
            UriFormer         uriFormer         = new UriFormer(configJsonHandler.GetUrisConfig());
            string            uri           = uriFormer.GetURI("http://purl.org/roh/mirror/vivo#AdvisorRole", queryString, true);
            string            uriResultante = "http://graph.um.es/res/advisor-role/123d";

            Assert.True(uriResultante.Equals(uri));
        }
コード例 #11
0
        static void Main(string[] args)
        {
            Dictionary <string, string> queryString = new Dictionary <string, string>();

            queryString.Add("identifier", "123d");
            string texto = File.ReadAllText("Config/UrisConfig.json");
            UriStructureGeneral uriStructure      = JsonConvert.DeserializeObject <UriStructureGeneral>(texto);
            ConfigJsonHandler   configJsonHandler = new ConfigJsonHandler(texto);
            UriFormer           uriFormer         = new UriFormer(configJsonHandler.GetUrisConfig());
            string uri = uriFormer.GetURI("AdvisorRole", queryString);

            Console.WriteLine(uri);
        }
コード例 #12
0
 public void TestGetSchemaController()
 {
     try
     {
         ConfigJsonHandler       configJsonHandler      = new ConfigJsonHandler();
         ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler);
         SchemaController        schemaController       = new SchemaController(configJsonHandler, schemaConfigOperations);
         var result = schemaController.GetSchema();
         Assert.True(true);
     }
     catch (Exception)
     {
         Assert.True(false);
     }
 }
コード例 #13
0
 public void TestAddUriStructureFailMatchNames()
 {
     try
     {
         ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
         CreateBackUpConfig();
         UriStructure   newUriStructure   = CreateUriStructureExample("newUriExamp");
         ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon");
         Assert.Throws <UriStructureBadInfoException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass));
     }
     catch (Exception)
     {
         RestoreBackUpConfig();
     }
 }
コード例 #14
0
 public void TestAddUriStructureFailUriStructureConfiguredException()
 {
     try
     {
         ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();
         CreateBackUpConfig();
         UriStructure   newUriStructure   = CreateUriStructureExample("uriResourceStructure");
         ResourcesClass newResourcesClass = CreateResourceClassExample("uriResourceStructure", "rsp", "");
         Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass));
     }
     catch (Exception)
     {
         RestoreBackUpConfig();
     }
 }
コード例 #15
0
        public void TestGetUriController()
        {
            ConfigJsonHandler       configJsonHandler      = new ConfigJsonHandler();
            ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler);
            SchemaController        schemaController       = new SchemaController(configJsonHandler, schemaConfigOperations);
            var result = schemaController.GetUriStructureInfo("uriResourceStructure");

            if (result is BadRequestObjectResult)
            {
                Assert.True(false);
            }
            else
            {
                Assert.True(true);
            }
        }
コード例 #16
0
 public void TestDeleteUriStructureNoNameFoundError()
 {
     try
     {
         ConfigJsonHandler          configJsonHandler          = new ConfigJsonHandler();
         SchemaConfigFileOperations schemaConfigFileOperations = new SchemaConfigFileOperations(configJsonHandler);
         CreateBackUpConfig();
         Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.DeleteUriStructureInfo("badName"));
         schemaConfigFileOperations.SaveConfigJson();
         configJsonHandler.GetUrisConfig();
         RestoreBackUpConfig();
     }
     catch (Exception)
     {
         RestoreBackUpConfig();
     }
 }
コード例 #17
0
        public void TestAddUriStructureOk()
        {
            ConfigJsonHandler   configJsonHandler = new ConfigJsonHandler();
            UriStructureGeneral uriSchema         = configJsonHandler.GetUrisConfig();
            UriStructure        newUriStructure   = CreateUriStructureExample("newUriExample");
            ResourcesClass      newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", "pipaon");
            int oldResourcesClassesCount          = uriSchema.ResourcesClasses.Count;
            int oldUriStructuresCount             = uriSchema.UriStructures.Count;

            configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass);
            ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler);

            schemaConfigOperations.SaveConfigJson();
            UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig();

            Assert.True(oldResourcesClassesCount + 1 == uriSchema2.ResourcesClasses.Count && oldUriStructuresCount + 1 == uriSchema2.UriStructures.Count);
        }
コード例 #18
0
        public void TestDeleteUriStructureOk()
        {
            ConfigJsonHandler   configJsonHandler = new ConfigJsonHandler();
            UriStructureGeneral uriSchema         = configJsonHandler.GetUrisConfig();
            int oldResourcesClassesCount          = uriSchema.ResourcesClasses.Count;
            int oldUriStructuresCount             = uriSchema.UriStructures.Count;

            if (configJsonHandler.ExistUriStructure("uriResourceStructure"))
            {
                configJsonHandler.DeleteUriStructureInfo("uriResourceStructure");
                ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler);
                schemaConfigOperations.SaveConfigJson();
                UriStructureGeneral uriSchema2 = configJsonHandler.GetUrisConfig();
                Assert.True(oldResourcesClassesCount > uriSchema2.ResourcesClasses.Count && oldUriStructuresCount > uriSchema2.UriStructures.Count);
            }
            else
            {
                Assert.True(false);
            }
        }
コード例 #19
0
        public void TestBadFormedJson()
        {
            ConfigJsonHandler       configJsonHandler      = new ConfigJsonHandler();
            ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler);
            SchemaController        schemaController       = new SchemaController(configJsonHandler, schemaConfigOperations);
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);

            writer.Write(jsonConfigBad);
            writer.Flush();
            stream.Position = 0;
            var file   = new FormFile(stream, 0, stream.Length, null, "config.json");
            var result = schemaController.ReplaceSchemaConfig(file);

            if (result is BadRequestObjectResult)
            {
                Assert.True(true);
            }
            else
            {
                Assert.True(false);
            }
        }
コード例 #20
0
 public SchemaConfigMemoryOperations(ConfigJsonHandler configJsonHandler)
 {
     _configJsonHandler = configJsonHandler;
 }
コード例 #21
0
 public bool SaveConfigJson()
 {
     return(ConfigJsonHandler.IsCorrectFormedUriStructure(_configJsonHandler.GetUrisConfig()));
 }
コード例 #22
0
 public FactoryController(ConfigJsonHandler configJsonHandler)
 {
     _configJsonHandler = configJsonHandler;
 }
コード例 #23
0
 public SchemaController(ConfigJsonHandler configJsonHandler, ISchemaConfigOperations schemaConfigOperations)
 {
     _configJsonHandler      = configJsonHandler;
     _schemaConfigOperations = schemaConfigOperations;
 }
コード例 #24
0
 public AddParametersFilter(ConfigJsonHandler configJsonHandler)
 {
     _configJsonHandler = configJsonHandler;
 }
コード例 #25
0
        public static void Get()
        {
            UriStructureGeneral structureGeneral = new UriStructureGeneral()
            {
                Base = "http://graph.um.es"
            };
            List <Characters> characters = new List <Characters>();
            Characters        charac     = new Characters()
            {
                Character      = "resource",
                LabelCharacter = "res"
            };

            characters.Add(charac);
            structureGeneral.Characters = characters;
            Component baseC = new Component()
            {
                UriComponent      = "base",
                UriComponentValue = "base",
                UriComponentOrder = 1,
                Mandatory         = true,
                FinalCharacter    = "/"
            };
            Component character = new Component()
            {
                UriComponent      = "character",
                UriComponentValue = "character@resource",
                UriComponentOrder = 2,
                Mandatory         = true,
                FinalCharacter    = "/"
            };
            Component resource = new Component()
            {
                UriComponent      = "resourceClass",
                UriComponentValue = "resourceClass",
                UriComponentOrder = 3,
                Mandatory         = true,
                FinalCharacter    = "/"
            };
            Component identifier = new Component()
            {
                UriComponent      = "identifier",
                UriComponentValue = "@ID",
                UriComponentOrder = 4,
                Mandatory         = true,
                FinalCharacter    = ""
            };
            List <Component> componentes = new List <Component>();

            componentes.Add(baseC);
            componentes.Add(character);
            componentes.Add(resource);
            componentes.Add(identifier);
            UriStructure uriStructure = new UriStructure()
            {
                Name       = "test",
                Components = componentes
            };

            structureGeneral.UriStructures = new List <UriStructure>();
            structureGeneral.UriStructures.Add(uriStructure);
            ResourcesClass clas = new ResourcesClass()
            {
                LabelResourceClass = "project-object",
                ResourceClass      = "Project",
                ResourceURI        = "test"
            };
            ResourcesClass clas2 = new ResourcesClass()
            {
                LabelResourceClass = "researcher",
                ResourceClass      = "Researcher",
                ResourceURI        = "test"
            };

            structureGeneral.ResourcesClasses = new List <ResourcesClass>();
            structureGeneral.ResourcesClasses.Add(clas);
            structureGeneral.ResourcesClasses.Add(clas2);

            string uriSchemaJson = JsonConvert.SerializeObject(structureGeneral);

            ConfigJsonHandler           config      = new ConfigJsonHandler(uriSchemaJson);
            Dictionary <string, string> queryString = new Dictionary <string, string>();

            queryString.Add("identifier", "123d");
            UriFormer uriFormer = new UriFormer(config.GetUrisConfig());
            string    uri       = uriFormer.GetURI("Project", queryString);

            Console.WriteLine(uri);
        }
コード例 #26
0
        public IActionResult Get()
        {
            UriStructureGeneral structureGeneral = new UriStructureGeneral()
            {
                Base = "http://graph.um.es"
            };
            List <Characters> characters = new List <Characters>();
            Characters        charac     = new Characters()
            {
                Character      = "resource",
                LabelCharacter = "res"
            };

            characters.Add(charac);
            structureGeneral.Characters = characters;
            Component baseC = new Component()
            {
                UriComponent      = "base",
                UriComponentValue = "base",
                UriComponentOrder = 1,
                Mandatory         = true,
                FinalCharacter    = "/"
            };
            Component character = new Component()
            {
                UriComponent      = "character",
                UriComponentValue = "character@RESOURCE",
                UriComponentOrder = 2,
                Mandatory         = true,
                FinalCharacter    = "/"
            };
            Component resource = new Component()
            {
                UriComponent      = "resourceClass",
                UriComponentValue = "resourceClass@RESOURCECLASS",
                UriComponentOrder = 3,
                Mandatory         = true,
                FinalCharacter    = "/"
            };
            Component identifier = new Component()
            {
                UriComponent      = "identifier",
                UriComponentValue = "@ID",
                UriComponentOrder = 4,
                Mandatory         = true,
                FinalCharacter    = ""
            };
            List <Component> componentes = new List <Component>();

            componentes.Add(baseC);
            componentes.Add(character);
            componentes.Add(resource);
            componentes.Add(identifier);
            UriStructure uriStructure = new UriStructure()
            {
                Name       = "test",
                Components = componentes
            };

            structureGeneral.UriStructures = new List <UriStructure>();
            structureGeneral.UriStructures.Add(uriStructure);
            ResourcesClass clas = new ResourcesClass()
            {
                LabelResourceClass = "prueba",
                ResourceClass      = "Test",
                ResourceURI        = "test"
            };

            structureGeneral.ResourcesClasses = new List <ResourcesClass>();
            structureGeneral.ResourcesClasses.Add(clas);

            string uriSchemaJson = JsonConvert.SerializeObject(structureGeneral);

            ConfigJsonHandler config = new ConfigJsonHandler(uriSchemaJson);

            FactoryController factoryController = new FactoryController(config);

            return(factoryController.GenerateUri("Test", "1234"));
        }
コード例 #27
0
        public void TestDeleteUriStructureNoNameFoundError()
        {
            ConfigJsonHandler configJsonHandler = new ConfigJsonHandler();

            Assert.Throws <UriStructureConfiguredException>(() => configJsonHandler.DeleteUriStructureInfo("badName"));
        }