Пример #1
0
        public CsdlSemanticsEntitySetTests()
        {
            var referentialConstraints = new List <CsdlReferentialConstraint>();
            var csdlNavigation         = new CsdlNavigationProperty("Navigation", null, null, null, false, null, referentialConstraints, null, null);

            this.csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty <CsdlProperty>(), new[] { csdlNavigation }, null, null);
            var goodBinding = new CsdlNavigationPropertyBinding("Navigation", "EntitySet", null, new CsdlLocation(1, 1));

            this.csdlEntitySet = new CsdlEntitySet("EntitySet", "FQ.NS.EntityType", new[] { goodBinding }, null, null);
            this.csdlContainer = new CsdlEntityContainer("Container", null, new[] { this.csdlEntitySet }, Enumerable.Empty <CsdlSingleton>(), Enumerable.Empty <CsdlOperationImport>(), null, null);

            var derivedCsdlNavigation = new CsdlNavigationProperty("DerivedNavigation", null, null, null, false, null, referentialConstraints, null, null);
            var derivedCsdlEntityType = new CsdlEntityType("DerivedEntityType", "FQ.NS.EntityType", false, false, false, null, Enumerable.Empty <CsdlProperty>(), new[] { derivedCsdlNavigation }, null, null);

            var unrelatedCsdlEntityType = new CsdlEntityType("UnrelatedEntityType", null, false, false, false, null, Enumerable.Empty <CsdlProperty>(), Enumerable.Empty <CsdlNavigationProperty>(), null, null);

            var csdlSchema = new CsdlSchema("FQ.NS", null, null, new[] { this.csdlEntityType, derivedCsdlEntityType, unrelatedCsdlEntityType }, Enumerable.Empty <CsdlEnumType>(), Enumerable.Empty <CsdlOperation>(), Enumerable.Empty <CsdlTerm>(), Enumerable.Empty <CsdlEntityContainer>(), Enumerable.Empty <CsdlAnnotations>(), Enumerable.Empty <CsdlTypeDefinition>(), null, null);
            var csdlModel  = new CsdlModel();

            csdlModel.AddSchema(csdlSchema);
            var semanticModel = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty <IEdmModel>());

            this.semanticSchema    = new CsdlSemanticsSchema(semanticModel, csdlSchema);
            this.semanticContainer = new CsdlSemanticsEntityContainer(this.semanticSchema, this.csdlContainer);

            this.semanticEntityType = semanticModel.FindType("FQ.NS.EntityType") as CsdlSemanticsEntityTypeDefinition;
            this.semanticEntityType.Should().NotBeNull();
            this.navigationProperty = this.semanticEntityType.FindProperty("Navigation") as CsdlSemanticsNavigationProperty;
            this.navigationProperty.Should().NotBeNull();
        }
 public CsdlSemanticsEntityContainer(CsdlSemanticsSchema context, CsdlEntityContainer entityContainer)
     : base(entityContainer)
 {
     this.context         = context;
     this.entityContainer = entityContainer;
     this.fullName        = EdmUtil.GetFullNameForSchemaElement(this.context?.Namespace, this.entityContainer?.Name);
 }
Пример #3
0
        private static CsdlSemanticsSchema CreateCsdlSemanticsSchema(CsdlEntityContainer csdlEntityContainer, params CsdlOperation[] operations)
        {
            var csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, new Collection <CsdlProperty>(), new System.Collections.Generic.List <CsdlNavigationProperty>(), null, null);
            var schema         = CsdlBuilder.Schema("FQ.NS", csdlOperations: operations, csdlEntityContainers: new CsdlEntityContainer[] { csdlEntityContainer }, csdlStructuredTypes: new CsdlStructuredType[] { csdlEntityType });
            var csdlModel      = new CsdlModel();

            csdlModel.AddSchema(schema);
            var semanticSchema = new CsdlSemanticsSchema(new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty <IEdmModel>()), schema);

            return(semanticSchema);
        }
        internal void WriteEntityContainerElementHeader(IEdmEntityContainer container)
        {
            this.xmlWriter.WriteStartElement(CsdlConstants.Element_EntityContainer);
            this.WriteRequiredAttribute(CsdlConstants.Attribute_Name, container.Name, EdmValueWriter.StringAsXml);
            CsdlSemanticsEntityContainer tmp           = container as CsdlSemanticsEntityContainer;
            CsdlEntityContainer          csdlContainer = null;

            if (tmp != null && (csdlContainer = tmp.Element as CsdlEntityContainer) != null)
            {
                this.WriteOptionalAttribute(CsdlConstants.Attribute_Extends, csdlContainer.Extends, EdmValueWriter.StringAsXml);
            }
        }
 public CsdlSemanticsEntityContainer(CsdlSemanticsSchema context, CsdlEntityContainer entityContainer) : base(entityContainer)
 {
     this.elementsCache                  = new Cache <CsdlSemanticsEntityContainer, IEnumerable <IEdmEntityContainerElement> >();
     this.associationSetsCache           = new Cache <CsdlSemanticsEntityContainer, IEnumerable <CsdlSemanticsAssociationSet> >();
     this.associationSetMappingsCache    = new Cache <CsdlSemanticsEntityContainer, Dictionary <IEdmAssociation, IEnumerable <CsdlSemanticsAssociationSet> > >();
     this.entitySetDictionaryCache       = new Cache <CsdlSemanticsEntityContainer, Dictionary <string, IEdmEntitySet> >();
     this.functionImportsDictionaryCache = new Cache <CsdlSemanticsEntityContainer, Dictionary <string, object> >();
     this.errorsCache     = new Cache <CsdlSemanticsEntityContainer, IEnumerable <EdmError> >();
     this.extendsCache    = new Cache <CsdlSemanticsEntityContainer, IEdmEntityContainer>();
     this.context         = context;
     this.entityContainer = entityContainer;
 }
Пример #6
0
        public void ParseCsdlEntityContainerWithMembersWorksAsExpected()
        {
            string json = @"""DemoService"": {
  ""$Kind"": ""EntityContainer"",
  ""Products"": {
     ""$Type"": ""self.Product"",
     ""$Collection"": true
    },
   ""Me"": {
     ""$Type"": ""self.User""
    },
   ""LeaveRequestApproval"": {
    ""$Action"": ""self.Approval""
  },
 ""ProductsByRating"": {
    ""$EntitySet"": ""Products"",
    ""$Function"": ""self.ProductsByRating""
  },
 ""@UI.DisplayName"": ""Supplier Directory""
}";

            CsdlEntityContainer entityContainer = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlEntityContainer);

            Assert.NotNull(entityContainer);

            Assert.Equal("DemoService", entityContainer.Name);

            CsdlEntitySet entitySet = Assert.Single(entityContainer.EntitySets);

            Assert.Equal("Products", entitySet.Name);

            CsdlSingleton singleton = Assert.Single(entityContainer.Singletons);

            Assert.Equal("Me", singleton.Name);

            Assert.Equal(2, entityContainer.OperationImports.Count());
            CsdlActionImport actionImport = Assert.Single(entityContainer.OperationImports.OfType <CsdlActionImport>());

            Assert.Equal("LeaveRequestApproval", actionImport.Name);

            CsdlFunctionImport functionImport = Assert.Single(entityContainer.OperationImports.OfType <CsdlFunctionImport>());

            Assert.Equal("ProductsByRating", functionImport.Name);

            CsdlAnnotation annotation = Assert.Single(entityContainer.VocabularyAnnotations);

            Assert.Equal("UI.DisplayName", annotation.Term);
            Assert.IsType <CsdlConstantExpression>(annotation.Expression);
        }
Пример #7
0
        public void ParseCsdlEntityContainerBasicWorksAsExpected()
        {
            string json = @"""DemoService"": {
  ""$Kind"": ""EntityContainer""
}";

            CsdlEntityContainer entityContainer = ParseCsdlSchemaElement(json, SchemaJsonParser.ParseCsdlEntityContainer);

            Assert.NotNull(entityContainer);

            Assert.Equal("DemoService", entityContainer.Name);
            Assert.Empty(entityContainer.EntitySets);
            Assert.Empty(entityContainer.Singletons);
            Assert.Empty(entityContainer.OperationImports);
        }
 public CsdlSemanticsEntityContainer(CsdlSemanticsSchema context, CsdlEntityContainer entityContainer)
     : base(entityContainer)
 {
     this.context         = context;
     this.entityContainer = entityContainer;
 }
Пример #9
0
        internal static CsdlSchema Schema(
            string namespaceName,
            string alias    = null,
            Version version = null,
            CsdlStructuredType[] csdlStructuredTypes = default(CsdlStructuredType[]),
            CsdlEnumType[] csdlEnumTypes             = default(CsdlEnumType[]),
            CsdlOperation[] csdlOperations           = default(CsdlOperation[]),
            CsdlTerm[] csdlTerms = default(CsdlTerm[]),
            CsdlEntityContainer[] csdlEntityContainers = default(CsdlEntityContainer[]),
            CsdlAnnotations[] csdlAnnotations          = default(CsdlAnnotations[]),
            CsdlTypeDefinition[] csdlTypeDefinitions   = default(CsdlTypeDefinition[]),
            CsdlLocation location = null)
        {
            if (csdlStructuredTypes == null)
            {
                csdlStructuredTypes = new CsdlStructuredType[] { };
            }

            if (csdlEnumTypes == null)
            {
                csdlEnumTypes = new CsdlEnumType[] { };
            }

            if (csdlOperations == null)
            {
                csdlOperations = new CsdlOperation[] { };
            }

            if (csdlTerms == null)
            {
                csdlTerms = new CsdlTerm[] { };
            }

            if (csdlEntityContainers == null)
            {
                csdlEntityContainers = new CsdlEntityContainer[] { };
            }

            if (csdlAnnotations == null)
            {
                csdlAnnotations = new CsdlAnnotations[] { };
            }

            if (csdlTypeDefinitions == null)
            {
                csdlTypeDefinitions = new CsdlTypeDefinition[] { };
            }

            var csdlSchema = new CsdlSchema(
                namespaceName,
                alias,
                version,
                csdlStructuredTypes,
                csdlEnumTypes,
                csdlOperations,
                csdlTerms,
                csdlEntityContainers,
                csdlAnnotations,
                csdlTypeDefinitions,
                location /*location*/);

            return(csdlSchema);
        }