コード例 #1
0
ファイル: DatabaseHelper.cs プロジェクト: rwredding/jerrycurl
        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);
        }
コード例 #2
0
ファイル: MetadataTests.cs プロジェクト: mephistoc/jerrycurl
        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"));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: MetadataTests.cs プロジェクト: mephistoc/jerrycurl
        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();
        }