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(); } }
public IActionResult AddUriStructure(InfoUriStructure infoUriStructure) { if (infoUriStructure != null && infoUriStructure.ResourcesClass != null && infoUriStructure.UriStructure != null && infoUriStructure.ResourcesClass.Count == 1) { try { _configJsonHandler.AddUriStructureInfo(infoUriStructure.UriStructure, infoUriStructure.ResourcesClass.First()); bool saved = _schemaConfigOperations.SaveConfigJson(); if (saved) { return(Ok($"uriStructure: {infoUriStructure.UriStructure.Name} has been added and the new config schema is loaded")); } else { return(Problem(detail: "Server error has ocurred", null, 500)); } } catch (UriStructureConfiguredException confEx) { return(BadRequest(confEx.Message)); } catch (UriStructureBadInfoException badInfoEx) { return(BadRequest($"{{\"error\": \"{badInfoEx.Message}\"}}")); } } else { return(BadRequest("{{\"error\": \"info structure is missing\"}}")); } }
public void TestAddUriStructureFailUriStructureBadInfoException() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); UriStructure newUriStructure = CreateUriStructureExample("newUriExample"); ResourcesClass newResourcesClass = CreateResourceClassExample("newUriExample", "rsp", ""); Assert.Throws <UriStructureBadInfoException>(() => configJsonHandler.AddUriStructureInfo(newUriStructure, newResourcesClass)); }
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(); } }
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(); } }
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); }