private static IEdmModel BuildModel() { EdmModel model = new EdmModel(); var movieType = new EdmEntityType("TestModel", "Movie"); EdmStructuralProperty idProperty = new EdmStructuralProperty(movieType, "Id", EdmCoreModel.Instance.GetInt32(false)); movieType.AddProperty(idProperty); movieType.AddKeys(idProperty); movieType.AddProperty(new EdmStructuralProperty(movieType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(movieType); var tvMovieType = new EdmEntityType("TestModel", "TVMovie", movieType); tvMovieType.AddProperty(new EdmStructuralProperty(tvMovieType, "Channel", EdmCoreModel.Instance.GetString(false))); model.AddElement(tvMovieType); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default"); defaultContainer.AddEntitySet("Movies", movieType); model.AddElement(defaultContainer); EdmAction simpleAction = new EdmAction("TestModel", "SimpleAction", null /*returnType*/, false /*isBound*/, null /*entitySetPath*/); model.AddElement(simpleAction); defaultContainer.AddActionImport(simpleAction); EdmAction checkoutAction1 = new EdmAction("TestModel", "Checkout", EdmCoreModel.Instance.GetInt32(false), false /*isBound*/, null /*entitySetPath*/); checkoutAction1.AddParameter("movie", movieType.ToTypeReference()); checkoutAction1.AddParameter("duration", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(checkoutAction1); EdmAction rateAction1 = new EdmAction("TestModel", "Rate", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); rateAction1.AddParameter("movie", movieType.ToTypeReference()); rateAction1.AddParameter("rating", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(rateAction1); EdmAction changeChannelAction1 = new EdmAction("TestModel", "ChangeChannel", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); changeChannelAction1.AddParameter("movie", tvMovieType.ToTypeReference()); changeChannelAction1.AddParameter("channel", EdmCoreModel.Instance.GetString(false)); model.AddElement(changeChannelAction1); EdmAction checkoutAction = new EdmAction("TestModel", "Checkout", EdmCoreModel.Instance.GetInt32(false) /*returnType*/, false /*isBound*/, null /*entitySetPath*/); checkoutAction.AddParameter("movie", movieType.ToTypeReference()); checkoutAction.AddParameter("duration", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(checkoutAction); var movieCollectionTypeReference = (new EdmCollectionType(movieType.ToTypeReference(nullable: false))).ToTypeReference(nullable:false); EdmAction checkoutMultiple1Action = new EdmAction("TestModel", "CheckoutMultiple", EdmCoreModel.Instance.GetInt32(false), false /*isBound*/, null /*entitySetPath*/); checkoutMultiple1Action.AddParameter("movies", movieCollectionTypeReference); checkoutMultiple1Action.AddParameter("duration", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(checkoutMultiple1Action); EdmAction rateMultiple1Action = new EdmAction("TestModel", "RateMultiple", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); rateMultiple1Action.AddParameter("movies", movieCollectionTypeReference); rateMultiple1Action.AddParameter("rating", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(rateMultiple1Action); EdmAction checkoutMultiple2Action = new EdmAction("TestModel", "CheckoutMultiple", EdmCoreModel.Instance.GetInt32(false) /*returnType*/, false /*isBound*/, null /*entitySetPath*/); checkoutMultiple2Action.AddParameter("movies", movieCollectionTypeReference); checkoutMultiple2Action.AddParameter("duration", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(checkoutMultiple2Action); EdmAction rateMultiple2Action = new EdmAction("TestModel", "RateMultiple", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); rateMultiple2Action.AddParameter("movies", movieCollectionTypeReference); rateMultiple2Action.AddParameter("rating", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(rateMultiple2Action); return model; }
/// <summary> /// Creates a test model shared among parameter reader/writer tests. /// </summary> /// <returns>Returns a model with function imports.</returns> public static IEdmModel BuildModelWithFunctionImport() { EdmCoreModel coreModel = EdmCoreModel.Instance; EdmModel model = new EdmModel(); const string defaultNamespaceName = "TestModel"; EdmEntityContainer container = new EdmEntityContainer(defaultNamespaceName, "TestContainer"); model.AddElement(container); EdmComplexType complexType = new EdmComplexType(defaultNamespaceName, "ComplexType"); complexType.AddProperty(new EdmStructuralProperty(complexType, "PrimitiveProperty", coreModel.GetString(false))); complexType.AddProperty(new EdmStructuralProperty(complexType, "ComplexProperty", complexType.ToTypeReference(false))); model.AddElement(complexType); EdmEnumType enumType = new EdmEnumType(defaultNamespaceName, "EnumType"); model.AddElement(enumType); EdmEntityType entityType = new EdmEntityType(defaultNamespaceName, "EntityType"); entityType.AddKeys(new IEdmStructuralProperty[] {new EdmStructuralProperty(entityType, "ID", coreModel.GetInt32(false))}); entityType.AddProperty(new EdmStructuralProperty(entityType, "ComplexProperty", complexType.ToTypeReference())); container.AddActionAndActionImport(model, "FunctionImport_Primitive", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("primitive", coreModel.GetString(false)); container.AddActionAndActionImport(model, "FunctionImport_NullablePrimitive", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("nullablePrimitive", coreModel.GetString(true)); EdmCollectionType stringCollectionType = new EdmCollectionType(coreModel.GetString(true)); container.AddActionAndActionImport(model, "FunctionImport_PrimitiveCollection", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("primitiveCollection", stringCollectionType.ToTypeReference(false)); container.AddActionAndActionImport(model, "FunctionImport_Complex", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("complex", complexType.ToTypeReference(true)); EdmCollectionType complexCollectionType = new EdmCollectionType(complexType.ToTypeReference()); container.AddActionAndActionImport(model, "FunctionImport_ComplexCollection", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("complexCollection", complexCollectionType.ToTypeReference()); container.AddActionAndActionImport(model, "FunctionImport_Entry", null /*returnType*/, null /*entitySet*/, true /*bindable*/).Action.AsEdmAction().AddParameter("entry", entityType.ToTypeReference()); EdmCollectionType entityCollectionType = new EdmCollectionType(entityType.ToTypeReference()); container.AddActionAndActionImport(model, "FunctionImport_Feed", null /*returnType*/, null /*entitySet*/, true /*bindable*/).Action.AsEdmAction().AddParameter("feed", entityCollectionType.ToTypeReference()); container.AddActionAndActionImport(model, "FunctionImport_Stream", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("stream", coreModel.GetStream(false)); container.AddActionAndActionImport(model, "FunctionImport_Enum", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("enum", enumType.ToTypeReference()); var functionImport_PrimitiveTwoParameters = container.AddActionAndActionImport(model, "FunctionImport_PrimitiveTwoParameters", null /*returnType*/, null /*entitySet*/, false /*bindable*/); functionImport_PrimitiveTwoParameters.Action.AsEdmAction().AddParameter("p1", coreModel.GetInt32(false)); functionImport_PrimitiveTwoParameters.Action.AsEdmAction().AddParameter("p2", coreModel.GetString(false)); container.AddActionAndActionImport(model, "FunctionImport_Int", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("p1", coreModel.GetInt32(false)); container.AddActionAndActionImport(model, "FunctionImport_Double", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("p1", coreModel.GetDouble(false)); EdmCollectionType int32CollectionType = new EdmCollectionType(coreModel.GetInt32(false)); container.AddActionAndActionImport(model, "FunctionImport_NonNullablePrimitiveCollection", null /*returnType*/, null /*entitySet*/, false /*bindable*/).Action.AsEdmAction().AddParameter("p1", int32CollectionType.ToTypeReference(false)); EdmComplexType complexType2 = new EdmComplexType(defaultNamespaceName, "ComplexTypeWithNullableProperties"); complexType2.AddProperty(new EdmStructuralProperty(complexType2, "StringProperty", coreModel.GetString(true))); complexType2.AddProperty(new EdmStructuralProperty(complexType2, "IntegerProperty", coreModel.GetInt32(true))); model.AddElement(complexType2); var functionImport_MultipleNullableParameters = container.AddActionAndActionImport(model, "FunctionImport_MultipleNullableParameters", null /*returnType*/, null /*entitySet*/, false /*bindable*/); var function_MultipleNullableParameters = functionImport_MultipleNullableParameters.Action.AsEdmAction(); function_MultipleNullableParameters.AddParameter("p1", coreModel.GetBinary(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p2", coreModel.GetBoolean(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p3", coreModel.GetByte(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p5", coreModel.GetDateTimeOffset(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p6", coreModel.GetDecimal(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p7", coreModel.GetDouble(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p8", coreModel.GetGuid(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p9", coreModel.GetInt16(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p10", coreModel.GetInt32(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p11", coreModel.GetInt64(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p12", coreModel.GetSByte(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p13", coreModel.GetSingle(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p14", coreModel.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p15", coreModel.GetString(true /*isNullable*/)); function_MultipleNullableParameters.AddParameter("p16", complexType2.ToTypeReference(true /*isNullable*/)); return model; }