public SchemaStore GetSchemas() { RelationMetadataBuilder relationBuilder = new RelationMetadataBuilder(); BindingMetadataBuilder bindingBuilder = new BindingMetadataBuilder(); ReferenceMetadataBuilder referenceBuilder = new ReferenceMetadataBuilder(); SchemaStore store = new SchemaStore(new DotNotation(), relationBuilder, bindingBuilder, referenceBuilder); bindingBuilder.Add(new SqliteContractResolver()); return(store); }
public void Test_Metadata_WithInvalidListContract_Throws() { RelationMetadataBuilder builder = new RelationMetadataBuilder() { new InvalidContractResolver() }; SchemaStore customStore = new SchemaStore(new DotNotation()) { builder }; ISchema schema = customStore.GetSchema(typeof(CustomModel)); Should.Throw <MetadataBuilderException>(() => schema.GetMetadata <IRelationMetadata>("List1")); }
public static ISchemaStore Use(this ISchemaStore store, IRelationContractResolver resolver) { if (store == null) { throw new ArgumentNullException(nameof(store)); } if (resolver == null) { throw new ArgumentNullException(nameof(resolver)); } RelationMetadataBuilder builder = store.Builders.FirstOfType <RelationMetadataBuilder>(); builder?.Add(resolver); return(store); }
public static void AddContract(this ISchemaStore schemas, IRelationContractResolver contract) { if (schemas == null) { throw new ArgumentNullException(nameof(schemas)); } if (contract == null) { throw new ArgumentNullException(nameof(contract)); } RelationMetadataBuilder builder = schemas.OfType <RelationMetadataBuilder>().FirstOrDefault(); if (builder == null) { throw new InvalidOperationException("No relation metadata builder found."); } builder.Add(contract); }
public void Test_Metadata_WithCustomListContract() { RelationMetadataBuilder builder = new RelationMetadataBuilder() { new CustomListContractResolver() }; SchemaStore customStore = new SchemaStore(new DotNotation()) { builder }; ISchema schema1 = DatabaseHelper.Default.Schemas.GetSchema(typeof(CustomModel)); ISchema schema2 = customStore.GetSchema(typeof(CustomModel)); IRelationMetadata notFound = schema1.GetMetadata <IRelationMetadata>("Values.Item"); IRelationMetadata found = schema2.GetMetadata <IRelationMetadata>("Values.Item"); notFound.ShouldBeNull(); found.ShouldNotBeNull(); found.Type.ShouldBe(typeof(int)); found.Annotations.OfType <CustomAttribute>().FirstOrDefault().ShouldNotBeNull(); }