private IEdmModel GetEdmModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
            model.AddElement(container);

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);

            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType));

            var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType);
            functionWithOneParam.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOneParam);

            var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType);
            functionWithMultipleParams.AddParameter("Parameter1", parameterType);
            functionWithMultipleParams.AddParameter("Parameter2", parameterType);
            functionWithMultipleParams.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithMultipleParams);

            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType));
            var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads2.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOverloads2);
            var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads3.AddParameter("Parameter1", parameterType);
            functionWithOverloads3.AddParameter("Parameter2", parameterType);
            functionWithOverloads3.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithOverloads3);

            return model;
        }
        public void DuplicateFunctionsUnBoundFunctionsWithSameNameWhereBindingTypeDifferentonNullabilityAndSameParametersShouldError()
        {
            var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true));
            edmFunction.AddParameter("differentName", EdmCoreModel.Instance.GetInt16(true));
            var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true));
            edmFunction2.AddParameter("otherParameter", EdmCoreModel.Instance.GetInt16(false));

            EdmModel model = new EdmModel();
            model.AddElement(edmFunction);
            model.AddElement(edmFunction2);
            ValidateError(model, EdmErrorCode.DuplicateFunctions, Strings.EdmModel_Validator_Semantic_ModelDuplicateBoundFunctionParameterTypes("n.s.GetStuff"));
        }
        public void DuplicateBoundFunctionOverloadsSameParameterNamesShouldError()
        {
            var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true));
            edmFunction.AddParameter("param1", EdmCoreModel.Instance.GetInt32(true));
            var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetInt16(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true));
            edmFunction2.AddParameter("param1", EdmCoreModel.Instance.GetInt16(true));

            EdmModel model = new EdmModel();
            model.AddElement(edmFunction);
            model.AddElement(edmFunction2);
            ValidateError(model, EdmErrorCode.DuplicateFunctions, Strings.EdmModel_Validator_Semantic_ModelDuplicateBoundFunctionParameterNames("n.s.GetStuff"));
        }
        public static IEdmModel MultipleSchemasWithDifferentNamespacesEdm()
        {
            var namespaces = new string[] 
                { 
                    "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.first", 
                    "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.second" 
                };

            var model = new EdmModel();
            foreach (var namespaceName in namespaces)
            {
                var entityType1 = new EdmEntityType(namespaceName, "validEntityType1");
                entityType1.AddKeys(entityType1.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
                var entityType2 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE2");
                entityType2.AddKeys(entityType2.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
                var entityType3 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE3");
                entityType3.AddKeys(entityType3.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));

                entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo {Name = "Mumble", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many});

                var complexType = new EdmComplexType(namespaceName, "ValidNameComplexType1");
                complexType.AddStructuralProperty("aPropertyOne", new EdmComplexTypeReference(complexType, false));
                model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType });

                var function1 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); 
                var function2 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
                function2.AddParameter("param1", new EdmEntityTypeReference(entityType1, false));
                var function3 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false));
                function3.AddParameter("param1", EdmCoreModel.Instance.GetSingle(false));

                model.AddElements(new IEdmSchemaElement[] {function1, function2, function3});
            }

            return model;
        }
Esempio n. 5
0
 public void FunctionImportShouldProduceCorrectFullyQualifiedNameAndNotHaveParameters()
 {
     var function = new EdmFunction("d.s", "testFunction", EdmCoreModel.Instance.GetString(true));
     function.AddParameter("param1", EdmCoreModel.Instance.GetString(false));
     var functionImport = new EdmFunctionImport(new EdmEntityContainer("d.s", "container"), "testFunction", function);
     EdmUtil.FullyQualifiedName(functionImport).Should().Be("d.s.container/testFunction");
 }
        public void TryMatch_ReturnTrue_IfSameUnboundFunction()
        {
            // Arrange
            IEdmModel model = new Mock<IEdmModel>().Object;
            IEdmEntityType returnType = new Mock<IEdmEntityType>().Object;
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");

            EdmFunction func = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false));
            func.AddParameter("Parameter1", EdmCoreModel.Instance.GetInt32(isNullable: false));
            func.AddParameter("Parameter2", EdmCoreModel.Instance.GetInt32(isNullable: false));
            EdmFunctionImport function = new EdmFunctionImport(container, "Function", func);

            Dictionary<string, string> parameterValues = new Dictionary<string, string>
            {
                { "Parameter1", "1" },
                { "Parameter2", "2" }
            };

            Dictionary<string, string> parameterMappings = new Dictionary<string, string>
            {
                { "Parameter1", "{param1}" },
                { "Parameter2", "{param2}" }
            };

            UnboundFunctionPathSegment segment = new UnboundFunctionPathSegment(function, model, parameterValues);
            UnboundFunctionPathSegmentTemplate template = new UnboundFunctionPathSegmentTemplate(
                new UnboundFunctionPathSegment(function, model, parameterMappings));

            // Act
            Dictionary<string, object> values = new Dictionary<string,object>();
            bool result = template.TryMatch(segment, values);

            // Assert
            Assert.True(result);
            Assert.Equal(4, values.Count);
            Assert.Equal("1", values["param1"]);
            Assert.Equal("2", values["param2"]);

            Assert.Equal(1, (values[ODataParameterValue.ParameterValuePrefix + "param1"] as ODataParameterValue).Value);
            Assert.Equal(2, (values[ODataParameterValue.ParameterValuePrefix + "param2"] as ODataParameterValue).Value);
        }
        public void DuplicateFunctionOverloadsWithDifferentBindingTypesAndSameNameWithDifferentReturnTypesShouldNotError()
        {
            var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true));
            var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetInt16(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
            edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true));

            EdmModel model = new EdmModel();
            model.AddElement(edmFunction);
            model.AddElement(edmFunction2);
            ValidateNoError(model);
        }
Esempio n. 8
0
 public void EdmFunctionConstructorShouldHaveSpecifiedConstructorValues()
 {
     var entitySetPath = new EdmPathExpression("Param1/Nav");
     var edmFunction = new EdmFunction(defaultNamespaceName, checkout, this.boolType, true, entitySetPath, true /*IsComposable*/);
     edmFunction.AddParameter(new EdmOperationParameter(edmFunction, "Param1", new EdmEntityTypeReference(personType, false)));
     edmFunction.Namespace.Should().Be(defaultNamespaceName);
     edmFunction.Name.Should().Be(checkout);
     edmFunction.ReturnType.Should().Be(this.boolType);
     edmFunction.EntitySetPath.Should().Be(entitySetPath);
     edmFunction.IsBound.Should().BeTrue();
     edmFunction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Function);
     edmFunction.IsComposable.Should().BeTrue();
 }
        private IEdmModel CreateTestModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default");
            model.AddElement(defaultContainer);

            var productType = new EdmEntityType("TestModel", "Product");
            EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false));
            productType.AddProperty(idProperty);
            productType.AddKeys(idProperty);
            productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);

            var customerType = new EdmEntityType("TestModel", "Customer");
            idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false));
            customerType.AddProperty(idProperty);
            customerType.AddKeys(idProperty);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(productType);

            defaultContainer.AddEntitySet("Products", productType);
            defaultContainer.AddEntitySet("Customers", customerType);
            defaultContainer.AddSingleton("SingleProduct", productType);
            defaultContainer.AddSingleton("SingleCustomer", customerType);

            EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/);
            model.AddElement(action);
            defaultContainer.AddActionImport("SimpleActionImport", action);

            EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
            function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1);

            EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true);
            function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false));
            defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/);

            return model;
        }
        public void CanParse_FunctionParameters_CanResolveAliasedParameterValue()
        {
            // Arrange
            var model = new CustomersModelWithInheritance();
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            var function = new EdmFunction(
                model.Container.Namespace,
                "FunctionAtRoot",
                returnType,
                isBound: false,
                entitySetPathExpression: null,
                isComposable: true);
            function.AddParameter("IntParameter", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
            model.Container.AddFunctionImport("FunctionAtRoot", function, entitySet: null);

            // Act
            ODataPath path = _parser.Parse(model.Model, "FunctionAtRoot(IntParameter=@p1)");
            UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)path.Segments.Last();

            // Assert
            UnresolvedParameterValue unresolvedParamValue = functionSegment.GetParameterValue("IntParameter") as UnresolvedParameterValue;
            int intParameter = (int)unresolvedParamValue.Resolve(new Uri("http://services.odata.org/FunctionAtRoot(IntParameter=@p1)?@p1=1"));
            Assert.Equal(1, intParameter);
        }
        private static EdmFunction AddFunction(CustomersModelWithInheritance model, string name,
            IEdmTypeReference returnType = null, IEdmEntitySet entitySet = null, IEdmTypeReference bindingParameterType = null)
        {
            returnType = returnType ?? EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmExpression expression = entitySet == null ? null : new EdmEntitySetReferenceExpression(entitySet);

            var function = new EdmFunction(
                model.Container.Namespace,
                name,
                returnType,
                isBound: bindingParameterType != null,
                entitySetPathExpression: null,
                isComposable: true);
            if (bindingParameterType != null)
            {
                function.AddParameter("bindingParameter", bindingParameterType);
                model.Model.AddElement(function);
            }
            else
            {
                model.Container.AddFunctionImport(name, function, expression);
            }

            return function;
        }
Esempio n. 12
0
        public static IEdmModel ModelWithAllConceptsEdm()
        {
            var stringType = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String);

            var model = new EdmModel();
            var addressType = new EdmComplexType("NS1", "Address");
            addressType.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            addressType.AddStructuralProperty("City", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/30, /*isUnicode*/true));
            model.AddElement(addressType);

            var zipCodeType = new EdmComplexType("NS1", "ZipCode");
            zipCodeType.AddStructuralProperty("Main", new EdmStringTypeReference(stringType, /*isNullable*/false, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
            zipCodeType.AddStructuralProperty("Extended", new EdmStringTypeReference(stringType, /*isNullable*/true, /*isUnbounded*/false, /*maxLength*/5, /*isUnicode*/false));
            model.AddElement(zipCodeType);
            addressType.AddStructuralProperty("Zip", new EdmComplexTypeReference(zipCodeType, false));

            var foreignAddressType = new EdmComplexType("NS1", "ForeignAddress", addressType, false);
            foreignAddressType.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
            model.AddElement(foreignAddressType);

            var personType = new EdmEntityType("NS1", "Person", null, true, false);
            personType.AddKeys(personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
            model.AddElement(personType);

            var customerType = new EdmEntityType("NS1", "Customer", personType);
            customerType.AddStructuralProperty("IsVIP", EdmPrimitiveTypeKind.Boolean);
            customerType.AddProperty(new EdmStructuralProperty(customerType, "LastUpdated", EdmCoreModel.Instance.GetDateTimeOffset(false), null, EdmConcurrencyMode.Fixed));
            customerType.AddStructuralProperty("BillingAddress", new EdmComplexTypeReference(addressType, false));
            customerType.AddStructuralProperty("ShippingAddress", new EdmComplexTypeReference(addressType, false));
            model.AddElement(customerType);

            var orderType = new EdmEntityType("NS1", "Order");
            orderType.AddKeys(orderType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false));
            var customerIdProperty = orderType.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32, false);
            model.AddElement(orderType);

            var navProp1 = new EdmNavigationPropertyInfo { Name = "ToOrders", Target = orderType, TargetMultiplicity = EdmMultiplicity.Many, };
            var navProp2 = new EdmNavigationPropertyInfo { Name = "ToCustomer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One, DependentProperties = new[] { customerIdProperty }, PrincipalProperties = customerType.Key() };
            customerType.AddBidirectionalNavigation(navProp1, navProp2);

            var container = new EdmEntityContainer("NS1", "MyContainer");
            container.AddEntitySet("PersonSet", personType);
            container.AddEntitySet("OrderSet", orderType);
            model.AddElement(container);

            var function = new EdmFunction("NS1", "Function1", EdmCoreModel.Instance.GetInt64(true));
            function.AddParameter("Param1", EdmCoreModel.Instance.GetInt32(true));
            container.AddFunctionImport(function);
            model.AddElement(function);

            return model;
        }
Esempio n. 13
0
        public static IEdmModel EntityContainerWithOperationImportsEdm()
        {
            var model = new EdmModel();
            var customerType = new EdmEntityType("NS1", "Customer");
            customerType.AddKeys(customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(customerType);

            var container = new EdmEntityContainer("NS1", "MyContainer");
            var customerSet = container.AddEntitySet("Customer", customerType);

            var function = new EdmFunction("NS1", "GetCustomersExcluding", EdmCoreModel.GetCollection(new EdmEntityTypeReference(customerType, false)), false, null, false);
            function.AddParameter("CustomerId", EdmCoreModel.Instance.GetInt32(true));

            model.AddElement(function);
            container.AddFunctionImport("GetCustomersExcluding", function, new EdmEntitySetReferenceExpression(customerSet));

            model.AddElement(container);
            return model;
        }
        public void CannotParseOverloadUnboundFunctionWithDifferentParamterType(string uri)
        {
            // Arrange
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            model.AddElement(container);

            var unboundFunction = new EdmFunction("NS", "OverloadUnboundFunction", EdmCoreModel.Instance.GetInt32(false));
            unboundFunction.AddParameter("Parameter", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(unboundFunction);

            unboundFunction = new EdmFunction("NS", "OverloadUnboundFunction", EdmCoreModel.Instance.GetInt32(false));
            unboundFunction.AddParameter("Parameter", EdmCoreModel.Instance.GetString(false));
            model.AddElement(unboundFunction);

            // Act & Assert
            Assert.Throws<ODataUnrecognizedPathException>(
                () => _parser.Parse(model, _serviceRoot, _serviceRoot + uri),
                "Resource not found for the segment 'OverloadUnboundFunction'.");
        }
        private object GetParameterValue(object value, Type type)
        {
            var model = new CustomersModelWithInheritance();
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            var function = new EdmFunction(
                model.Container.Namespace,
                "FunctionAtRoot",
                returnType,
                isBound: false,
                entitySetPathExpression: null,
                isComposable: true);

            model.Model.SetAnnotationValue(model.Model.FindType("NS.SimpleEnum"), new ClrTypeAnnotation(typeof(SimpleEnum)));
            function.AddParameter("Parameter", model.Model.GetEdmTypeReference(type));
            model.Container.AddFunctionImport("FunctionAtRoot", function, entitySet: null);

            ODataPath path = _parser.Parse(
                model.Model,
                _serviceRoot,
                "FunctionAtRoot(Parameter=" + ODataUriUtils.ConvertToUriLiteral(value, ODataVersion.V4) + ")");
            UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)path.Segments.Last();

            return functionSegment.GetParameterValue("Parameter");
        }
Esempio n. 16
0
 void AddTableValueFunction(string name, EdmModel model, Dictionary<string, IEdmTypeReference> pars)
 {
     var container = model.EntityContainer as EdmEntityContainer;
     var t = BuildTableValueType(name, model);
     var func = new EdmFunction(container.Namespace, name, t, false, null, true);
     foreach (var item in pars)
     {
         func.AddParameter(item.Key, item.Value);
     }
     container.AddFunctionImport(func.Name, func, null, true);
     model.AddElement(func);
     TVFList.Add(func.Name);
     pars.Clear();
 }
        public void CanParse_FunctionParameters_CanResolveNestedAliasedParameterValues()
        {
            // Arrange
            var model = new CustomersModelWithInheritance();
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            var function = new EdmFunction(
                model.Container.Namespace,
                "BoundFunction",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: true);

            model.Model.SetAnnotationValue(model.Model.FindType("NS.SimpleEnum"), new ClrTypeAnnotation(typeof(SimpleEnum)));
            function.AddParameter("bindingParameter", model.Customer.ToEdmTypeReference(false));
            function.AddParameter("IntParameter", model.Model.GetEdmTypeReference(typeof(int)));
            function.AddParameter("NullableDoubleParameter", model.Model.GetEdmTypeReference(typeof(double?)));
            function.AddParameter("StringParameter", model.Model.GetEdmTypeReference(typeof(string)));
            function.AddParameter("GuidParameter", model.Model.GetEdmTypeReference(typeof(Guid)));
            function.AddParameter("EnumParameter", model.Model.GetEdmTypeReference(typeof(SimpleEnum)));
            model.Model.AddElement(function);

            // Act
            ODataPath path = _parser.Parse(model.Model, _serviceRoot, String.Format(
                "Customers(1)/NS.BoundFunction(StringParameter=@p2,IntParameter=@p0,NullableDoubleParameter=@p1," +
                "EnumParameter=@p4,GuidParameter=@p3)?@p2={2}&@p4={4}&@p1={1}&@p0={0}&@p999={3}&@p3=@p999",
                ODataUriUtils.ConvertToUriLiteral(123, ODataVersion.V4),
                ODataUriUtils.ConvertToUriLiteral(null, ODataVersion.V4),
                ODataUriUtils.ConvertToUriLiteral("123", ODataVersion.V4),
                ODataUriUtils.ConvertToUriLiteral(Guid.Empty, ODataVersion.V4),
                ODataUriUtils.ConvertToUriLiteral(new ODataEnumValue("Third", "NS.SimpleEnum"), ODataVersion.V4)));

            BoundFunctionPathSegment functionSegment = (BoundFunctionPathSegment)path.Segments.Last();
            object intParameter = functionSegment.GetParameterValue("IntParameter");
            object nullableDoubleParameter = functionSegment.GetParameterValue("NullableDoubleParameter");
            object stringParameter = functionSegment.GetParameterValue("StringParameter");
            object guidParameter = functionSegment.GetParameterValue("GuidParameter");
            object enumParameter = functionSegment.GetParameterValue("EnumParameter");

            // Assert
            Assert.Equal(123, intParameter);
            Assert.IsType<ODataNullValue>(nullableDoubleParameter);
            Assert.Equal("123", stringParameter);
            Assert.Equal(Guid.Empty, guidParameter);
            Assert.IsType<ODataEnumValue>(enumParameter);
            Assert.Equal("2", ((ODataEnumValue)enumParameter).Value);
            Assert.Equal("NS.SimpleEnum", ((ODataEnumValue)enumParameter).TypeName);
        }
Esempio n. 18
0
        public static IEdmModel CreateTripPinServiceModel(string ns)
        {
            EdmModel model = new EdmModel();
            var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
            model.AddElement(defaultContainer);

            var genderType = new EdmEnumType(ns, "PersonGender", isFlags: false);
            genderType.AddMember("Male", new EdmIntegerConstant(0));
            genderType.AddMember("Female", new EdmIntegerConstant(1));
            genderType.AddMember("Unknown", new EdmIntegerConstant(2));
            model.AddElement(genderType);

            var cityType = new EdmComplexType(ns, "City");
            cityType.AddProperty(new EdmStructuralProperty(cityType, "CountryRegion", EdmCoreModel.Instance.GetString(false)));
            cityType.AddProperty(new EdmStructuralProperty(cityType, "Name", EdmCoreModel.Instance.GetString(false)));
            cityType.AddProperty(new EdmStructuralProperty(cityType, "Region", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(cityType);

            var locationType = new EdmComplexType(ns, "Location", null, false, true);
            locationType.AddProperty(new EdmStructuralProperty(locationType, "Address", EdmCoreModel.Instance.GetString(false)));
            locationType.AddProperty(new EdmStructuralProperty(locationType, "City", new EdmComplexTypeReference(cityType, false)));
            model.AddElement(locationType);

            var eventLocationType = new EdmComplexType(ns, "EventLocation", locationType, false, true);
            eventLocationType.AddProperty(new EdmStructuralProperty(eventLocationType, "BuildingInfo", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(eventLocationType);

            var airportLocationType = new EdmComplexType(ns, "AirportLocation", locationType, false, true);
            airportLocationType.AddProperty(new EdmStructuralProperty(airportLocationType, "Loc", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, false)));
            model.AddElement(airportLocationType);

            var photoType = new EdmEntityType(ns, "Photo", null, false, false, true);
            var photoIdProperty = new EdmStructuralProperty(photoType, "Id", EdmCoreModel.Instance.GetInt64(false));
            photoType.AddProperty(photoIdProperty);
            photoType.AddKeys(photoIdProperty);
            photoType.AddProperty(new EdmStructuralProperty(photoType, "Name", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(photoType);

            var photoSet = new EdmEntitySet(defaultContainer, "Photos", photoType);
            defaultContainer.AddElement(photoSet);

            var personType = new EdmEntityType(ns, "Person", null, false, /* isOpen */ true);
            var personIdProperty = new EdmStructuralProperty(personType, "UserName", EdmCoreModel.Instance.GetString(false));
            personType.AddProperty(personIdProperty);
            personType.AddKeys(personIdProperty);
            personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true)))));
            personType.AddProperty(new EdmStructuralProperty(personType, "AddressInfo", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(locationType, true)))));
            personType.AddProperty(new EdmStructuralProperty(personType, "Gender", new EdmEnumTypeReference(genderType, true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Concurrency", EdmCoreModel.Instance.GetInt64(false)));
            model.AddElement(personType);

            var personSet = new EdmEntitySet(defaultContainer, "People", personType);
            defaultContainer.AddElement(personSet);

            var airlineType = new EdmEntityType(ns, "Airline");
            var airlineCodeProp = new EdmStructuralProperty(airlineType, "AirlineCode", EdmCoreModel.Instance.GetString(false));
            airlineType.AddKeys(airlineCodeProp);
            airlineType.AddProperty(airlineCodeProp);
            airlineType.AddProperty(new EdmStructuralProperty(airlineType, "Name", EdmCoreModel.Instance.GetString(false)));

            model.AddElement(airlineType);
            var airlineSet = new EdmEntitySet(defaultContainer, "Airlines", airlineType);
            defaultContainer.AddElement(airlineSet);

            var airportType = new EdmEntityType(ns, "Airport");
            var airportIdType = new EdmStructuralProperty(airportType, "IcaoCode", EdmCoreModel.Instance.GetString(false));
            airportType.AddProperty(airportIdType);
            airportType.AddKeys(airportIdType);
            airportType.AddProperty(new EdmStructuralProperty(airportType, "Name", EdmCoreModel.Instance.GetString(false)));
            airportType.AddProperty(new EdmStructuralProperty(airportType, "IataCode", EdmCoreModel.Instance.GetString(false)));
            airportType.AddProperty(new EdmStructuralProperty(airportType, "Location", new EdmComplexTypeReference(airportLocationType, false)));
            model.AddElement(airportType);

            var airportSet = new EdmEntitySet(defaultContainer, "Airports", airportType);
            defaultContainer.AddElement(airportSet);

            var planItemType = new EdmEntityType(ns, "PlanItem");
            var planItemIdType = new EdmStructuralProperty(planItemType, "PlanItemId", EdmCoreModel.Instance.GetInt32(false));
            planItemType.AddProperty(planItemIdType);
            planItemType.AddKeys(planItemIdType);
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "ConfirmationCode", EdmCoreModel.Instance.GetString(true)));
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(true)));
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(true)));
            planItemType.AddProperty(new EdmStructuralProperty(planItemType, "Duration", EdmCoreModel.Instance.GetDuration(true)));
            model.AddElement(planItemType);

            var publicTransportationType = new EdmEntityType(ns, "PublicTransportation", planItemType);
            publicTransportationType.AddProperty(new EdmStructuralProperty(publicTransportationType, "SeatNumber", EdmCoreModel.Instance.GetString(true)));
            model.AddElement(publicTransportationType);

            var flightType = new EdmEntityType(ns, "Flight", publicTransportationType);
            var flightNumberType = new EdmStructuralProperty(flightType, "FlightNumber", EdmCoreModel.Instance.GetString(false));
            flightType.AddProperty(flightNumberType);
            model.AddElement(flightType);

            var eventType = new EdmEntityType(ns, "Event", planItemType, false, true);
            eventType.AddProperty(new EdmStructuralProperty(eventType, "Description", EdmCoreModel.Instance.GetString(true)));
            eventType.AddProperty(new EdmStructuralProperty(eventType, "OccursAt", new EdmComplexTypeReference(eventLocationType, false)));
            model.AddElement(eventType);

            var tripType = new EdmEntityType(ns, "Trip");
            var tripIdType = new EdmStructuralProperty(tripType, "TripId", EdmCoreModel.Instance.GetInt32(false));
            tripType.AddProperty(tripIdType);
            tripType.AddKeys(tripIdType);
            tripType.AddProperty(new EdmStructuralProperty(tripType, "ShareId", EdmCoreModel.Instance.GetGuid(true)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Description", EdmCoreModel.Instance.GetString(true)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Name", EdmCoreModel.Instance.GetString(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Budget", EdmCoreModel.Instance.GetSingle(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(false)));
            tripType.AddProperty(new EdmStructuralProperty(tripType, "Tags", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))));
            model.AddElement(tripType);

            var friendsnNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Friends",
                Target = personType,
                TargetMultiplicity = EdmMultiplicity.Many
            });

            var personTripNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Trips",
                Target = tripType,
                TargetMultiplicity = EdmMultiplicity.Many,
                ContainsTarget = true
            });

            var personPhotoNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Photo",
                Target = photoType,
                TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
            });

            var tripPhotosNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Photos",
                Target = photoType,
                TargetMultiplicity = EdmMultiplicity.Many,
            });

            var tripItemNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "PlanItems",
                Target = planItemType,
                ContainsTarget = true,
                TargetMultiplicity = EdmMultiplicity.Many
            });

            var flightFromAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "From",
                Target = airportType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var flightToAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "To",
                Target = airportType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var flightAirlineNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Airline",
                Target = airlineType,
                TargetMultiplicity = EdmMultiplicity.One
            });

            var me = new EdmSingleton(defaultContainer, "Me", personType);
            defaultContainer.AddElement(me);

            personSet.AddNavigationTarget(friendsnNavigation, personSet);
            me.AddNavigationTarget(friendsnNavigation, personSet);

            personSet.AddNavigationTarget(flightAirlineNavigation, airlineSet);
            me.AddNavigationTarget(flightAirlineNavigation, airlineSet);

            personSet.AddNavigationTarget(flightFromAirportNavigation, airportSet);
            me.AddNavigationTarget(flightFromAirportNavigation, airportSet);

            personSet.AddNavigationTarget(flightToAirportNavigation, airportSet);
            me.AddNavigationTarget(flightToAirportNavigation, airportSet);

            personSet.AddNavigationTarget(personPhotoNavigation, photoSet);
            me.AddNavigationTarget(personPhotoNavigation, photoSet);

            personSet.AddNavigationTarget(tripPhotosNavigation, photoSet);
            me.AddNavigationTarget(tripPhotosNavigation, photoSet);

            var getFavoriteAirlineFunction = new EdmFunction(ns, "GetFavoriteAirline",
                new EdmEntityTypeReference(airlineType, false), true,
                new EdmPathExpression("person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline"), true);
            getFavoriteAirlineFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            model.AddElement(getFavoriteAirlineFunction);

            var getInvolvedPeopleFunction = new EdmFunction(ns, "GetInvolvedPeople",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(personType, false))), true, null, true);
            getInvolvedPeopleFunction.AddParameter("trip", new EdmEntityTypeReference(tripType, false));
            model.AddElement(getInvolvedPeopleFunction);

            var getFriendsTripsFunction = new EdmFunction(ns, "GetFriendsTrips",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(tripType, false))),
                true, new EdmPathExpression("person/Friends/Trips"), true);
            getFriendsTripsFunction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            getFriendsTripsFunction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
            model.AddElement(getFriendsTripsFunction);

            var getNearestAirport = new EdmFunction(ns, "GetNearestAirport",
                new EdmEntityTypeReference(airportType, false),
                false, null, true);
            getNearestAirport.AddParameter("lat", EdmCoreModel.Instance.GetDouble(false));
            getNearestAirport.AddParameter("lon", EdmCoreModel.Instance.GetDouble(false));
            model.AddElement(getNearestAirport);
            var getNearestAirportFunctionImport = (IEdmFunctionImport)defaultContainer.AddFunctionImport("GetNearestAirport", getNearestAirport, new EdmEntitySetReferenceExpression(airportSet), true);

            var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
            model.AddElement(resetDataSourceAction);
            defaultContainer.AddActionImport(resetDataSourceAction);

            var shareTripAction = new EdmAction(ns, "ShareTrip", null, true, null);
            shareTripAction.AddParameter("person", new EdmEntityTypeReference(personType, false));
            shareTripAction.AddParameter("userName", EdmCoreModel.Instance.GetString(false));
            shareTripAction.AddParameter("tripId", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(shareTripAction);

            model.SetDescriptionAnnotation(defaultContainer, "TripPin service is a sample service for OData V4.");
            model.SetOptimisticConcurrencyAnnotation(personSet, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
            // TODO: currently singleton does not support ETag feature
            // model.SetOptimisticConcurrencyAnnotation(me, personType.StructuralProperties().Where(p => p.Name == "Concurrency"));
            model.SetResourcePathCoreAnnotation(personSet, "People");
            model.SetResourcePathCoreAnnotation(me, "Me");
            model.SetResourcePathCoreAnnotation(airlineSet, "Airlines");
            model.SetResourcePathCoreAnnotation(airportSet, "Airports");
            model.SetResourcePathCoreAnnotation(photoSet, "Photos");
            model.SetResourcePathCoreAnnotation(getNearestAirportFunctionImport, "Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport");
            model.SetDereferenceableIDsCoreAnnotation(defaultContainer, true);
            model.SetConventionalIDsCoreAnnotation(defaultContainer, true);
            model.SetPermissionsCoreAnnotation(personType.FindProperty("UserName"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(airlineType.FindProperty("AirlineCode"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(airportType.FindProperty("IcaoCode"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(planItemType.FindProperty("PlanItemId"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(tripType.FindProperty("TripId"), CorePermission.Read);
            model.SetPermissionsCoreAnnotation(photoType.FindProperty("Id"), CorePermission.Read);
            model.SetImmutableCoreAnnotation(airportType.FindProperty("IataCode"), true);
            model.SetComputedCoreAnnotation(personType.FindProperty("Concurrency"), true);
            model.SetAcceptableMediaTypesCoreAnnotation(photoType, new[] { "image/jpeg" });
            model.SetConformanceLevelCapabilitiesAnnotation(defaultContainer, CapabilitiesConformanceLevelType.Advanced);
            model.SetSupportedFormatsCapabilitiesAnnotation(defaultContainer, new[] { "application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true" });
            model.SetAsynchronousRequestsSupportedCapabilitiesAnnotation(defaultContainer, true);
            model.SetBatchContinueOnErrorSupportedCapabilitiesAnnotation(defaultContainer, false);
            model.SetNavigationRestrictionsCapabilitiesAnnotation(personSet, CapabilitiesNavigationType.None, new[] { new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>(friendsnNavigation, CapabilitiesNavigationType.Recursive) });
            model.SetFilterFunctionsCapabilitiesAnnotation(defaultContainer, new[] { "contains", "endswith", "startswith", "length", "indexof", "substring", "tolower", "toupper", "trim", "concat", "year", "month", "day", "hour", "minute", "second", "round", "floor", "ceiling", "cast", "isof" });
            model.SetSearchRestrictionsCapabilitiesAnnotation(personSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(airlineSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(airportSet, true, CapabilitiesSearchExpressions.None);
            model.SetSearchRestrictionsCapabilitiesAnnotation(photoSet, true, CapabilitiesSearchExpressions.None);
            model.SetInsertRestrictionsCapabilitiesAnnotation(personSet, true, new[] { personTripNavigation, friendsnNavigation });
            model.SetInsertRestrictionsCapabilitiesAnnotation(airlineSet, true, null);
            model.SetInsertRestrictionsCapabilitiesAnnotation(airportSet, false, null);
            model.SetInsertRestrictionsCapabilitiesAnnotation(photoSet, true, null);
            // TODO: model.SetUpdateRestrictionsCapabilitiesAnnotation();
            model.SetDeleteRestrictionsCapabilitiesAnnotation(airportSet, false, null);
            model.SetISOCurrencyMeasuresAnnotation(tripType.FindProperty("Budget"), "USD");
            model.SetScaleMeasuresAnnotation(tripType.FindProperty("Budget"), 2);

            return model;
        }
        public void ParseAsUnresolvePathSegment_OverloadBoundFunctionWithDifferentParamterType(string uri, string unresolvedValue)
        {
            // Arrange
            EdmModel model = new EdmModel();
            var entityType = new EdmEntityType("NS", "EntityTypeName");
            entityType.AddKeys(entityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            model.AddElement(entityType);
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            model.AddElement(container);
            container.AddEntitySet("EntitySet", entityType);

            var boundFunction = new EdmFunction("NS", "OverloadBoundFunction", EdmCoreModel.Instance.GetInt32(false));
            boundFunction.AddParameter("bindingParameter", entityType.ToEdmTypeReference(false));
            boundFunction.AddParameter("FunctionParameter", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(boundFunction);

            boundFunction = new EdmFunction("NS", "OverloadBoundFunction", EdmCoreModel.Instance.GetInt32(false));
            boundFunction.AddParameter("bindingParameter", entityType.ToEdmTypeReference(false));
            boundFunction.AddParameter("FunctionParameter", EdmCoreModel.Instance.GetString(false));
            model.AddElement(boundFunction);

            // Act & Assert
            UnresolvedPathSegment unresolvedPathSegment = Assert.IsType<UnresolvedPathSegment>(
                _parser.Parse(model, _serviceRoot, _serviceRoot + uri).Segments.Last());
            Assert.Equal(unresolvedValue, unresolvedPathSegment.SegmentValue);
        }
 public void NonBoundOperationShouldNotWriteIsBoundAttribute()
 {
     EdmFunction function = new EdmFunction("Default.Namespace", "Checkout", EdmCoreModel.Instance.GetString(true) /*returnType*/, false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/);
     function.AddParameter("param", EdmCoreModel.Instance.GetString(true));
     this.TestWriteFunctionElementHeaderMethod(function, @"<Function Name=""Checkout""");
 }
        static FullPayloadValidateTests()
        {
            EntityType = new EdmEntityType("Namespace", "EntityType", null, false, false, false);
            EntityType.AddKeys(EntityType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            EntityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(isNullable: true), null, EdmConcurrencyMode.Fixed);
            DerivedType = new EdmEntityType("Namespace", "DerivedType", EntityType, false, true);

            var expandedCollectionNavProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Target = EntityType,
                TargetMultiplicity = EdmMultiplicity.Many,
                Name = "ExpandedCollectionNavProp"
            });

            var expandedNavProp = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Target = EntityType,
                TargetMultiplicity = EdmMultiplicity.One,
                Name = "ExpandedNavProp"
            });

            EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Target = EntityType,
                TargetMultiplicity = EdmMultiplicity.Many,
                Name = "ContainedCollectionNavProp",
                ContainsTarget = true
            });

            EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Target = EntityType,
                TargetMultiplicity = EdmMultiplicity.One,
                Name = "ContainedNavProp",
                ContainsTarget = true
            });

            var container = new EdmEntityContainer("Namespace", "Container");
            EntitySet = container.AddEntitySet("EntitySet", EntityType);

            EntitySet.AddNavigationTarget(expandedNavProp, EntitySet);
            EntitySet.AddNavigationTarget(expandedCollectionNavProp, EntitySet);

            Model = new EdmModel();
            Model.AddElement(EntityType);
            Model.AddElement(DerivedType);
            Model.AddElement(container);

            ModelWithFunction = new EdmModel();
            ModelWithFunction.AddElement(EntityType);
            ModelWithFunction.AddElement(DerivedType);
            ModelWithFunction.AddElement(container);

            EdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(EntityType, false);
            EdmCollectionTypeReference typeReference = new EdmCollectionTypeReference(new EdmCollectionType(entityTypeReference));
            EdmFunction function = new EdmFunction("Namespace", "Function", EdmCoreModel.Instance.GetBoolean(true), true, null, false);
            function.AddParameter("bindingParameter", typeReference);
            ModelWithFunction.AddElement(function);

            EdmAction action = new EdmAction("Namespace", "Action", EdmCoreModel.Instance.GetBoolean(true), true, null);
            action.AddParameter("bindingParameter", typeReference);
            ModelWithFunction.AddElement(action);
        }
Esempio n. 22
0
        private static void BoundFunction(EdmModel model, string funcName, string paramName, IEdmTypeReference edmType, IEdmEntityTypeReference bindingType)
        {
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);

            EdmFunction boundFunction = new EdmFunction("NS", funcName, returnType, isBound: true, entitySetPathExpression: null, isComposable: false);
            boundFunction.AddParameter("entity", bindingType);
            boundFunction.AddParameter(paramName, edmType);
            model.AddElement(boundFunction);
        }
Esempio n. 23
0
        public static IEdmModel FunctionWithAllEdm()
        {
            var model = new EdmModel();
            var function = new EdmFunction("NS1", "FunctionWithAll", EdmCoreModel.Instance.GetInt32(true));
            function.AddParameter("Param1", EdmCoreModel.Instance.GetInt32(false));
            model.AddElement(function);

            return model;
        }
Esempio n. 24
0
        private static void UnboundFunction(EdmEntityContainer container, string funcName, string paramName, IEdmTypeReference edmType)
        {
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);

            var unboundFunction = new EdmFunction("NS", funcName, returnType, isBound: false, entitySetPathExpression: null, isComposable: true);
            unboundFunction.AddParameter("key", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
            unboundFunction.AddParameter(paramName, edmType);
            container.AddFunctionImport(funcName, unboundFunction, entitySet: null);
        }
Esempio n. 25
0
        public static IEdmModel ModelWithEnumEdm(params IEdmEnumType[] enumTypes)
        {
            var model = new EdmModel();
            var complexType = new EdmComplexType("NS1", "Complex");
            model.AddElement(complexType);
            var entityType = new EdmEntityType("NS1", "Person");
            model.AddElement(entityType);
            var container = new EdmEntityContainer("NS1", "MyContainer");
            model.AddElement(container);

            int counter = 0;
            foreach (var enumType in enumTypes)
            {
                var enumTypeReference = new EdmEnumTypeReference(enumType, false);
                model.AddElement(enumType);
                complexType.AddStructuralProperty("EnumProperty" + counter, enumTypeReference);
                entityType.AddKeys(entityType.AddStructuralProperty("EnumProperty" + counter, enumTypeReference));
                var function = new EdmFunction("NS1", "Function" + counter, enumTypeReference);
                model.AddElement(function);
                container.AddFunctionImport(function);
                function.AddParameter("Param" + counter, enumTypeReference);
                counter++;
            }

            return model;
        }
        private IEdmModel GetEdmModel()
        {
            EdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Name");
            model.AddElement(container);
            var entityType = new EdmEntityType("NS", "EntityTypeName");
            model.AddElement(entityType);
            container.AddEntitySet("EntitySet", entityType);

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference stringType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false);

            // unbound function without parameter
            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType));

            // unbound function with one parameter
            var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType);
            functionWithOneParam.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOneParam);

            // unbound function with multiple parameters
            var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType);
            functionWithMultipleParams.AddParameter("Parameter1", parameterType);
            functionWithMultipleParams.AddParameter("Parameter2", parameterType);
            functionWithMultipleParams.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithMultipleParams);

            // unbound overload function
            container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType));
            var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads2.AddParameter("Parameter", parameterType);
            container.AddFunctionImport(functionWithOverloads2);

            var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType);
            functionWithOverloads3.AddParameter("Parameter1", parameterType);
            functionWithOverloads3.AddParameter("Parameter2", parameterType);
            functionWithOverloads3.AddParameter("Parameter3", parameterType);
            container.AddFunctionImport(functionWithOverloads3);

            // bound function with only binding parameter
            IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(entityType, isNullable: false);
            var boundFunction = new EdmFunction("NS", "BoundFunctionWithoutParams", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            model.AddElement(boundFunction);

            // bound function with binding and one non-binding parameter
            boundFunction = new EdmFunction("NS", "BoundFunctionWithOneParam", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter", parameterType);
            model.AddElement(boundFunction);

            // bound function with binding and multiple non-binding parameters
            boundFunction = new EdmFunction("NS", "BoundFunctionWithMultipleParams", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter1", parameterType);
            boundFunction.AddParameter("Parameter2", parameterType);
            boundFunction.AddParameter("Parameter3", parameterType);
            model.AddElement(boundFunction);

            // bound overload function with only binding parameter
            boundFunction = new EdmFunction("NS", "BoundFunctionOverload", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            model.AddElement(boundFunction);

            // bound overload function with binding and one non-binding parameter
            boundFunction = new EdmFunction("NS", "BoundFunctionOverload", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter", parameterType);
            model.AddElement(boundFunction);

            // bound overload function with binding and multiple non-binding parameters
            boundFunction = new EdmFunction("NS", "BoundFunctionOverload", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("Parameter1", parameterType);
            boundFunction.AddParameter("Parameter2", parameterType);
            boundFunction.AddParameter("Parameter3", parameterType);
            model.AddElement(boundFunction);

            // the following two bound functions have the same function name, same binding type and the same parameter name,
            // but the non-binding parameter type is different.
            boundFunction = new EdmFunction("NS", "BoundOverloadFailed", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("FunctionParameter", parameterType);
            model.AddElement(boundFunction);

            boundFunction = new EdmFunction("NS", "BoundOverloadFailed", returnType, true, null, true);
            boundFunction.AddParameter("bindingParameter", bindingParamterType);
            boundFunction.AddParameter("FunctionParameter", stringType);
            model.AddElement(boundFunction);

            // the following two unbound functions have the same function name and the same parameter name,
            // but the parameter type is different.
            var function = new EdmFunction("NS", "UnboundOverloadFailed", returnType);
            function.AddParameter("FunctionParameter", parameterType);
            container.AddFunctionImport(function);

            function = new EdmFunction("NS", "UnboundOverloadFailed", returnType);
            function.AddParameter("FunctionParameter", stringType);
            container.AddFunctionImport(function);

            return model;
        }
        public void CanParse_BoundFunction_AtEntityCollection()
        {
            // Arrange
            var model = new CustomersModelWithInheritance();
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmExpression entitySet = new EdmEntitySetReferenceExpression(model.Customers);
            var function = new EdmFunction(
                model.Container.Namespace,
                "Count",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: true);
            IEdmTypeReference bindingParameterType = new EdmCollectionTypeReference(
                new EdmCollectionType(new EdmEntityTypeReference(model.Customer, isNullable: false)));
            function.AddParameter("customers", bindingParameterType);
            model.Model.AddElement(function);

            // Act
            ODataPath path = _parser.Parse(model.Model, "Customers/NS.Count");

            // Assert
            Assert.NotNull(path);
            Assert.Equal(2, path.Segments.Count);
            var functionSegment = Assert.IsType<BoundFunctionPathSegment>(path.Segments.Last());
            Assert.Same(function, functionSegment.Function);
            Assert.Empty(functionSegment.Values);
        }
        public void GetTargetEntitySetForSingleton()
        {
            var model = new EdmModel();
            var container = new EdmEntityContainer("Fake", "Container");
            model.AddElement(container);
            var edmEntityType = new EdmEntityType("Fake", "EntityType");

            var singleton = container.AddSingleton("Singleton", edmEntityType);

            var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(edmEntityType, false), true, new EdmPathExpression("bindingparameter"), false);
            function.AddParameter("bindingparameter", new EdmEntityTypeReference(edmEntityType, false));
            var target = function.GetTargetEntitySet(singleton, model);
            target.Should().BeNull();
        }
        public void GetParameterValue_Returns_FunctionParameterValue()
        {
            // Arrange
            string parameterName = "Parameter";
            EdmModel model = new EdmModel();
            var entityType = new EdmEntityType("NS", "Customer");
            model.AddElement(entityType);

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false);
            IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(entityType, isNullable: false);
            EdmFunction function = new EdmFunction("NS", "Function", returnType);
            function.AddParameter("bindingParameter", bindingParamterType);
            function.AddParameter(parameterName, parameterType);
            model.AddElement(function);

            IDictionary<string, string> parameterValues = new Dictionary<string, string>();
            parameterValues.Add(parameterName, "101");

            // Act
            BoundFunctionPathSegment segment = new BoundFunctionPathSegment(function, model, parameterValues);
            var result = segment.GetParameterValue(parameterName);

            // Assert
            Assert.Equal("System.Int32", result.GetType().FullName);
            Assert.Equal("101", result.ToString());
        }
Esempio n. 30
0
 void AddEdmFunction(string spName,
     EdmModel model,
     Dictionary<string, IEdmTypeReference> pars,
     Dictionary<string, IEdmTypeReference> outPars)
 {
     IEdmTypeReference t = BuildSPReturnType(spName, model, outPars);
     EdmEntityContainer container = model.EntityContainer as EdmEntityContainer;
     var func = new EdmFunction(container.Namespace, spName, t, false, null, false);
     foreach (var item in pars)
     {
         func.AddParameter(item.Key, item.Value);
     }
     container.AddFunctionImport(func.Name, func, null, true);
     model.AddElement(func);
     pars.Clear();
     outPars.Clear();
 }