예제 #1
0
        public void FilterByFullNameShouldReturnOneActionsWithCorrectNamespace()
        {
            EdmAction action = new EdmAction("namespace", "action", null);
            EdmAction action2 = new EdmAction("namespace2", "action", null);
            var       filteredResults = new IEdmOperation[] { action, action2 }.FilterByName(false, "namespace.action").ToList();

            filteredResults.Should().HaveCount(1);
            filteredResults[0].Should().Be(action);
        }
예제 #2
0
        public void GetEntityTypeThrowsNotImplementedException()
        {
            // Arrange & Act
            IEdmOperation operation = new EdmAction("NS", "MyAction", null);
            var           segment   = new ODataOperationSegment(operation);

            // Assert
            Assert.Throws <NotImplementedException>(() => segment.EntityType);
        }
        public void CtorSetOperationProperty()
        {
            // Arrange & Act
            IEdmOperation operation = new EdmAction("NS", "MyAction", null);
            var           segment   = new ODataOperationSegment(operation);

            // Assert
            Assert.Same(operation, segment.Operation);
        }
예제 #4
0
        public void KindPropertyReturnsOperationEnumMember()
        {
            // Arrange & Act
            IEdmOperation operation = new EdmAction("NS", "MyAction", null);
            var           segment   = new ODataOperationSegment(operation);

            // Assert
            Assert.Equal(ODataSegmentKind.Operation, segment.Kind);
        }
예제 #5
0
        public void VerifyOperationParameterWritten()
        {
            var action = new EdmAction("Default.Namespace", "Checkout", null);

            action.AddParameter("firstParameter", EdmCoreModel.Instance.GetSingle(true));
            VisitAndVerifyXml(
                (visitor) => visitor.VisitSchemaElement(action),
                @"<Action Name=""Checkout""><Parameter Name=""firstParameter"" Type=""Edm.Single"" /></Action>");
        }
        private void BuildOperations(EdmModel model, string modelNamespace)
        {
            foreach (var operationMethodInfo in operationInfos)
            {
                // With this method, if return type is nullable type,it will get underlying type
                var returnType          = TypeHelper.GetUnderlyingTypeOrSelf(operationMethodInfo.Method.ReturnType);
                var returnTypeReference = returnType.GetReturnTypeReference(model);
                var isBound             = operationMethodInfo.IsBound;
                var bindingParameter    = operationMethodInfo.Method.GetParameters().FirstOrDefault();

                if (bindingParameter == null && isBound)
                {
                    // Ignore the method which is marked as bounded but no parameters
                    continue;
                }

                var namespaceName = GetNamespaceName(operationMethodInfo, modelNamespace);

                EdmOperation      operation = null;
                EdmPathExpression path      = null;
                if (isBound)
                {
                    // Unbound actions or functions should not have EntitySetPath attribute
                    path = BuildBoundOperationReturnTypePathExpression(returnTypeReference, bindingParameter);
                }

                if (operationMethodInfo.HasSideEffects)
                {
                    operation = new EdmAction(namespaceName, operationMethodInfo.Name, returnTypeReference, isBound, path);
                }
                else
                {
                    operation = new EdmFunction(namespaceName, operationMethodInfo.Name, returnTypeReference, isBound, path, operationMethodInfo.IsComposable);
                }

                BuildOperationParameters(operation, operationMethodInfo.Method, model);
                model.AddElement(operation);

                if (!isBound)
                {
                    // entitySetReferenceExpression refer to an entity set containing entities returned
                    // by this function/action import.
                    var entitySetExpression = BuildEntitySetExpression(
                        model, operationMethodInfo.EntitySet, returnTypeReference);
                    var entityContainer = model.EnsureEntityContainer(targetType);
                    if (operationMethodInfo.HasSideEffects)
                    {
                        entityContainer.AddActionImport(operation.Name, (EdmAction)operation, entitySetExpression);
                    }
                    else
                    {
                        entityContainer.AddFunctionImport(
                            operation.Name, (EdmFunction)operation, entitySetExpression);
                    }
                }
            }
        }
예제 #7
0
        public void VerifyEntityReturnTypeDefinedInChildReturnTypeElement()
        {
            var entityType = new EdmEntityType("NS.ds", "EntityType");
            var action     = new EdmAction("Default.Namespace", "Checkout", new EdmEntityTypeReference(entityType, false));

            VisitAndVerifyXml(
                (visitor) => visitor.VisitSchemaElement(action),
                @"<Action Name=""Checkout""><ReturnType Type=""NS.ds.EntityType"" Nullable=""false"" /></Action>");
        }
        /// <summary>	Builds the actions. </summary>
        ///
        /// <param name="model">	    The model. </param>
        /// <param name="targetType">	Type of the target. </param>
        private void BuildActions(EdmModel model, Type targetType)
        {
            var methods = targetType.GetMethods(
                BindingFlags.NonPublic |
                BindingFlags.Public |
                BindingFlags.Static |
                BindingFlags.Instance);

            ICollection <ActionMethodInfo> actionInfos = new List <ActionMethodInfo>();

            foreach (var method in methods)
            {
                //var functionAttribute = method.GetCustomAttributes<FunctionAttribute>(true).FirstOrDefault();
                //if (functionAttribute != null)
                //{
                //	functionInfos.Add(new FunctionMethodInfo
                //	{
                //		Method = method,
                //		FunctionAttribute = functionAttribute
                //	});
                //}

                var actionAttribute = method.GetCustomAttributes <ActionAttribute>(true).FirstOrDefault();
                if (actionAttribute != null)
                {
                    actionInfos.Add(new ActionMethodInfo
                    {
                        Method          = method,
                        ActionAttribute = actionAttribute
                    });
                }
            }

            foreach (ActionMethodInfo actionInfo in actionInfos)
            {
                var returnTypeReference = GetReturnTypeReference(actionInfo.Method.ReturnType, model);

                bool isBound = TryGetBindingParameter(actionInfo.Method, model, out ParameterInfo bindingParameter);

                var action = new EdmAction(
                    actionInfo.Namespace,
                    actionInfo.Name,
                    returnTypeReference,
                    isBound,
                    BuildEntitySetPathExpression(returnTypeReference, bindingParameter));
                BuildOperationParameters(action, actionInfo.Method, model);
                model.AddElement(action);

                if (!isBound)
                {
                    var entitySetReferenceExpression = BuildEntitySetReferenceExpression(model, actionInfo.EntitySet, returnTypeReference);
                    var entityContainer = EnsureEntityContainer(model, targetType);
                    entityContainer.AddActionImport(action.Name, action, entitySetReferenceExpression);
                }
            }
        }
예제 #9
0
        public static IEdmModel GetUntypedEdmModel()
        {
            if (_untypedEdmModel != null)
            {
                return(_untypedEdmModel);
            }

            var model = new EdmModel();
            // complex type address
            EdmComplexType address = new EdmComplexType("NS", "Address", null, false, true);

            address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            model.AddElement(address);
            IEdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(address.ToEdmTypeReference(false)));

            // enum type color
            EdmEnumType color = new EdmEnumType("NS", "Color");

            color.AddMember(new EdmEnumMember(color, "Red", new EdmEnumMemberValue(0)));
            model.AddElement(color);
            IEdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(color.ToEdmTypeReference(false)));

            // primitive collection type
            IEdmTypeReference          intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true);
            EdmCollectionTypeReference primitiveCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(intType));

            // entity type customer
            EdmEntityType customer = new EdmEntityType("NS", "UntypedSimpleOpenCustomer", null, false, true);

            customer.AddKeys(customer.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32));
            customer.AddStructuralProperty("Color", new EdmEnumTypeReference(color, isNullable: true));
            customer.AddStructuralProperty("DeclaredAddresses", complexCollectionType);
            customer.AddStructuralProperty("DeclaredColors", enumCollectionType);
            customer.AddStructuralProperty("DeclaredNumbers", primitiveCollectionType);

            model.AddElement(customer);

            EdmAction action = new EdmAction(
                "NS",
                "AddColor",
                null,
                isBound: true,
                entitySetPathExpression: null);

            action.AddParameter("bindingParameter", new EdmEntityTypeReference(customer, false));
            action.AddParameter("Color", new EdmEnumTypeReference(color, true));
            model.AddElement(action);

            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");

            container.AddEntitySet("UntypedSimpleOpenCustomers", customer);

            model.AddElement(container);
            _untypedEdmModel = model;
            return(model);
        }
예제 #10
0
        public void EnsureActionImportIsAddedWithActionSuppliedName()
        {
            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction          action    = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
            var actionImport             = container.AddActionImport(action);

            actionImport.Action.Should().Be(action);
            actionImport.Name.Should().Be(action.Name);
            container.Elements.ToArray()[0].Should().Be(actionImport);
        }
예제 #11
0
        public void FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingTypeShouldNotThrowAndFilterNonBoundOperations()
        {
            EdmEntityType aType  = new EdmEntityType("N", "A");
            EdmAction     action = new EdmAction("namespace", "action", null, false, null);

            action.AddParameter("bindingParameter", new EdmEntityTypeReference(aType, false));
            var filteredResults = new IEdmOperation[] { action }.FilterBoundOperationsWithSameTypeHierarchyToTypeClosestToBindingType(aType).ToList();

            filteredResults.Should().HaveCount(0);
        }
예제 #12
0
        public void CreateODataOperationFromFunctionImportShouldCreateODataAction()
        {
            var            action = new EdmAction("TestModel", "FunctionImport1", null /*returnType*/);
            bool           isAction;
            ODataOperation operation = ODataJsonLightUtils.CreateODataOperation(new Uri("http://www.example.com/$metadata"), "#Foo", action, out isAction);

            Assert.True(isAction);
            Assert.Equal("http://www.example.com/$metadata#Foo", operation.Metadata.AbsoluteUri);
            Assert.Same(operation.GetType(), typeof(ODataAction));
        }
예제 #13
0
        public void EdmActionImportConstructorShouldDefaultNonSpecifiedPropertiesCorrectly()
        {
            var edmAction       = new EdmAction("DefaultNamespace", "Checkout", this.boolType);
            var edmActionImport = new EdmActionImport(this.entityContainer, "CheckoutImport", edmAction, null);

            edmActionImport.Name.Should().Be("CheckoutImport");
            edmActionImport.EntitySet.Should().BeNull();
            edmActionImport.Container.Should().Be(this.entityContainer);
            edmActionImport.Action.Should().Be(edmAction);
        }
예제 #14
0
        public void GetActionLinkBuilder_ReturnsDefaultActionLinkBuilder_IfNotSet()
        {
            // Arrange
            IEdmModel           model     = new EdmModel();
            IEdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            IEdmAction          action    = new EdmAction("NS", "Action", returnType: null);

            // Act & Assert
            Assert.NotNull(model.GetActionLinkBuilder(action));
        }
예제 #15
0
        public void EnsureActionImportIsAddedAndWithCorrectSuppliedName()
        {
            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction          action    = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
            var actionImport             = container.AddActionImport("OtherName", action);

            Assert.Same(action, actionImport.Action);
            Assert.Equal("OtherName", actionImport.Name);
            Assert.Same(actionImport, container.Elements.ToArray()[0]);
        }
        public void CtorActionSegmentTemplate_ThrowsArgument_NonboundAction()
        {
            // Arrange
            var       primitive = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, false);
            EdmAction action    = new EdmAction("NS", "MyAction", primitive, false, null);

            // Act & Assert
            ExceptionAssert.Throws <ODataException>(() => new ActionSegmentTemplate(action, null),
                                                    "The input operation 'MyAction' is not a bound 'action'.");
        }
예제 #17
0
        private static void BuildAction(EdmModel model, string actName, IEdmEntityTypeReference bindingType, string paramName, IEdmTypeReference edmType)
        {
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);

            EdmAction boundAction = new EdmAction("NS", actName, returnType, isBound: true, entitySetPathExpression: null);

            boundAction.AddParameter("entity", bindingType);
            boundAction.AddParameter(paramName, edmType);
            boundAction.AddParameter(paramName + "List", new EdmCollectionTypeReference(new EdmCollectionType(edmType)));
            model.AddElement(boundAction);
        }
        internal void AddAction(Action action)
        {
            EdmAction          edmAction;
            EdmEntityContainer entityContainer  = (EdmEntityContainer)EntityContainer;
            IEdmTypeReference  edmTypeReference = GetNotEntityTypeReference(action.ReturnType);

            if (edmTypeReference == null)
            {
                edmTypeReference = GetCollectionNotEntityTypeReference(action.ReturnType);
            }

            if (edmTypeReference != null)
            {
                edmAction = new EdmAction(DefaultNamespace, action.Name, edmTypeReference);
                entityContainer.AddActionImport(edmAction);
            }
            else if (action.ReturnType == typeof(void))
            {
                edmAction = new EdmAction(DefaultNamespace, action.Name, null);
                entityContainer.AddActionImport(edmAction);
            }
            else
            {
                IEdmTypeReference returnEdmTypeReference = GetEdmTypeReference(action.ReturnType, out IEdmEntityType returnEntityType, out bool isCollection);
                if (returnEntityType == null)
                {
                    throw new ArgumentNullException("Тип возвращаемого результата action не найден в модели OData.");
                }

                edmAction = new EdmAction(DefaultNamespace, action.Name, returnEdmTypeReference);
                edmAction.AddParameter("bindingParameter", returnEdmTypeReference);
                entityContainer.AddActionImport(action.Name, edmAction, new EdmEntitySetReferenceExpression(GetEdmEntitySet(returnEntityType)));
            }

            AddElement(edmAction);
            foreach (var parameter in action.ParametersTypes.Keys)
            {
                Type paramType = action.ParametersTypes[parameter];
                edmTypeReference = GetEdmTypeReference(paramType, out IEdmEntityType entityType, out bool isCollection);
                if (edmTypeReference == null)
                {
                    edmTypeReference = GetNotEntityTypeReference(paramType);
                    if (edmTypeReference == null)
                    {
                        edmTypeReference = GetCollectionNotEntityTypeReference(paramType);
                    }
                }

                if (edmTypeReference != null)
                {
                    edmAction.AddParameter(parameter, edmTypeReference);
                }
            }
        }
예제 #19
0
        public void KindPropertyReturnsOperation()
        {
            // Arrange
            ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(_simpleKeyEntitySet);
            EdmAction             action           = new EdmAction("NS", "MyAction", null, isBound: true, entitySetPathExpression: null);
            ODataOperationSegment opSegment        = new ODataOperationSegment(action);
            ODataPath             path             = new ODataPath(nsSegment, opSegment);

            // Act & Assert
            Assert.Equal(ODataPathKind.Operation, path.Kind);
        }
예제 #20
0
        public void EdmActionConstructorShouldDefaultNonSpecifiedPropertiesCorrectly()
        {
            var edmAction = new EdmAction(defaultNamespaceName, checkout, this.boolType);

            Assert.Equal(defaultNamespaceName, edmAction.Namespace);
            Assert.Equal(checkout, edmAction.Name);
            Assert.Same(this.boolType, edmAction.ReturnType);
            Assert.Null(edmAction.EntitySetPath);
            Assert.False(edmAction.IsBound);
            Assert.Equal(EdmSchemaElementKind.Action, edmAction.SchemaElementKind);
        }
예제 #21
0
        public void EdmActionConstructorShouldDefaultNonSpecifiedPropertiesCorrectly()
        {
            var edmAction = new EdmAction(defaultNamespaceName, checkout, this.boolType);

            edmAction.Namespace.Should().Be(defaultNamespaceName);
            edmAction.Name.Should().Be(checkout);
            edmAction.ReturnType.Should().Be(this.boolType);
            edmAction.EntitySetPath.Should().BeNull();
            edmAction.IsBound.Should().BeFalse();
            edmAction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Action);
        }
예제 #22
0
        /// <summary>
        /// Adds the action.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="boundType">Type of the bound.</param>
        /// <param name="resultType">Type of the result.</param>
        /// <param name="isBound">if set to <c>true</c> [is bound].</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns></returns>
        public EdmAction AddAction(string name, IEdmTypeReference boundType, IEdmTypeReference resultType, bool isBound, IEdmPathExpression entitySetPathExpression, params Tuple <string, IEdmTypeReference>[] parameters)
        {
            var action = new EdmAction(namespaceName, name, resultType, isBound, entitySetPathExpression);

            if (isBound)
            {
                action.AddParameter(new EdmOperationParameter(action, "bindingparameter", boundType));
            }

            this.AddOperation(action);
            return(action);
        }
예제 #23
0
        private EdmAction BuildAction(OeOperationConfiguration operationConfiguration, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
        {
            var edmAction = new EdmAction(operationConfiguration.NamespaceName, operationConfiguration.Name, null);

            foreach (OeOperationParameterConfiguration parameterConfiguration in operationConfiguration.Parameters)
            {
                IEdmTypeReference edmTypeReference = GetEdmTypeReference(parameterConfiguration.ClrType, entityTypeInfos);
                edmAction.AddParameter(parameterConfiguration.Name, edmTypeReference);
            }

            return(edmAction);
        }
예제 #24
0
        public void KindPropertyReturnsOperationImport()
        {
            // Arrange
            IEdmEntityContainer container       = new EdmEntityContainer("NS", "default");
            IEdmAction          action          = new EdmAction("NS", "MyAction", null);
            var operationImport                 = new EdmActionImport(container, "MyAction", action);
            ODataOperationImportSegment segment = new ODataOperationImportSegment(operationImport);
            ODataPath path = new ODataPath(segment);

            // Act & Assert
            Assert.Equal(ODataPathKind.OperationImport, path.Kind);
        }
예제 #25
0
        public static IEdmModel GetModelFunctionsOnNonEntityTypes()
        {
            EdmComplexType colorInfoType = new EdmComplexType("Test", "ColorInfo");

            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Red", EdmCoreModel.Instance.GetInt32(false)));
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Green", EdmCoreModel.Instance.GetInt32(false)));
            colorInfoType.AddProperty(new EdmStructuralProperty(colorInfoType, "Blue", EdmCoreModel.Instance.GetInt32(false)));

            EdmEntityType          vegetableType = new EdmEntityType("Test", "Vegetable");
            IEdmStructuralProperty id            = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false));

            vegetableType.AddKeys(id);
            vegetableType.AddStructuralProperty("Color", new EdmComplexTypeReference(colorInfoType, false));

            EdmEntityContainer container = new EdmEntityContainer("Test", "Container");
            var set = container.AddEntitySet("Vegetables", vegetableType);

            var function1 = new EdmFunction("Test", "IsPrime", EdmCoreModel.Instance.GetBoolean(false), true, null, true);

            function1.AddParameter("integer", EdmCoreModel.Instance.GetInt32(false));
            container.AddFunctionImport("IsPrime", function1);

            var action = new EdmAction("Test", "Subtract", EdmCoreModel.Instance.GetInt32(false), true /*isBound*/, null /*entitySetPath*/);

            action.AddParameter("integer", EdmCoreModel.Instance.GetInt32(false));
            container.AddActionImport(action);

            var function2 = new EdmFunction("Test", "IsDark", EdmCoreModel.Instance.GetBoolean(false), true, null, true);

            function2.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
            container.AddFunctionImport("IsDark", function2);

            var function3 = new EdmFunction("Test", "IsDarkerThan", EdmCoreModel.Instance.GetBoolean(false), true, null, true);

            function3.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));
            function3.AddParameter("other", new EdmComplexTypeReference(colorInfoType, true));
            container.AddFunctionImport("IsDarkerThan", function3);

            var function4 = new EdmFunction("Test", "GetMostPopularVegetableWithThisColor", new EdmEntityTypeReference(vegetableType, true), true, new EdmPathExpression("color"), true);

            function4.AddParameter("color", new EdmComplexTypeReference(colorInfoType, false));

            EdmModel model = new EdmModel();

            model.AddElement(container);
            model.AddElement(vegetableType);
            model.AddElement(action);
            model.AddElement(function1);
            model.AddElement(function2);
            model.AddElement(function3);
            model.AddElement(function4);
            return(model);
        }
예제 #26
0
        public void WriteOperationParametersAsAvroTest()
        {
            var operation = new EdmAction("NS", "op1", null);

            operation.AddParameter("p1", EdmCoreModel.Instance.GetString(false));
            operation.AddParameter("p2", new EdmEntityTypeReference(TestEntityType, false));

            MemoryStream ms      = new MemoryStream();
            var          context = this.CreateOutputContext(ms);
            var          opw     = new ODataAvroParameterWriter(context, operation);

            {
                opw.WriteStart();
                opw.WriteValue("p1", "dat");
                {
                    var ew = opw.CreateEntryWriter("p2");
                    ew.WriteStart(entry0);
                    ew.WriteEnd();
                    ew.Flush();
                }

                opw.WriteEnd();
                opw.Flush();
            }

            ms.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            IEnumerable <object> results = null;

            using (var reader = AvroContainer.CreateGenericReader(ms))
                using (var seqReader = new SequentialReader <object>(reader))
                {
                    results = seqReader.Objects;
                }

            dynamic record = results.Cast <AvroRecord>().Single();

            Assert.AreEqual("dat", record.p1);
            dynamic p2 = record.p2;

            Assert.AreEqual(true, p2.TBoolean);
            Assert.AreEqual(32, p2.TInt32);
            var col = p2.TCollection as object[];

            Assert.IsNotNull(col);
            Assert.IsTrue(longCollection0.SequenceEqual(col.Cast <long>()));
            dynamic cpx = p2.TComplex as AvroRecord;

            Assert.IsNotNull(cpx);
            Assert.IsTrue(binary0.SequenceEqual((byte[])cpx.TBinary));
            Assert.AreEqual("iamstr", cpx.TString);
        }
예제 #27
0
        public void EnsureFunctionImportIsAddedAndWithCorrectEntitySetExpression()
        {
            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction          action    = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
            var entitySetExpression      = new EdmPathExpression("EntitySet");
            var functionImport           = container.AddActionImport("OtherName", action, entitySetExpression);

            functionImport.Action.Should().Be(action);
            functionImport.Name.Should().Be("OtherName");
            functionImport.EntitySet.Should().Be(entitySetExpression);
            container.Elements.ToArray()[0].Should().Be(functionImport);
        }
        public static IEdmModel InterfaceCriticalPropertyValueMustNotBeNullUsingOperationParameterTypeModel()
        {
            var model = new EdmModel();

            var operation = new EdmAction("NS", "Function", EdmCoreModel.Instance.GetInt32(true));
            var parameter = new CustomOperationParameter(operation, "Parameter", null);

            operation.AddParameter(parameter);
            model.AddElement(operation);

            return(model);
        }
예제 #29
0
        public static IEdmModel AddDynamicModel(this EdmModel model)
        {
            var addressType = new EdmComplexType(Namespace, "address");

            addressType.AddStructuralProperty("street", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("city", EdmPrimitiveTypeKind.String);

            var addressTypeRef   = new EdmComplexTypeReference(addressType, isNullable: false);
            var addressesTypeRef = EdmCoreModel.GetCollection(addressTypeRef);

            var nonNullableStringTypeRef = EdmCoreModel.Instance.GetString(isNullable: false);
            var tagsTypeRef = EdmCoreModel.GetCollection(nonNullableStringTypeRef);

            var docEntityType         = new EdmEntityType(Namespace, DocEntityTypeName);
            EdmStructuralProperty key = docEntityType.AddStructuralProperty("id", EdmPrimitiveTypeKind.String);

            docEntityType.AddKeys(key);
            docEntityType.AddStructuralProperty("addresses", addressesTypeRef);
            docEntityType.AddStructuralProperty("tags", tagsTypeRef);

            var docEntitySetType = EdmCoreModel.GetCollection(new EdmEntityTypeReference(docEntityType, isNullable: true));

            var docComplexType = new EdmComplexType(Namespace, DocComplexTypeName);

            foreach (IEdmStructuralProperty property in docEntityType.StructuralProperties())
            {
                docComplexType.AddStructuralProperty(property.Name, property.Type);
            }

            var valueParameterTypeRef =
                EdmCoreModel.GetCollection(new EdmComplexTypeReference(docComplexType, isNullable: false));

            var container = (EdmEntityContainer)model.EntityContainer;

            container.AddEntitySet("Docs", docEntityType);

            var indexAction =
                new EdmAction(
                    Namespace,
                    "Index",
                    returnType: null,
                    isBound: true,
                    entitySetPathExpression: null);

            indexAction.AddParameter("bindingParameter", docEntitySetType);
            indexAction.AddParameter("value", valueParameterTypeRef);

            var indexActionImport = new EdmActionImport(container, indexAction.Name, indexAction);

            model.AddElements(new IEdmSchemaElement[] { addressType, docEntityType, docComplexType, indexActionImport.Operation });
            return(model);
        }
        public void CtorFunctionSegmentTemplate_ThrowsODataException_NonFunction()
        {
            // Arrange
            IEdmPrimitiveTypeReference intPrimitive = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, false);
            EdmAction        action           = new EdmAction("NS", "MyAction", intPrimitive);
            OperationSegment operationSegment = new OperationSegment(action, null);

            // Act
            Action test = () => new FunctionSegmentTemplate(operationSegment);

            // Assert
            ExceptionAssert.Throws <ODataException>(test, "The input segment should be 'Function' in 'FunctionSegmentTemplate'.");
        }
        private void BuildOperations(EdmModel model, string modelNamespace)
        {
            foreach (OperationMethodInfo operationMethodInfo in this.operationInfos)
            {
                // With this method, if return type is nullable type,it will get underlying type
                var returnType = TypeHelper.GetUnderlyingTypeOrSelf(operationMethodInfo.Method.ReturnType);
                var returnTypeReference = returnType.GetReturnTypeReference(model);
                bool isBound = operationMethodInfo.IsBound;
                var bindingParameter = operationMethodInfo.Method.GetParameters().FirstOrDefault();

                if (bindingParameter == null && isBound)
                {
                    // Ignore the method which is marked as bounded but no parameters
                    continue;
                }

                string namespaceName = GetNamespaceName(operationMethodInfo, modelNamespace);

                EdmOperation operation = null;
                EdmPathExpression path = null;
                if (isBound)
                {
                    // Unbound actions or functions should not have EntitySetPath attribute
                    path = BuildBoundOperationReturnTypePathExpression(returnTypeReference, bindingParameter);
                }

                if (operationMethodInfo.HasSideEffects)
                {
                    operation = new EdmAction(
                        namespaceName,
                        operationMethodInfo.Name,
                        returnTypeReference,
                        isBound,
                        path);
                }
                else
                {
                    operation = new EdmFunction(
                        namespaceName,
                        operationMethodInfo.Name,
                        returnTypeReference,
                        isBound,
                        path,
                        operationMethodInfo.IsComposable);
                }

                BuildOperationParameters(operation, operationMethodInfo.Method, model);
                model.AddElement(operation);

                if (!isBound)
                {
                    // entitySetReferenceExpression refer to an entity set containing entities returned
                    // by this function/action import.
                    var entitySetExpression = BuildEntitySetExpression(
                        model, operationMethodInfo.EntitySet, returnTypeReference);
                    var entityContainer = model.EnsureEntityContainer(this.targetType);
                    if (operationMethodInfo.HasSideEffects)
                    {
                        entityContainer.AddActionImport(operation.Name, (EdmAction)operation, entitySetExpression);
                    }
                    else
                    {
                        entityContainer.AddFunctionImport(
                            operation.Name, (EdmFunction)operation, entitySetExpression);
                    }
                }
            }
        }