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); } }
public void TestGetSchemaFileData() { ConfigJsonHandler configJsonHandler = new ConfigJsonHandler(); ISchemaConfigOperations schemaConfigOperations = new SchemaConfigMemoryOperations(configJsonHandler); var bytesSchema = schemaConfigOperations.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); }
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); } }
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); } }
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); }
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); } }
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); } }