예제 #1
0
        public void TryGetEntitySetWithBoundCsdlSemanticOperationParameterShouldReturnTrueAndHaveNoErrors()
        {
            var csdlEntityType = new CsdlEntityType("EntityType", null, false, false, false, null, Enumerable.Empty <CsdlProperty>(), Enumerable.Empty <CsdlNavigationProperty>(), null, null);
            var csdlSchema     = CsdlBuilder.Schema("FQ.NS", csdlStructuredTypes: new[] { csdlEntityType });

            var csdlModel = new CsdlModel();

            csdlModel.AddSchema(csdlSchema);
            var semanticModel  = new CsdlSemanticsModel(csdlModel, new EdmDirectValueAnnotationsManager(), Enumerable.Empty <IEdmModel>());
            var semanticSchema = new CsdlSemanticsSchema(semanticModel, csdlSchema);
            var testLocation   = new CsdlLocation(1, 3);

            var action = new CsdlAction(
                "Checkout",
                new CsdlOperationParameter[] { new CsdlOperationParameter("entity", new CsdlNamedTypeReference("FQ.NS.EntityType", false, testLocation), null, testLocation) },
                new CsdlNamedTypeReference("Edm.String", false, testLocation),
                true /*isBound*/,
                "entity",
                null /*documentation*/,
                testLocation);

            var semanticAction = new CsdlSemanticsAction(semanticSchema, action);
            IEdmOperationParameter edmParameter;
            IEnumerable <IEdmNavigationProperty> navigationProperties;
            IEdmEntityType         entityType;
            IEnumerable <EdmError> errors;

            semanticAction.TryGetRelativeEntitySetPath(semanticSchema.Model, out edmParameter, out navigationProperties, out entityType, out errors).Should().BeTrue();
            edmParameter.Name.Should().Be("entity");
            navigationProperties.Should().BeEmpty();
            entityType.FullName().Should().Be("FQ.NS.EntityType");
            errors.Should().BeEmpty();
        }
예제 #2
0
        public void ParseCsdlOperationForActionWithMembersWorksAsExpected()
        {
            string json = @"""Approval"": [
    {
        ""$Kind"": ""Action"",
        ""$IsBound"": true,
        ""$Parameter"": [
            {
                ""$Name"": ""binding"",
                ""$Type"": ""self.Order"",
                ""$Nullable"": true
            }
        ]
    }
]";

            IList <CsdlOperation> operations = ParseCsdlSchemaElement(json, SchemaJsonParser.TryParseCsdlOperationOverload);

            Assert.NotNull(operations);
            CsdlOperation operation = Assert.Single(operations);

            CsdlAction action = Assert.IsType <CsdlAction>(operation);

            Assert.Equal("Approval", action.Name);
            Assert.True(action.IsBound);
            Assert.Null(action.EntitySetPath);

            // Parameter
            CsdlOperationParameter parameter = Assert.Single(action.Parameters);

            Assert.Equal("binding", parameter.Name);
            Assert.False(parameter.IsOptional);
            Assert.Null(parameter.DefaultValue);
            CsdlNamedTypeReference namedType = Assert.IsType <CsdlNamedTypeReference>(parameter.Type);

            Assert.True(namedType.IsNullable);
            Assert.Equal("self.Order", namedType.FullName);

            // ReturnType
            Assert.Null(action.Return);
        }
예제 #3
0
        public void BoundCsdlSemanticsOperationPropertiesShouldBeCorrect()
        {
            var action = new CsdlAction(
                "Checkout",
                new CsdlOperationParameter[] { new CsdlOperationParameter("entity", new CsdlNamedTypeReference("FQ.NS.EntityType", false, testLocation), testLocation) },
                new CsdlOperationReturn(new CsdlNamedTypeReference("Edm.String", false, testLocation), testLocation),
                true /*isBound*/,
                "entity/FakePath",
                testLocation);

            var semanticAction = new CsdlSemanticsAction(this.semanticSchema, action);

            semanticAction.IsBound.Should().BeTrue();
            semanticAction.Location().Should().Be(testLocation);
            semanticAction.Name.Should().Be("Checkout");
            semanticAction.Namespace.Should().Be("FQ.NS");
            semanticAction.ReturnType.Definition.Should().Be(EdmCoreModel.Instance.GetString(true).Definition);
            semanticAction.EntitySetPath.PathSegments.ToList()[0].Should().Be("entity");
            semanticAction.EntitySetPath.PathSegments.ToList()[1].Should().Be("FakePath");
            semanticAction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Action);
        }
        private IEnumerable <IEdmOperation> ComputeOperations()
        {
            List <IEdmOperation> operations = new List <IEdmOperation>();

            foreach (CsdlOperation operation in this.schema.Operations)
            {
                CsdlAction action = operation as CsdlAction;
                if (action != null)
                {
                    operations.Add(new CsdlSemanticsAction(this, action));
                }
                else
                {
                    CsdlFunction function = operation as CsdlFunction;
                    Debug.Assert(function != null, "function != null");
                    operations.Add(new CsdlSemanticsFunction(this, function));
                }
            }

            return(operations);
        }
        public void BoundCsdlSemanticsOperationPropertiesShouldBeCorrect()
        {
            var action = new CsdlAction(
                "Checkout",
                new CsdlOperationParameter[] { new CsdlOperationParameter("entity", new CsdlNamedTypeReference("FQ.NS.EntityType", false, testLocation), testLocation) },
                new CsdlOperationReturn(new CsdlNamedTypeReference("Edm.String", false, testLocation), testLocation),
                true /*isBound*/,
                "entity/FakePath",
                testLocation);

            var semanticAction = new CsdlSemanticsAction(this.semanticSchema, action);

            Assert.True(semanticAction.IsBound);
            Assert.Equal(testLocation, semanticAction.Location());
            Assert.Equal("Checkout", semanticAction.Name);
            Assert.Equal("FQ.NS", semanticAction.Namespace);
            Assert.Equal("Edm.String", semanticAction.ReturnType.Definition.FullTypeName());
            Assert.Equal("entity", semanticAction.EntitySetPath.PathSegments.ToList()[0]);
            Assert.Equal("FakePath", semanticAction.EntitySetPath.PathSegments.ToList()[1]);
            Assert.Equal(EdmSchemaElementKind.Action, semanticAction.SchemaElementKind);
        }
예제 #6
0
        public void ParseCsdlOperationWithActionAndFunctionWorksAsExpected()
        {
            string json = @"""Approval"": [
    {
        ""$Kind"": ""Action"",
        ""$IsBound"": true,
        ""$Parameter"": [
            {
                ""$Name"": ""binding"",
                ""$Type"": ""self.Order"",
                ""$Nullable"": true
            }
        ]
    },
    {
        ""$Kind"": ""Function"",
        ""$Parameter"": [
            {
                ""$Name"": ""Rating"",
                ""$Type"": ""Edm.Decimal"",
                ""$Precision"": 4,
                ""$Scale"": 1
            }
        ],
        ""$ReturnType"": {
            ""$Type"": ""self.Product""
         }
    }
]";

            IList <CsdlOperation> operations = ParseCsdlSchemaElement(json, SchemaJsonParser.TryParseCsdlOperationOverload);

            Assert.NotNull(operations);
            Assert.Equal(2, operations.Count);

            // #1 CsdlAction
            CsdlAction action = Assert.IsType <CsdlAction>(operations.First());

            Assert.Equal("Approval", action.Name);
            Assert.True(action.IsBound);
            Assert.Null(action.EntitySetPath);

            CsdlOperationParameter parameter = Assert.Single(action.Parameters);

            Assert.Equal("binding", parameter.Name);
            Assert.False(parameter.IsOptional);
            Assert.Null(parameter.DefaultValue);
            CsdlNamedTypeReference namedType = Assert.IsType <CsdlNamedTypeReference>(parameter.Type);

            Assert.True(namedType.IsNullable);
            Assert.Equal("self.Order", namedType.FullName);
            Assert.Null(action.Return);

            // #2 CsdlFunction
            CsdlFunction function = Assert.IsType <CsdlFunction>(operations.Last());

            Assert.Equal("Approval", function.Name);
            Assert.False(function.IsBound);
            Assert.Null(function.EntitySetPath);

            parameter = Assert.Single(function.Parameters);
            Assert.Equal("Rating", parameter.Name);
            Assert.False(parameter.IsOptional);
            Assert.Null(parameter.DefaultValue);
            CsdlDecimalTypeReference decimalType = Assert.IsType <CsdlDecimalTypeReference>(parameter.Type);

            Assert.False(decimalType.IsNullable);
            Assert.Equal(4, decimalType.Precision.Value);
            Assert.Equal(1, decimalType.Scale.Value);

            Assert.NotNull(function.Return);
            namedType = Assert.IsType <CsdlNamedTypeReference>(function.Return.ReturnType);
            Assert.False(namedType.IsNullable);
            Assert.Equal("self.Product", namedType.FullName);
        }
예제 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CsdlSemanticsAction"/> class.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="action">The action.</param>
 public CsdlSemanticsAction(CsdlSemanticsSchema context, CsdlAction action)
     : base(context, action)
 {
 }