public static IEdmModel GetModelWithFunctionOverloadsWithSameParameterNames() { EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable"); IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)); vegetableType.AddKeys(id); EdmEntityContainer container = new EdmEntityContainer("Test", "Container"); var set = container.AddEntitySet("Vegetables", vegetableType); var function1 = new EdmFunction("Test", "Foo", new EdmEntityTypeReference(vegetableType, true), true /*isBound*/, null, true /*isComposable*/); function1.AddParameter("p1", new EdmEntityTypeReference(vegetableType, false)); function1.AddParameter("p2", EdmCoreModel.Instance.GetInt32(false)); container.AddFunctionImport("Foo", function1, new EdmPathExpression("Vegetables")); var function2 = new EdmFunction("Test", "Foo", new EdmEntityTypeReference(vegetableType, true), true /*isBound*/, null, true /*isComposable*/); function2.AddParameter("p1", new EdmEntityTypeReference(vegetableType, false)); function2.AddParameter("p2", EdmCoreModel.Instance.GetString(false)); container.AddFunctionImport("Foo", function2, new EdmPathExpression("Vegetables")); EdmModel model = new EdmModel(); model.AddElement(container); model.AddElement(vegetableType); model.AddElement(function1); model.AddElement(function2); return(model); }
private static IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); IEdmTypeReference stringType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false); IEdmTypeReference intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmFunction calcByRating1 = new EdmFunction("NS", "CalcByRating", returnType, false, entitySetPathExpression: null, isComposable: false); calcByRating1.AddParameter("order", intType); model.AddElement(calcByRating1); container.AddFunctionImport(calcByRating1); EdmFunction calcByRating2 = new EdmFunction("NS", "CalcByRating", returnType, false, entitySetPathExpression: null, isComposable: false); calcByRating2.AddParameter("name", stringType); model.AddElement(calcByRating2); container.AddFunctionImport(calcByRating2); EdmAction calcByRatingAction = new EdmAction("NS", "CalcByRatingAction", returnType, false, null); calcByRatingAction.AddParameter("name", stringType); model.AddElement(calcByRatingAction); container.AddActionImport(calcByRatingAction); model.AddElement(container); return(model); }
public ODataJsonLightUtilsTests() { this.MetadataDocumentUri = new Uri("http://www.myhost.com/myservice.svc/$metadata"); this.model = new EdmModel(); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); this.model.AddElement(defaultContainer); this.cityType = new EdmEntityType("TestModel", "City"); EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false)); cityType.AddKeys(cityIdProperty); cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/ false)); cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false)); this.model.AddElement(cityType); EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType"); this.model.AddElement(complexType); this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationImportWithNoOverload = defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload); this.model.AddElement(operationWithNoOverload); this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param); this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); this.model.AddElement(operationWithOverloadAnd1Param); this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param); this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); var cityTypeReference = new EdmEntityTypeReference(this.cityType, isNullable: false); this.operationWithOverloadAnd2Params.AddParameter("p1", cityTypeReference); this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true)); this.model.AddElement(operationWithOverloadAnd2Params); this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params); this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(cityTypeReference))); this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)))); this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true)); EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false); this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference); this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference))); this.model.AddElement(operationWithOverloadAnd5Params); this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params); }
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); }
internal void AddUserFunction(Function function) { if (function is Action) { AddAction(function as Action); return; } EdmFunction edmFunction; EdmEntityContainer entityContainer = (EdmEntityContainer)EntityContainer; IEdmTypeReference edmTypeReference = GetNotEntityTypeReference(function.ReturnType); if (edmTypeReference == null) { edmTypeReference = GetCollectionNotEntityTypeReference(function.ReturnType); } if (edmTypeReference != null) { edmFunction = new EdmFunction(DefaultNamespace, function.Name, edmTypeReference, false, null, false); entityContainer.AddFunctionImport(edmFunction); } else { IEdmTypeReference returnEdmTypeReference = GetEdmTypeReference(function.ReturnType, out IEdmEntityType returnEntityType, out bool isCollection); if (returnEntityType == null) { throw new ArgumentNullException("Тип возвращаемого результата пользовательской функции не найден в модели OData."); } edmFunction = new EdmFunction(DefaultNamespace, function.Name, returnEdmTypeReference, true, null, true); edmFunction.AddParameter("bindingParameter", returnEdmTypeReference); entityContainer.AddFunctionImport(function.Name, edmFunction, new EdmEntitySetReferenceExpression(GetEdmEntitySet(returnEntityType)), true); } AddElement(edmFunction); foreach (var parameter in function.ParametersTypes.Keys) { Type paramType = function.ParametersTypes[parameter]; IEdmEnumType enumType = GetEdmEnumType(paramType); var edmParameterType = EdmTypeMap.GetEdmPrimitiveType(paramType); if (edmParameterType != null) { edmFunction.AddParameter(parameter, new EdmPrimitiveTypeReference(edmParameterType, false)); } if (enumType != null) { edmFunction.AddParameter(parameter, new EdmEnumTypeReference(enumType, false)); } } }
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", function2, null, true /*IncludeInServiceDocument*/); // Parameterless unbound function. EdmFunction function3 = new EdmFunction("TestModel", "SimpleFunction3", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true); defaultContainer.AddFunctionImport("SimpleFunctionImport3", function3, null, true /*IncludeInServiceDocument*/); return(model); }
public void OverloadServiceOperationSuccessfullyResolved() { var model = new EdmModel(); // Add function without parameter. var int32TypeReference = EdmCoreModel.Instance.GetInt32(false); var functionWithoutParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); model.AddElement(functionWithoutParameter); // Add function with parameter. var functionWithParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithParameter.AddParameter("Parameter", int32TypeReference); model.AddElement(functionWithParameter); // Add function with two parameters. var functionWithTwoParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithTwoParameter.AddParameter("Parameter", int32TypeReference); functionWithTwoParameter.AddParameter("Parameter2", int32TypeReference); model.AddElement(functionWithTwoParameter); // Add function import. var container = new EdmEntityContainer("Fully.Qualified.Namespace", "Container"); model.AddElement(container); var functionImportWithoutParameter = container.AddFunctionImport("FunctionImport", functionWithoutParameter); var functionImportWithParameter = container.AddFunctionImport("FunctionImport", functionWithParameter); var functionImportWithTwoParameter = container.AddFunctionImport("FunctionImport", functionWithTwoParameter); IEdmOperationImport functionImport; // Resolve overload function import without parameter. var parameters = new string[] { }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, ODataUriResolver.Default).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithoutParameter); // Resolve overload function import with parameter. parameters = new string[] { "Parameter" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, ODataUriResolver.Default).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithParameter); // Resolve overload function import with parameter. parameters = new string[] { "Parameter", "Parameter2" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, ODataUriResolver.Default).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithTwoParameter); }
private static IEdmModel CreateModel() { var model = new EdmModel(); var orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); model.AddElement(orderType); var customerType = new EdmEntityType("Default", "Customer"); customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); model.AddElement(customerType); // Add navigations orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); var container = new EdmEntityContainer("Default", "Container"); var orderSet = container.AddEntitySet("Orders", orderType); var customerSet = container.AddEntitySet("Customers", customerType); container.AddFunctionImport("GetId", new EdmPrimitiveTypeReference( EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true)); orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet); model.AddElement(container); return(model); }
/// <summary> /// Adds the function and function import. /// </summary> /// <param name="container">The container.</param> /// <param name="model">The model.</param> /// <param name="name">The name.</param> /// <param name="returnType">Type of the return.</param> /// <param name="entitySet">The entity set.</param> /// <param name="isComposable">if set to <c>true</c> [is composable].</param> /// <param name="isBound">if set to <c>true</c> [is bound].</param> /// <returns></returns> public static EdmFunctionImport AddFunctionAndFunctionImport(this EdmEntityContainer container, EdmModel model, string name, IEdmTypeReference returnType, IEdmExpression entitySet = null, bool isComposable = false, bool isBound = false) { EdmFunction function = new EdmFunction(container.Namespace, name, returnType, isBound, null, isComposable); model.AddElement(function); return(container.AddFunctionImport(name, function, entitySet)); }
/// <summary> /// Creates a new function import with the specified name. /// </summary> /// <param name="container">The <see cref="EntityContainer"/> to create the function import in.</param> /// <param name="localName">The name for the function import to create.</param> /// <returns>The newly created function import instance.</returns> public static EdmFunctionImport FunctionImport(this EdmEntityContainer container, IEdmFunction function) { ExceptionUtilities.CheckArgumentNotNull(container, "container"); ExceptionUtilities.CheckArgumentNotNull(function, "function"); return(container.AddFunctionImport(function.Name, function)); }
public void ParseODataUriTemplate_ForFunctionImport(string template, int parameterCount) { // Arrange EdmFunction getSalaray = new EdmFunction("NS", "GetWholeSalaryImport", IntType, isBound: false, entitySetPathExpression: null, isComposable: false); getSalaray.AddParameter("minSalary", IntType); getSalaray.AddOptionalParameter("maxSalary", IntType); getSalaray.AddOptionalParameter("aveSalary", IntType, "129"); _edmModel.AddElement(getSalaray); EdmEntityContainer container = _edmModel.SchemaElements.OfType <EdmEntityContainer>().First(); container.AddFunctionImport(getSalaray); IODataPathTemplateParser parser = new DefaultODataPathTemplateParser(); // Act ODataPathTemplate path = parser.Parse(_edmModel, template, null); // Assert Assert.NotNull(path); ODataSegmentTemplate segmentTemplate = Assert.Single(path); FunctionImportSegmentTemplate functionImportSegment = Assert.IsType <FunctionImportSegmentTemplate>(segmentTemplate); if (parameterCount == 2) { Assert.Equal(new[] { "minSalary", "maxSalary" }, functionImportSegment.ParameterMappings.Keys); Assert.Equal(new[] { "min", "max" }, functionImportSegment.ParameterMappings.Values); } else { Assert.Equal(new[] { "minSalary", "maxSalary", "aveSalary" }, functionImportSegment.ParameterMappings.Keys); Assert.Equal(new[] { "min", "max", "ave" }, functionImportSegment.ParameterMappings.Values); } }
public static IEdmModel GetModelWithMixedActionsAndFunctionsWithSameName() { EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable"); IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)); vegetableType.AddKeys(id); EdmEntityContainer container = new EdmEntityContainer("Test", "Container"); var set = container.AddEntitySet("Vegetables", vegetableType); var action1 = new EdmAction("Test", "Foo", new EdmEntityTypeReference(vegetableType, true), false /*isBound*/, null /*entitySetPath*/); action1.AddParameter("p1", new EdmEntityTypeReference(vegetableType, false)); container.AddActionImport("Foo", action1, new EdmEntitySetReferenceExpression(set)); var function1 = new EdmFunction("Test", "Foo", new EdmEntityTypeReference(vegetableType, true), false /*isBound*/, null, true); function1.AddParameter("p1", new EdmEntityTypeReference(vegetableType, false)); function1.AddParameter("p2", EdmCoreModel.Instance.GetInt32(false)); container.AddFunctionImport("Foo", function1, new EdmEntitySetReferenceExpression(set)); EdmModel model = new EdmModel(); model.AddElement(container); model.AddElement(vegetableType); model.AddElement(action1); model.AddElement(function1); return(model); }
public static EdmFunctionImport AddFunctionAndFunctionImport(this EdmEntityContainer container, EdmModel model, string name, IEdmTypeReference returnType) { EdmFunction function = new EdmFunction(container.Namespace, name, returnType, false /*isBound*/, null, false /*isComposable*/); model.AddElement(function); return(container.AddFunctionImport(name, function)); }
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); }
public EdmLibraryExtensionsTests() { this.model = TestModel.BuildDefaultTestModel(); this.defaultContainer = (EdmEntityContainer)this.model.FindEntityContainer("Default"); this.productsSet = this.defaultContainer.FindEntitySet("Products"); this.productType = (IEdmEntityType)this.model.FindDeclaredType("TestModel.Product"); this.productTypeReference = new EdmEntityTypeReference(this.productType, false); EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType"); this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithNoOverload.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); this.model.AddElement(operationWithNoOverload); this.operationImportWithNoOverload = this.defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload); this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.model.AddElement(operationWithOverloadAnd0Param); this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param); this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); this.model.AddElement(operationWithOverloadAnd1Param); this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param); this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); var productTypeReference = new EdmEntityTypeReference(productType, isNullable: false); this.operationWithOverloadAnd2Params.AddParameter("p1", productTypeReference); this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true)); this.model.AddElement(operationWithOverloadAnd2Params); this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params); this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(productTypeReference))); this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)))); this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true)); EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false); this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference); this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference))); this.model.AddElement(operationWithOverloadAnd5Params); this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params); }
public void EnsureFunctionImportIsAddedAndWithCorrectSuppliedName() { EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmFunction function = new EdmFunction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false)); var functionImport = container.AddFunctionImport("OtherName", function); Assert.Same(function, functionImport.Function); Assert.Equal("OtherName", functionImport.Name); Assert.Same(functionImport, container.Elements.ToArray()[0]); }
public void EnsureFunctionImportIsAddedWithActionSuppliedName() { EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmFunction function = new EdmFunction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false)); var functionImport = container.AddFunctionImport(function); functionImport.Function.Should().Be(function); functionImport.Name.Should().Be(function.Name); container.Elements.ToArray()[0].Should().Be(functionImport); }
public void GetTargetEntitySetForFunctionWithStaticSet() { var model = new EdmModel(); var container = new EdmEntityContainer("Fake", "Container"); model.AddElement(container); var entitySet = container.AddEntitySet("EntitySet", new EdmEntityType("Fake", "EntityType")); var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(entitySet.EntityType(), false)); var operationImport = container.AddFunctionImport("FakeAction", function, new EdmEntitySetReferenceExpression(entitySet)); operationImport.GetTargetEntitySet(null, model).Should().BeSameAs(entitySet); }
public void GetTargetEntitySetForFunctionWithNoStaticSetOrSourceSetShouldBeNull() { var model = new EdmModel(); var container = new EdmEntityContainer("Fake", "Container"); model.AddElement(container); var function = new EdmFunction("Fake", "FakeFunction", new EdmEntityTypeReference(new EdmEntityType("Fake", "EntityType"), false)); var expression = new EdmPathExpression("p1/Navigation1"); var operationImport = container.AddFunctionImport("FakeAction", function, expression); operationImport.GetTargetEntitySet(null, model).Should().BeNull(); }
public void ParsePathFunctionWithNullEntitySetPath() { var model = new EdmModel(); var customer = new EdmEntityType("Test", "Customer", null, false, false); var customerId = customer.AddStructuralProperty("id", EdmPrimitiveTypeKind.String, false); customer.AddKeys(customerId); model.AddElement(customer); var detail = new EdmEntityType("Test", "Detail", null, false, true); detail.AddStructuralProperty("address", EdmPrimitiveTypeKind.String, true); model.AddElement(detail); var customerDetail = customer.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo() { Name = "detail", Target = detail, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true }); // The test is to make sure the ODataUriParser works even though // the entitySetPathExpression is null. var getCurrentCustomer = new EdmFunction( "Test", "getCurrentCustomer", new EdmEntityTypeReference(customer, false), isBound: false, entitySetPathExpression: null, isComposable: true); model.AddElement(getCurrentCustomer); var container = new EdmEntityContainer("Test", "Container"); var getCurrentCustomerImport = container.AddFunctionImport(getCurrentCustomer); model.AddElement(container); var parser = new ODataUriParser(model, new Uri("http://host"), new Uri("http://host/getCurrentCustomer()/detail")); var path = parser.ParsePath(); var pathSegmentList = path.ToList(); pathSegmentList.Count.Should().Be(2); pathSegmentList[0].ShouldBeOperationImportSegment(getCurrentCustomerImport); pathSegmentList[1].ShouldBeNavigationPropertySegment(customerDetail); }
private static IEdmFunctionImport AddBindableAction(EdmEntityContainer container, string name, IEdmEntityType bindingType, bool isCollection) { var action = container.AddFunctionImport(name, returnType: null, entitySet: null, sideEffecting: true, composable: false, bindable: true); IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(bindingType, isNullable: false); if (isCollection) { bindingParamterType = new EdmCollectionTypeReference( new EdmCollectionType(bindingParamterType), isNullable: false); } action.AddParameter("bindingParameter", bindingParamterType); return(action); }
public void HeterogeneousCollectionReaderTest() { EdmModel model = new EdmModel(); var cityType = new EdmComplexType("TestModel", "CityType"); cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); model.AddElement(cityType); var addressType = new EdmComplexType("TestModel", "AddressType"); addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true)); model.AddElement(addressType); var testContainer = new EdmEntityContainer("TestModel", "TestContainer"); model.AddElement(testContainer); EdmFunction citiesFunction = new EdmFunction("TestModel", "Cities", EdmCoreModel.GetCollection(cityType.ToTypeReference())); model.AddElement(citiesFunction); EdmOperationImport citiesFunctionImport = testContainer.AddFunctionImport("Cities", citiesFunction); model.Fixup(); // Add some hand-crafted payloads IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[] { // expected type without type names in the payload and heterogeneous items new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = new ComplexInstanceCollection( PayloadBuilder.ComplexValue().Property("Name", PayloadBuilder.PrimitiveValue("Vienna")), PayloadBuilder.ComplexValue().Property("Street", PayloadBuilder.PrimitiveValue("Am Euro Platz"))) .ExpectedFunctionImport(citiesFunctionImport) .CollectionName(null), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "Street", "TestModel.CityType"), }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration); }); }
public static EdmModel GetModelWithServiceOperationWithMissingReturnSet() { EdmEntityType vegetableType = new EdmEntityType("Test", "Vegetable"); IEdmStructuralProperty id = vegetableType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)); vegetableType.AddKeys(id); // Note how the entity set expression is null even though it returns an entity EdmEntityContainer container = new EdmEntityContainer("Test", "Container"); var function = new EdmFunction("Test", "Container", new EdmEntityTypeReference(vegetableType, true)); container.AddFunctionImport("GetVegetableWithMissingSet", function, null); EdmModel model = new EdmModel(); model.AddElement(container); model.AddElement(vegetableType); return(model); }
static ODataJsonLightEntryAndFeedDeserializerTests() { EdmModel tmpModel = new EdmModel(); EdmComplexType complexType = new EdmComplexType("TestNamespace", "TestComplexType"); complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(false))); tmpModel.AddElement(complexType); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); tmpModel.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub"); tmpModel.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); defaultContainer.AddElement(EntitySet); Action = new EdmAction("TestNamespace", "DoSomething", null, true, null); Action.AddParameter("p1", new EdmEntityTypeReference(EntityType, false)); tmpModel.AddElement(Action); ActionImport = defaultContainer.AddActionImport("DoSomething", Action); var serviceOperationFunction = new EdmFunction("TestNamespace", "ServiceOperation", EdmCoreModel.Instance.GetInt32(true)); defaultContainer.AddFunctionImport("ServiceOperation", serviceOperationFunction); tmpModel.AddElement(serviceOperationFunction); tmpModel.AddElement(new EdmTerm("custom", "DateTimeOffsetAnnotation", EdmPrimitiveTypeKind.DateTimeOffset)); tmpModel.AddElement(new EdmTerm("custom", "DateAnnotation", EdmPrimitiveTypeKind.Date)); tmpModel.AddElement(new EdmTerm("custom", "TimeOfDayAnnotation", EdmPrimitiveTypeKind.TimeOfDay)); EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel); MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }; MessageReaderSettingsIgnoreInstanceAnnotations = new ODataMessageReaderSettings(); }
public CustomersModelWithInheritance() { EdmModel model = new EdmModel(); // complex type address EdmComplexType address = new EdmComplexType("NS", "Address"); address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("State", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String); model.AddElement(address); // entity type customer EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); customer.AddStructuralProperty("Address", new EdmComplexTypeReference(address, isNullable: true)); customer.AddStructuralProperty("City", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, true), defaultValue: null, concurrencyMode: EdmConcurrencyMode.Fixed); model.AddElement(customer); // derived entity type special customer EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer); specialCustomer.AddStructuralProperty("SpecialCustomerProperty", EdmPrimitiveTypeKind.Guid); model.AddElement(specialCustomer); // entity type order EdmEntityType order = new EdmEntityType("NS", "Order"); order.AddKeys(order.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32); model.AddElement(order); // derived entity type special order EdmEntityType specialOrder = new EdmEntityType("NS", "SpecialOrder", order); specialOrder.AddStructuralProperty("SpecialOrderProperty", EdmPrimitiveTypeKind.Guid); model.AddElement(specialOrder); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance"); model.AddElement(container); EdmEntitySet customers = container.AddEntitySet("Customers", customer); EdmEntitySet orders = container.AddEntitySet("Orders", order); // actions EdmFunctionImport upgradeCustomer = container.AddFunctionImport( "upgrade", returnType: null, entitySet: new EdmEntitySetReferenceExpression(customers), sideEffecting: true, composable: false, bindable: true); upgradeCustomer.AddParameter("entity", new EdmEntityTypeReference(customer, false)); EdmFunctionImport upgradeSpecialCustomer = container.AddFunctionImport( "specialUpgrade", returnType: null, entitySet: new EdmEntitySetReferenceExpression(customers), sideEffecting: true, composable: false, bindable: true); upgradeSpecialCustomer.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false)); // navigation properties customers.AddNavigationTarget( customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", TargetMultiplicity = EdmMultiplicity.Many, Target = order }), orders); orders.AddNavigationTarget( order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = customer }), customers); // navigation properties on derived types. customers.AddNavigationTarget( specialCustomer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "SpecialOrders", TargetMultiplicity = EdmMultiplicity.Many, Target = order }), orders); orders.AddNavigationTarget( specialOrder.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "SpecialCustomer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = customer }), customers); model.SetAnnotationValue <BindableProcedureFinder>(model, new BindableProcedureFinder(model)); // set properties Model = model; Container = container; Customer = customer; Order = order; Address = address; SpecialCustomer = specialCustomer; SpecialOrder = specialOrder; Orders = orders; Customers = customers; UpgradeCustomer = upgradeCustomer; UpgradeSpecialCustomer = upgradeSpecialCustomer; }
public void OverloadServiceOperationSuccessfullyResolved() { var model = new EdmModel(); // Add function without parameter. var int32TypeReference = EdmCoreModel.Instance.GetInt32(false); var functionWithoutParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); model.AddElement(functionWithoutParameter); // Add function with parameter. var functionWithParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithParameter.AddParameter("Parameter", int32TypeReference); model.AddElement(functionWithParameter); // Add function with two parameters. var functionWithTwoParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithTwoParameter.AddParameter("Parameter", int32TypeReference); functionWithTwoParameter.AddParameter("Parameter2", int32TypeReference); model.AddElement(functionWithTwoParameter); // Add function with two required and two optional parameters. var functionWithTwoRequiredOneOptionalParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithTwoRequiredOneOptionalParameter.AddParameter("Parameter", int32TypeReference); functionWithTwoRequiredOneOptionalParameter.AddParameter("Parameter2", int32TypeReference); functionWithTwoRequiredOneOptionalParameter.AddOptionalParameter("Parameter3", int32TypeReference); functionWithTwoRequiredOneOptionalParameter.AddOptionalParameter("Parameter4", int32TypeReference); model.AddElement(functionWithTwoRequiredOneOptionalParameter); // Add function with one required and one optional parameters. var functionWithOneRequiredOneOptionalParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithOneRequiredOneOptionalParameter.AddParameter("Parameter1", int32TypeReference); functionWithOneRequiredOneOptionalParameter.AddOptionalParameter("Parameter3", int32TypeReference); model.AddElement(functionWithOneRequiredOneOptionalParameter); // Add function with one required and two optional parameters. var functionWithOneRequiredTwoOptionalParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference); functionWithOneRequiredTwoOptionalParameter.AddParameter("Parameter1", int32TypeReference); functionWithOneRequiredTwoOptionalParameter.AddOptionalParameter("Parameter3", int32TypeReference); functionWithOneRequiredTwoOptionalParameter.AddOptionalParameter("Parameter4", int32TypeReference); model.AddElement(functionWithOneRequiredTwoOptionalParameter); // Add function with one required and two optional parameters. var functionWithOneRequiredThreeOptionalParameter = new EdmFunction("Fully.Qualified.Namespace", "Function", int32TypeReference, true, null, true); functionWithOneRequiredThreeOptionalParameter.AddParameter("BindingParameter", int32TypeReference); functionWithOneRequiredThreeOptionalParameter.AddParameter("Parameter1", int32TypeReference); functionWithOneRequiredThreeOptionalParameter.AddOptionalParameter("Parameter3", int32TypeReference); functionWithOneRequiredThreeOptionalParameter.AddOptionalParameter("Parameter4", int32TypeReference); functionWithOneRequiredThreeOptionalParameter.AddOptionalParameter("Parameter5", int32TypeReference); model.AddElement(functionWithOneRequiredThreeOptionalParameter); // Add function import. var container = new EdmEntityContainer("Fully.Qualified.Namespace", "Container"); model.AddElement(container); var functionImportWithoutParameter = container.AddFunctionImport("FunctionImport", functionWithoutParameter); var functionImportWithParameter = container.AddFunctionImport("FunctionImport", functionWithParameter); var functionImportWithTwoParameter = container.AddFunctionImport("FunctionImport", functionWithTwoParameter); var functionImportWithTwoRequiredOneOptionalParameter = container.AddFunctionImport("FunctionImport", functionWithTwoRequiredOneOptionalParameter); var functionImportWithOneRequiredOneOptionalParameter = container.AddFunctionImport("FunctionImport", functionWithOneRequiredOneOptionalParameter); var functionImportWithOneRequiredTwoOptionalParameter = container.AddFunctionImport("FunctionImport", functionWithOneRequiredTwoOptionalParameter); var functionImportWithOneRequiredThreeOptionalParameter = container.AddFunctionImport("FunctionImport", functionWithOneRequiredThreeOptionalParameter); IEdmOperationImport functionImport; // Resolve overload function import without parameter. var parameters = new string[] { }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithoutParameter); // Resolve overload function import with parameter. parameters = new string[] { "Parameter" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithParameter); // Resolve overload function import with parameter. parameters = new string[] { "Parameter", "Parameter2" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithTwoParameter); // Resolve overload function with two required and one optional parameter. parameters = new string[] { "Parameter", "Parameter2", "Parameter3" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithTwoRequiredOneOptionalParameter); // Resolve overload function with one required and two optional parameters. parameters = new string[] { "Parameter1", "Parameter3" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithOneRequiredOneOptionalParameter); // Resolve overload function with one required and three optional parameters (one omitted). parameters = new string[] { "Parameter1", "Parameter3", "Parameter5" }; FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver).Should().BeTrue(); functionImport.Should().BeSameAs(functionImportWithOneRequiredThreeOptionalParameter); // Raise exception if more than one match. parameters = new string[] { "Parameter1", "Parameter4" }; Action resolve = () => FunctionOverloadResolver.ResolveOperationImportFromList("FunctionImport", parameters, model, out functionImport, DefaultUriResolver); resolve.ShouldThrow <ODataException>().WithMessage(ODataErrorStrings.FunctionOverloadResolver_MultipleOperationImportOverloads("FunctionImport")); }
public EdmModel BuildEdmModel() { Dictionary <Type, EntityTypeInfo> entityTypeInfos = BuildEntityTypes(); foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { typeInfo.BuildProperties(entityTypeInfos, _enumTypes, _complexTypes); } foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { foreach (FKeyInfo fkeyInfo in typeInfo.NavigationClrProperties) { fkeyInfo.EdmNavigationProperty = CreateNavigationProperty(fkeyInfo); } } var edmModel = new EdmModel(); var container = new EdmEntityContainer("Default", "Container"); edmModel.AddElements(_enumTypes.Values); foreach (KeyValuePair <Type, EdmEnumType> enumType in _enumTypes) { edmModel.SetClrType(enumType.Value, enumType.Key); } edmModel.AddElements(_complexTypes.Values); foreach (KeyValuePair <Type, EdmComplexType> complexType in _complexTypes) { edmModel.SetClrType(complexType.Value, complexType.Key); } var entitySets = new Dictionary <IEdmEntityType, EdmEntitySet>(entityTypeInfos.Count); foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { edmModel.AddElement(typeInfo.EdmType); edmModel.SetClrType(typeInfo.EdmType, typeInfo.ClrType); foreach (KeyValuePair <String, Type> pair in _entitySets) { if (pair.Value == typeInfo.ClrType) { entitySets.Add(typeInfo.EdmType, container.AddEntitySet(pair.Key, typeInfo.EdmType)); break; } } } foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { foreach (FKeyInfo fkeyInfo in typeInfo.NavigationClrProperties) { EdmEntitySet principal = entitySets[fkeyInfo.PrincipalInfo.EdmType]; EdmEntitySet dependent = entitySets[fkeyInfo.DependentInfo.EdmType]; dependent.AddNavigationTarget(fkeyInfo.EdmNavigationProperty, principal); if (fkeyInfo.EdmNavigationProperty.Partner != null) { principal.AddNavigationTarget(fkeyInfo.EdmNavigationProperty.Partner, dependent); } } } foreach (OeOperationConfiguration operationConfiguration in _operationConfigurations) { if (operationConfiguration.IsEdmFunction) { EdmFunction edmFunction = BuildFunction(operationConfiguration, entityTypeInfos); if (edmFunction != null) { edmModel.AddElement(edmFunction); container.AddFunctionImport(operationConfiguration.Name, edmFunction); edmModel.SetIsDbFunction(edmFunction, operationConfiguration.IsDbFunction); } } else { EdmAction edmAction = BuildAction(operationConfiguration, entityTypeInfos); if (edmAction != null) { edmModel.AddElement(edmAction); container.AddActionImport(operationConfiguration.Name, edmAction); edmModel.SetIsDbFunction(edmAction, operationConfiguration.IsDbFunction); } } } edmModel.AddElement(container); return(edmModel); }
static ExtensionTestBase() { var model = new EdmModel(); Model = model; var person = new EdmEntityType("TestNS", "Person"); var personId = person.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); PersonNameProp = person.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); PersonPen = person.AddStructuralProperty("pen", EdmPrimitiveTypeKind.Binary); person.AddKeys(personId); PersonType = person; var address = new EdmComplexType("TestNS", "Address"); AddrType = address; ZipCodeProperty = address.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String); AddrProperty = person.AddStructuralProperty("Addr", new EdmComplexTypeReference(address, false)); var pencil = new EdmEntityType("TestNS", "Pencil"); var pencilId = pencil.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); PencilId = pencilId; var pid = pencil.AddStructuralProperty("Pid", EdmPrimitiveTypeKind.Int32); pencil.AddKeys(pencilId); var starPencil = new EdmEntityType("TestNS", "StarPencil", pencil); model.AddElement(starPencil); var starPencilUpper = new EdmEntityType("TestNS", "STARPENCIL"); model.AddElement(starPencilUpper); StarPencil = starPencil; var navInfo = new EdmNavigationPropertyInfo() { Name = "Pen", ContainsTarget = false, Target = pencil, TargetMultiplicity = EdmMultiplicity.One }; PersonNavPen = person.AddUnidirectionalNavigation(navInfo); var navInfo2 = new EdmNavigationPropertyInfo() { Name = "Pen2", ContainsTarget = true, Target = pencil, TargetMultiplicity = EdmMultiplicity.One }; PersonNavPen2 = person.AddUnidirectionalNavigation(navInfo2); var container = new EdmEntityContainer("Default", "Con1"); var personSet = container.AddEntitySet("People", person); PencilSet = container.AddEntitySet("PencilSet", pencil); Boss = container.AddSingleton("Boss", person); Bajie = container.AddSingleton("Bajie", pencil); BajieUpper = container.AddSingleton("BAJIE", pencil); personSet.AddNavigationTarget(PersonNavPen, PencilSet); PeopleSet = personSet; var pencilSetUpper = container.AddEntitySet("PENCILSET", pencil); PencilSetUpper = pencilSetUpper; var pencilRef = new EdmEntityTypeReference(pencil, false); EdmFunction findPencil1 = new EdmFunction("TestNS", "FindPencil", pencilRef, true, null, false); findPencil1.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); model.AddElement(findPencil1); FindPencil1P = findPencil1; EdmFunction findPencil = new EdmFunction("TestNS", "FindPencil", pencilRef, true, null, false); findPencil.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); findPencil.AddParameter("pid", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(findPencil); FindPencil2P = findPencil; EdmFunction findPencils = new EdmFunction("TestNS", "FindPencils", new EdmCollectionTypeReference(new EdmCollectionType(pencilRef)), true, null, false); findPencils.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); model.AddElement(findPencils); FindPencils = findPencils; EdmFunction findPencilsCon = new EdmFunction("TestNS", "FindPencilsCon", new EdmCollectionTypeReference(new EdmCollectionType(pencilRef)), true, null, false); FindPencilsCon = findPencilsCon; findPencilsCon.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); model.AddElement(findPencilsCon); EdmFunction findPencilsConUpper = new EdmFunction("TestNS", "FindPencilsCON", new EdmCollectionTypeReference(new EdmCollectionType(pencilRef)), true, null, false); FindPencilsConUpper = findPencilsConUpper; findPencilsConUpper.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); model.AddElement(findPencilsConUpper); EdmFunction findPencilsConNT = new EdmFunction("TestNT", "FindPencilsCon", new EdmCollectionTypeReference(new EdmCollectionType(pencilRef)), true, null, false); FindPencilsConNT = findPencilsConNT; findPencilsConNT.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); model.AddElement(findPencilsConNT); ChangeZip = new EdmAction("TestNS", "ChangeZip", null, true, null); ChangeZip.AddParameter("address", new EdmComplexTypeReference(address, false)); ChangeZip.AddParameter("newZip", EdmCoreModel.Instance.GetString(false)); model.AddElement(ChangeZip); GetZip = new EdmFunction("TestNS", "GetZip", EdmCoreModel.Instance.GetString(false), true, null, true); GetZip.AddParameter("address", new EdmComplexTypeReference(address, false)); model.AddElement(GetZip); model.AddElement(person); model.AddElement(address); model.AddElement(pencil); model.AddElement(container); var feed = new EdmAction("TestNS", "Feed", null); Feed = feed; feed.AddParameter("pid", EdmCoreModel.Instance.GetInt32(false)); FeedImport = container.AddActionImport("Feed", feed); FeedConImport = container.AddActionImport("FeedCon", feed); FeedConUpperImport = container.AddActionImport("FeedCON", feed); var pet = new EdmEntityType("TestNS", "Pet"); PetType = pet; model.AddElement(pet); var key1 = pet.AddStructuralProperty("key1", EdmCoreModel.Instance.GetInt32(false)); var key2 = pet.AddStructuralProperty("key2", EdmCoreModel.Instance.GetString(false)); pet.AddKeys(key1, key2); var petSet = container.AddEntitySet("PetSet", pet); var petCon = new EdmEntityType("TestNS", "PetCon"); model.AddElement(petCon); var key1Con = pet.AddStructuralProperty("key", EdmCoreModel.Instance.GetInt32(false)); var key2Con = pet.AddStructuralProperty("KEY", EdmCoreModel.Instance.GetString(false)); petCon.AddKeys(key1Con, key2Con); var petSetCon = container.AddEntitySet("PetSetCon", petCon); EdmEnumType colorType = new EdmEnumType("TestNS", "Color"); Color = colorType; colorType.AddMember("Red", new EdmEnumMemberValue(1L)); colorType.AddMember("Blue", new EdmEnumMemberValue(2L)); model.AddElement(colorType); var moonType = new EdmEntityType("TestNS", "Moon"); MoonType = moonType; var color = moonType.AddStructuralProperty("color", new EdmEnumTypeReference(colorType, false)); moonType.AddKeys(color); model.AddElement(moonType); container.AddEntitySet("MoonSet", moonType); var moonType2 = new EdmEntityType("TestNS", "Moon2"); MoonType2 = moonType2; var color2 = moonType2.AddStructuralProperty("color", new EdmEnumTypeReference(colorType, false)); var id = moonType2.AddStructuralProperty("id", EdmCoreModel.Instance.GetInt32(false)); moonType2.AddKeys(color2, id); model.AddElement(moonType2); container.AddEntitySet("MoonSet2", moonType2); EdmFunction findPencilCon = new EdmFunction("TestNS", "FindPencilCon", pencilRef, true, null, false); FindPencilCon = findPencilCon; findPencilCon.AddParameter("qid", new EdmEntityTypeReference(PersonType, false)); findPencilCon.AddParameter("pid", EdmCoreModel.Instance.GetInt32(false)); findPencilCon.AddParameter("PID", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(findPencilCon); EdmFunction getColorCmyk = new EdmFunction("TestNS", "GetColorCmyk", EdmCoreModel.Instance.GetString(false)); getColorCmyk.AddParameter("co", new EdmEnumTypeReference(colorType, true)); GetColorCmyk = getColorCmyk; model.AddElement(getColorCmyk); GetColorCmykImport = container.AddFunctionImport("GetColorCmykImport", getColorCmyk); EdmFunction getMixedColor = new EdmFunction("TestNS", "GetMixedColor", EdmCoreModel.Instance.GetString(false)); getMixedColor.AddParameter("co", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(colorType, true)))); model.AddElement(getMixedColor); GetMixedColor = container.AddFunctionImport("GetMixedColorImport", getMixedColor); }
public void TopLevelPropertiesWithMetadataTest() { IEnumerable <PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreatePrimitiveValueTestDescriptors(this.Settings); testDescriptors = testDescriptors.Concat(PayloadReaderTestDescriptorGenerator.CreateComplexValueTestDescriptors(this.Settings, true)); testDescriptors = testDescriptors.Concat(PayloadReaderTestDescriptorGenerator.CreateCollectionTestDescriptors(this.Settings, true)); testDescriptors = testDescriptors.Select(collectionTestDescriptor => collectionTestDescriptor.InProperty("propertyName")); testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td)); // Limit to only top-level property payloads testDescriptors = testDescriptors.Where(td => td.PayloadElement is PropertyInstance); // Add a couple of invalid cases which use a standard model EdmModel model = new EdmModel(); model.ComplexType("UnusedComplexType"); EdmEntityType unusedEntityType = model.EntityType("UnusedEntityType"); unusedEntityType.AddKeys(unusedEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false)); unusedEntityType.Property("Name", EdmPrimitiveTypeKind.String, isNullable: false); EdmEntityType streamPropertyEntityType = model.EntityType("EntityTypeWithStreamProperty"); streamPropertyEntityType.AddKeys(streamPropertyEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false)); streamPropertyEntityType.AddStructuralProperty("Video", EdmPrimitiveTypeKind.Stream, isNullable: false); streamPropertyEntityType.Property("NonStreamProperty", EdmPrimitiveTypeKind.Boolean, isNullable: false); EdmEntityType navigationPropertyEntityType = model.EntityType("EntityTypeWithNavigationProperty"); navigationPropertyEntityType.AddKeys(navigationPropertyEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, isNullable: false)); navigationPropertyEntityType.NavigationProperty("Navigation", streamPropertyEntityType); model.Fixup(); EdmEntityContainer container = model.EntityContainer as EdmEntityContainer; EdmFunction nameFunction = new EdmFunction(container.Namespace, "NameFunctionImport", EdmCoreModel.Instance.GetInt32(false), false /*isBound*/, null, false /*isComposable*/); model.AddElement(nameFunction); container.AddFunctionImport("NameFunctionImport", nameFunction); model.Fixup(); var videoPropertyType = model.GetEntityType("TestModel.EntityTypeWithStreamProperty").Properties().Single(p => p.Name == "Video").Type; var explicitTestDescriptors = new[] { // Non existant type name new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue("TestModel.NonExistantType")), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "TestModel.NonExistantType"), // This test has different meaning in JSON-L (no expected type + non-existent typename) SkipTestConfiguration = (tc) => tc.Format == ODataFormat.Json, }, // Existing type name without namespace new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue("UnusedComplexType")), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_UnrecognizedTypeName", "UnusedComplexType"), // This test has different meaning in JSON-L (no expected type + non-existent typename) SkipTestConfiguration = (tc) => tc.Format == ODataFormat.Json, }, // Existing type of wrong kind new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue("TestModel.UnusedEntityType")), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_IncorrectValueTypeKind", "TestModel.UnusedEntityType", "Entity"), // This test has different meaning in JSON-L SkipTestConfiguration = (tc) => tc.Format == ODataFormat.Json, }, // A stream is not allowed in a property with a non-stream property kind. new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.Entity("TestModel.EntityTypeWithStreamProperty").StreamProperty("NonStreamProperty", "http://readlink", "http://editlink"), PayloadEdmModel = model, ExpectedResultCallback = tc => new PayloadReaderTestExpectedResult(this.Settings.ExpectedResultSettings) { ExpectedException = tc.Format == ODataFormat.Json ? ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_PropertyWithoutValueWithWrongType", "NonStreamProperty", "Edm.Boolean") : ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject") }, }, // Top-level property of stream type is not allowed new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty("Video", 42).ExpectedPropertyType(videoPropertyType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeStream"), }, // Top-level deferred navigation property is not allowed new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty("Video", 42).ExpectedPropertyType(streamPropertyEntityType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), }, // Top-level expanded navigation property is not allowed new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty("Video", 42).ExpectedPropertyType(streamPropertyEntityType), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ArgumentException("ODataMessageReader_ExpectedPropertyTypeEntityKind"), }, }; testDescriptors = testDescriptors.Concat(explicitTestDescriptors); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { var property = testDescriptor.PayloadElement as PropertyInstance; testDescriptor.RunTest(testConfiguration); }); }
public EdmModel BuildEdmModel(params IEdmModel[] refModels) { AddOperations(); Dictionary <Type, EntityTypeInfo> entityTypeInfos = BuildEntityTypes(refModels); foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { if (!typeInfo.IsRefModel) { typeInfo.BuildProperties(entityTypeInfos, _enumTypes, _complexTypes); } } foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { if (!typeInfo.IsRefModel) { foreach (FKeyInfo fkeyInfo in typeInfo.NavigationClrProperties) { fkeyInfo.BuildNavigationProperty(); } } } var edmModel = new EdmModel(false); edmModel.AddElements(_enumTypes.Values); foreach (KeyValuePair <Type, EdmEnumType> enumType in _enumTypes) { edmModel.SetClrType(enumType.Value, enumType.Key); } edmModel.AddElements(_complexTypes.Values); foreach (KeyValuePair <Type, EdmComplexType> complexType in _complexTypes) { edmModel.SetClrType(complexType.Value, complexType.Key); } var container = new EdmEntityContainer(_dataAdapter.DataContextType.Namespace, _dataAdapter.DataContextType.Name); edmModel.SetDataAdapter(container, _dataAdapter); var entitySets = new Dictionary <IEdmEntityType, EdmEntitySet>(entityTypeInfos.Count); foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { if (!typeInfo.IsRefModel) { edmModel.AddElement(typeInfo.EdmType); edmModel.SetClrType(typeInfo.EdmType, typeInfo.ClrType); } Db.OeEntitySetAdapter entitySetAdapter = _dataAdapter.EntitySetAdapters.Find(typeInfo.ClrType); if (entitySetAdapter != null) { EdmEntitySet entitySet = container.AddEntitySet(entitySetAdapter.EntitySetName, typeInfo.EdmType); edmModel.SetEntitySetAdapter(entitySet, entitySetAdapter); entitySets.Add(typeInfo.EdmType, entitySet); } } var manyToManyBuilder = new ManyToManyBuilder(edmModel, _metadataProvider, entityTypeInfos); foreach (EntityTypeInfo typeInfo in entityTypeInfos.Values) { if (!typeInfo.IsRefModel) { foreach (FKeyInfo fkeyInfo in typeInfo.NavigationClrProperties) { EdmEntitySet principal = entitySets[fkeyInfo.PrincipalInfo.EdmType]; EdmEntitySet dependent = entitySets[fkeyInfo.DependentInfo.EdmType]; if (fkeyInfo.DependentNavigationProperty == null) { principal.AddNavigationTarget(fkeyInfo.EdmNavigationProperty, dependent); } else { dependent.AddNavigationTarget(fkeyInfo.EdmNavigationProperty, principal); if (fkeyInfo.EdmNavigationProperty.Partner != null) { principal.AddNavigationTarget(fkeyInfo.EdmNavigationProperty.Partner, dependent); } } } manyToManyBuilder.Build(typeInfo); } } foreach (OeOperationConfiguration operationConfiguration in _operationConfigurations) { if (operationConfiguration.IsEdmFunction) { EdmFunction edmFunction = BuildFunction(operationConfiguration, entityTypeInfos); edmModel.AddElement(edmFunction); if (edmFunction.IsBound) { edmModel.SetMethodInfo(edmFunction, operationConfiguration.MethodInfo); } else { container.AddFunctionImport(operationConfiguration.ImportName, edmFunction, edmFunction.EntitySetPath); edmModel.SetIsDbFunction(edmFunction, operationConfiguration.IsDbFunction); } } else { EdmAction edmAction = BuildAction(operationConfiguration, entityTypeInfos); edmModel.AddElement(edmAction); container.AddActionImport(operationConfiguration.ImportName, edmAction); edmModel.SetIsDbFunction(edmAction, operationConfiguration.IsDbFunction); } } edmModel.AddElement(container); _dataAdapter.SetEdmModel(edmModel); foreach (IEdmModel refModel in refModels) { edmModel.AddReferencedModel(refModel); } return(edmModel); }