public void TestElementInterfaceCriticalEntityTypeBaseType() { var expectedErrors = new EdmLibTestErrors() { { null, null, EdmErrorCode.InterfaceCriticalNavigationPartnerInvalid } }; var baseEntity = new EdmEntityType("DefaultNamespace", "baseEntity"); var entity2 = new EdmEntityType("DefaultNamespace", "Entity2"); var navProperty = new StubEdmNavigationProperty("Nav") { DeclaringType = baseEntity, Type = new EdmEntityTypeReference(entity2, false) }; navProperty.Partner = navProperty; baseEntity.AddProperty(navProperty); this.ValidateElement(baseEntity, expectedErrors); var entity = new EdmEntityType("DefaultNamespace", "Entity1", baseEntity); expectedErrors = new EdmLibTestErrors(); this.ValidateElement(entity, expectedErrors); }
private EdmModel CreateModel() { var model = new EdmModel(); var customer = new EdmEntityType("NS1", "Customer"); var customerId = new EdmStructuralProperty(customer, "CustomerID", EdmCoreModel.Instance.GetString(false)); customer.AddProperty(customerId); customer.AddKeys(customerId); model.AddElement(customer); var title = new EdmTerm("NS1", "Title", EdmCoreModel.Instance.GetString(true)); model.AddElement(title); var person = new EdmEntityType("NS1", "Person"); var Id = person.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); person.AddKeys(Id); model.AddElement(person); var container = new EdmEntityContainer("NS1", "Container"); container.AddElement(new EdmEntitySet(container, "Customers", customer)); model.AddElement(container); IEnumerable <EdmError> errors; Assert.IsTrue(model.Validate(out errors), "validate"); return(model); }
/// <summary> /// Adds a navigation property to the <paramref name="entityType"/>. This method creates an association type /// in order to add the navigation property. /// Returns the modified entity type for composability. /// </summary> /// <param name="entityType">The <see cref="EntityType"/> to add the navigation property to.</param> /// <param name="propertyName">The name of the property to add.</param> /// <param name="otherEndType">The type of the other end of the navigation property.</param> /// <returns>The <paramref name="entityType"/> instance after adding the navigation property to it.</returns> public static EdmEntityType NavigationProperty(this EdmEntityType entityType, string propertyName, EdmEntityType otherEndType) { ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType"); ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName"); // Create a navigation property representing one side of an association. // The partner representing the other side exists only inside this property and is not added to the target entity type, // so it should not cause any name collisions. EdmNavigationProperty navProperty = EdmNavigationProperty.CreateNavigationPropertyWithPartner( propertyName, otherEndType.ToTypeReference(), /*dependentProperties*/ null, /*principalProperties*/ null, /*containsTarget*/ false, EdmOnDeleteAction.None, "Partner", entityType.ToTypeReference(true), /*partnerDependentProperties*/ null, /*partnerPrincipalProperties*/ null, /*partnerContainsTarget*/ false, EdmOnDeleteAction.None); entityType.AddProperty(navProperty); return(entityType); }
public void EdmSingletonAnnotationTests() { EdmModel model = new EdmModel(); EdmStructuralProperty customerProperty = new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(false)); customerType.AddProperty(customerProperty); model.AddElement(this.customerType); EdmSingleton vipCustomer = new EdmSingleton(this.entityContainer, "VIP", this.customerType); EdmTerm term = new EdmTerm(myNamespace, "SingletonAnnotation", EdmPrimitiveTypeKind.String); var annotation = new EdmVocabularyAnnotation(vipCustomer, term, new EdmStringConstant("Singleton Annotation")); model.AddVocabularyAnnotation(annotation); var singletonAnnotation = vipCustomer.VocabularyAnnotations(model).Single(); Assert.Equal(vipCustomer, singletonAnnotation.Target); Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name); singletonAnnotation = model.FindDeclaredVocabularyAnnotations(vipCustomer).Single(); Assert.Equal(vipCustomer, singletonAnnotation.Target); Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name); EdmTerm propertyTerm = new EdmTerm(myNamespace, "SingletonPropertyAnnotation", EdmPrimitiveTypeKind.String); var propertyAnnotation = new EdmVocabularyAnnotation(customerProperty, propertyTerm, new EdmStringConstant("Singleton Property Annotation")); model.AddVocabularyAnnotation(propertyAnnotation); var singletonPropertyAnnotation = customerProperty.VocabularyAnnotations(model).Single(); Assert.Equal(customerProperty, singletonPropertyAnnotation.Target); Assert.Equal("SingletonPropertyAnnotation", singletonPropertyAnnotation.Term.Name); }
static DeltaLinkWriterIntegrationTests() { Model = new EdmModel(); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); Model.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many }); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer"); Model.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet); EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(EntitySet); }
public void TestElementInterfaceCriticalPropertyValueMustNotBeNull() { var expectedErrors = new EdmLibTestErrors() { { null, null, EdmErrorCode.InterfaceCriticalPropertyValueMustNotBeNull } }; var baseEntity = new EdmEntityType("DefaultNamespace", "BaseEntity"); var navProperty = new StubEdmNavigationProperty("Nav") { DeclaringType = baseEntity, Partner = new StubEdmNavigationProperty("Partner") { DeclaringType = baseEntity, Type = new EdmEntityTypeReference(baseEntity, false) } }; baseEntity.AddProperty(navProperty); this.ValidateElement(navProperty, expectedErrors); this.ValidateElement(baseEntity, expectedErrors); expectedErrors = new EdmLibTestErrors(); var entity = new EdmEntityType("DefaultNamespace", "Entity", baseEntity); this.ValidateElement(entity, expectedErrors); }
public void ValidateKindsOfNone() { StubEdmModel model = new StubEdmModel(); EdmEntityContainer container = new EdmEntityContainer("namespace", "container"); model.Add(container); model.Add(new NoneKinds1("namespace", "badThing", container)); var type = new EdmEntityType("namespace", "type"); type.AddProperty(new NoneKinds2("namespace", "otherBadThing", EdmCoreModel.Instance.GetInt32(false), type)); model.Add(type); var expectedErrors = new EdmLibTestErrors() { { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds1)", EdmErrorCode.TypeMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds1)", EdmErrorCode.EntityContainerElementMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds1)", EdmErrorCode.SchemaElementMustNotHaveKindOfNone }, { "(namespace.type)", EdmErrorCode.KeyMissingOnEntityType }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.PrimitiveTypeMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.SchemaElementMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.TypeMustNotHaveKindOfNone }, { "(EdmLibTests.FunctionalTests.CodeCoverageBoostingTests+NoneKinds2)", EdmErrorCode.PropertyMustNotHaveKindOfNone }, }; this.VerifySemanticValidation(model, expectedErrors); }
public void WriteNullEntryWithOperation() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("entry", new EdmEntityTypeReference(entityType, true)); Action <ODataJsonLightOutputContext> test = outputContext => { var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceWriter("entry"); entryWriter.WriteStart((ODataResource)null); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"entry\":null}", writingResponse: false); }
static ODataEntityReferenceLinkTests() { 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, "Customers", EntityType); defaultContainer.AddElement(EntitySet); EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel); MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }; }
public void TestNavigationBothNotPrincipalRoundTrip() { var model = new EdmModel(); var person = new EdmEntityType("NS", "Person"); var personId = person.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); person.AddKeys(personId); model.AddElement(person); var pet = new EdmEntityType("NS", "Pet"); var petId = new EdmStructuralProperty(pet, "Id", EdmCoreModel.Instance.GetInt32(false)); pet.AddProperty(petId); pet.AddKeys(petId); model.AddElement(pet); var personToPet = EdmNavigationProperty.CreateNavigationPropertyWithPartner( new EdmNavigationPropertyInfo() { Name = "ToPet", Target = pet, TargetMultiplicity = EdmMultiplicity.One, ContainsTarget = true }, new EdmNavigationPropertyInfo() { Name = "ToPerson", Target = person, TargetMultiplicity = EdmMultiplicity.One }); pet.AddProperty(personToPet.Partner); person.AddProperty(personToPet); Assert.IsFalse(personToPet.IsPrincipal(), "Invalid navigation principal value."); Assert.IsFalse(personToPet.Partner.IsPrincipal(), "Invalid navigation principal value."); var csdls = this.GetSerializerResult(model); var roundTripModel = this.GetParserResult(csdls); var roundTripPerson = roundTripModel.FindEntityType("NS.Person"); Assert.IsNotNull(roundTripPerson, "Invalid entity type."); var roundTripNavs = roundTripPerson.NavigationProperties(); Assert.AreEqual(1, roundTripNavs.Count(), "Invalid navigation property count."); var roundTripNav = roundTripNavs.First(); Assert.IsFalse(roundTripNav.IsPrincipal(), "Invalid navigation principal value."); Assert.IsFalse(roundTripNav.Partner.IsPrincipal(), "Invalid navigation principal value."); }
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 HandCraftEdmType() { foreach (var mimeType in this.testMimeTypes) { EdmModel edmModel = new EdmModel(); EdmEntityType edmEntityType = new EdmEntityType(NameSpace, "Person"); edmModel.AddElement(edmEntityType); var keyProperty = new EdmStructuralProperty(edmEntityType, "PersonId", EdmCoreModel.Instance.GetInt32(false)); edmEntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); edmEntityType.AddProperty(keyProperty); var property = new EdmStructuralProperty(edmEntityType, "Name", EdmCoreModel.Instance.GetString(true)); edmEntityType.AddKeys(new IEdmStructuralProperty[] { property }); edmEntityType.AddProperty(property); var defaultContainer = new EdmEntityContainer(NameSpace, "DefaultContainer"); edmModel.AddElement(defaultContainer); EdmEntitySet entitySet = new EdmEntitySet(defaultContainer, "Person", edmEntityType); defaultContainer.AddElement(entitySet); var settings = new ODataMessageWriterSettings(); settings.ODataUri = new ODataUri() { ServiceRoot = this.ServiceUri }; var responseMessageWithoutModel = new StreamResponseMessage(new MemoryStream()); responseMessageWithoutModel.SetHeader("Content-Type", mimeType); using (var messageWriter = new ODataMessageWriter(responseMessageWithoutModel, settings)) { var odataWriter = messageWriter.CreateODataResourceWriter(entitySet, edmEntityType); var entry = this.CreatePersonEntryWithoutSerializationInfo(); odataWriter.WriteStart(entry); odataWriter.WriteEnd(); if (!mimeType.Contains(MimeTypes.ODataParameterNoMetadata)) { Assert.IsTrue( WritePayloadHelper.ReadStreamContent(responseMessageWithoutModel.GetStream()) .Contains("Person/$entity")); } } } }
public void WriteFeedWithMultipleEntries() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmEntityType derivedType = new EdmEntityType("NS", "DerivedType", entityType); derivedType.AddProperty(new EdmStructuralProperty(derivedType, "Name", EdmCoreModel.Instance.GetString(false))); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("feed", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)))); Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataResource(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 } }; var entry2 = new ODataResource() { TypeName = "NS.DerivedType", }; entry2.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, new ODataProperty() { Name = "Name", Value = "TestName" } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceSetWriter("feed"); entryWriter.WriteStart(new ODataResourceSet()); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); entryWriter.WriteStart(entry2); entryWriter.WriteEnd(); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"feed\":[{\"ID\":1},{\"@odata.type\":\"#NS.DerivedType\",\"ID\":1,\"Name\":\"TestName\"}]}", writingResponse: false); }
private void BuildProperty(Dictionary <Type, EntityTypeInfo> entityTypes, Dictionary <Type, EdmEnumType> enumTypes, Dictionary <Type, EdmComplexType> complexTypes, PropertyInfo clrProperty) { bool isNullable = !_metadataProvider.IsRequired(clrProperty); IEdmTypeReference typeRef = PrimitiveTypeHelper.GetPrimitiveTypeRef(clrProperty, isNullable); if (typeRef == null) { EdmEnumType edmEnumType; Type underlyingType = null; if (clrProperty.PropertyType.IsEnum || (underlyingType = Nullable.GetUnderlyingType(clrProperty.PropertyType)) != null && underlyingType.IsEnum) { Type clrPropertyType = underlyingType ?? clrProperty.PropertyType; if (!enumTypes.TryGetValue(clrPropertyType, out edmEnumType)) { edmEnumType = CreateEdmEnumType(clrPropertyType); enumTypes.Add(clrPropertyType, edmEnumType); } typeRef = new EdmEnumTypeReference(edmEnumType, underlyingType != null); } else { EdmComplexType edmComplexType; if (complexTypes.TryGetValue(clrProperty.PropertyType, out edmComplexType)) { typeRef = new EdmComplexTypeReference(edmComplexType, clrProperty.PropertyType.IsClass); } else { FKeyInfo fkeyInfo = FKeyInfo.Create(_metadataProvider, entityTypes, this, clrProperty); if (fkeyInfo != null) { _navigationClrProperties.Add(fkeyInfo); } return; } } } else { if (clrProperty.PropertyType == typeof(DateTime?) && enumTypes.ContainsKey(typeof(DateTime?))) //zzz { var edmType = enumTypes[typeof(DateTime?)]; typeRef = new EdmEnumTypeReference(edmType, true); } } var edmProperty = new EdmStructuralProperty(_edmType, clrProperty.Name, typeRef); _edmType.AddProperty(edmProperty); if (_metadataProvider.IsKey(clrProperty)) { _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(clrProperty, edmProperty)); } }
public static IEdmModel BuildEdmModel() { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(DefaultNamespace, "DefaultContainer"); model.AddElement(defaultContainer); // Create an Enum type. var colorType = new EdmEnumType(DefaultNamespace, "Color", isFlags: false); colorType.AddMember("Red", new EdmIntegerConstant(1)); colorType.AddMember("Green", new EdmIntegerConstant(2)); colorType.AddMember("Blue", new EdmIntegerConstant(4)); model.AddElement(colorType); // Create another Enum type with isFlage=true. var accessLevelType = new EdmEnumType(DefaultNamespace, "AccessLevel", isFlags: true); accessLevelType.AddMember("None", new EdmIntegerConstant(0)); accessLevelType.AddMember("Read", new EdmIntegerConstant(1)); accessLevelType.AddMember("Write", new EdmIntegerConstant(2)); accessLevelType.AddMember("Execute", new EdmIntegerConstant(4)); accessLevelType.AddMember("ReadWrite", new EdmIntegerConstant(3)); model.AddElement(accessLevelType); // Create an Entity type which contains Enum properties. var productType = new EdmEntityType(DefaultNamespace, "Product"); var ProductIdProperty = new EdmStructuralProperty(productType, "ProductId", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(ProductIdProperty); productType.AddKeys(ProductIdProperty); productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(false))); productType.AddProperty(new EdmStructuralProperty(productType, "UserAccess", new EdmEnumTypeReference(accessLevelType, true))); productType.AddProperty(new EdmStructuralProperty(productType, "SkinColor", new EdmEnumTypeReference(colorType, true))); model.AddElement(productType); var productSet = new EdmEntitySet(defaultContainer, "Products", productType); defaultContainer.AddElement(productSet); return(model); }
public void TestManytoManyRelationshipWithOneNavigiationPropertyInOneOfThem() { var expectedErrors = new EdmLibTestErrors() { { null, null, EdmErrorCode.InterfaceCriticalNavigationPartnerInvalid } }; var entity1 = new EdmEntityType("DefaultNamespace", "Entity1"); var entity2 = new EdmEntityType("DefaultNamespace", "Entity2"); var navProperty1 = new StubEdmNavigationProperty("Nav1") { DeclaringType = entity1, Type = new EdmEntityTypeReference(entity2, false), }; var navProperty2 = new StubEdmNavigationProperty("Nav2") { DeclaringType = entity1, Type = new EdmEntityTypeReference(entity2, false), }; var navProperty3 = new StubEdmNavigationProperty("Nav3") { DeclaringType = entity2, Type = new EdmEntityTypeReference(entity1, false), }; navProperty1.Partner = navProperty3; navProperty2.Partner = navProperty3; navProperty3.Partner = navProperty1; entity1.AddProperty(navProperty1); entity1.AddProperty(navProperty2); entity2.AddProperty(navProperty3); var model = new EdmModel(); model.AddElement(entity1); model.AddElement(entity2); this.ValidateUsingEdmValidator(model, expectedErrors); }
private static IEdmModel CreateODataServiceModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var personType = new EdmEntityType(ns, "Person"); var personIdProperty = new EdmStructuralProperty(personType, "PersonId", EdmCoreModel.Instance.GetInt64(false)); personType.AddProperty(personIdProperty); personType.AddKeys(new IEdmStructuralProperty[] { 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, "UserName", EdmCoreModel.Instance.GetString(true))); personType.AddProperty(new EdmStructuralProperty(personType, "DbLocation", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPolygon, true))); personType.AddProperty(new EdmStructuralProperty(personType, "DbLineString", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyMultiPoint, true))); model.AddElement(personType); var personSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(personSet); model.SetAnnotationValue(personType, new ClrTypeAnnotation(typeof(Person))); return(model); }
public void TestElementInterfaceCriticalEnumPropertyValueOutOfRange() { var expectedErrors = new EdmLibTestErrors() { { null, null, EdmErrorCode.InterfaceCriticalEnumPropertyValueOutOfRange } }; var entity = new EdmEntityType("DefaultNamespace", "Entity"); var navProperty = EdmNavigationProperty.CreateNavigationPropertyWithPartner( "Navigation", new EdmEntityTypeReference(entity, false /*isNullable*/), null /*dependentProperties*/, null /*principalProperties*/, false /*containsTarget*/, (EdmOnDeleteAction)123, "", new EdmEntityTypeReference(entity, false /*isNullable*/), null /*partnerDependentProperties*/, null /*partnerPrincipalProperties*/, false /*partnerContainsTarget*/, EdmOnDeleteAction.Cascade); entity.AddProperty(navProperty); this.ValidateElement(navProperty, expectedErrors); }
public static IEdmModel AllInterfaceCriticalModel() { var model = new EdmModel(); var valueTerm = new EdmTerm("DefaultNamespace", "Note", EdmCoreModel.Instance.GetString(true)); model.AddElement(valueTerm); var badString = new CustomStringConstant("foo", EdmExpressionKind.None, EdmValueKind.Integer); var valueAnnotation = new EdmAnnotation( valueTerm, valueTerm, badString); model.AddVocabularyAnnotation(valueAnnotation); var mutableValueAnnotationueAnnotation = new MutableValueAnnotation() { Target = valueTerm }; model.AddVocabularyAnnotation(mutableValueAnnotationueAnnotation); var customEntity = new CustomEntityType(new List <IEdmProperty>() { null }); model.AddElement(customEntity); var entity = new EdmEntityType("DefaultNamespace", "bar"); var entity2 = new EdmEntityType("DefaultNamespace", "bar2"); var navProperty = new StubEdmNavigationProperty("Nav") { DeclaringType = entity, Type = new EdmEntityTypeReference(entity2, false) }; navProperty.Partner = navProperty; entity.AddProperty(navProperty); model.AddElement(entity); model.AddElement(entity2); 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 void ValidateSerializationBlockingErrors() { EdmModel model = new EdmModel(); EdmComplexType complexWithBadProperty = new EdmComplexType("Foo", "Bar"); complexWithBadProperty.AddProperty(new EdmStructuralProperty(complexWithBadProperty, "baz", new EdmComplexTypeReference(new EdmComplexType("", ""), false))); model.AddElement(complexWithBadProperty); EdmEntityType baseType = new EdmEntityType("Foo", ""); IEdmStructuralProperty keyProp = new EdmStructuralProperty(baseType, "Id", EdmCoreModel.Instance.GetInt32(false)); baseType.AddProperty(keyProp); baseType.AddKeys(keyProp); EdmEntityType derivedType = new EdmEntityType("Foo", "Quip", baseType); model.AddElement(baseType); model.AddElement(derivedType); EdmNavigationProperty navProp = derivedType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "navProp", Target = derivedType, TargetMultiplicity = EdmMultiplicity.One }); EdmEntityContainer container = new EdmEntityContainer("Foo", "Container"); model.AddElement(container); container.AddElement(new EdmEntitySet(container, "badNameSet", baseType)); StringBuilder sb = new StringBuilder(); IEnumerable <EdmError> errors; bool written = model.TryWriteSchema(XmlWriter.Create(sb), out errors); var expectedErrors = new EdmLibTestErrors() { { "([. Nullable=False])", EdmErrorCode.ReferencedTypeMustHaveValidName }, { "(Foo.Quip)", EdmErrorCode.ReferencedTypeMustHaveValidName }, { "(Microsoft.OData.Edm.EdmEntitySet)", EdmErrorCode.ReferencedTypeMustHaveValidName }, }; this.CompareErrors(errors, expectedErrors); }
public void ParseComputeAsExpandQueryOption() { // Create model EdmModel model = new EdmModel(); EdmEntityType elementType = model.AddEntityType("DevHarness", "Entity"); EdmEntityType targetType = model.AddEntityType("DevHarness", "Navigation"); EdmTypeReference typeReference = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false); targetType.AddProperty(new EdmStructuralProperty(targetType, "Prop1", typeReference)); EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo(); propertyInfo.Name = "Nav1"; propertyInfo.Target = targetType; propertyInfo.TargetMultiplicity = EdmMultiplicity.One; EdmProperty navigation = EdmNavigationProperty.CreateNavigationProperty(elementType, propertyInfo); elementType.AddProperty(navigation); EdmEntityContainer container = model.AddEntityContainer("Default", "Container"); container.AddEntitySet("Entities", elementType); // Define queries and new up parser. Uri root = new Uri("http://host"); Uri url = new Uri("http://host/Entities?$expand=Nav1($compute=cast(Prop1, 'Edm.String') as NavProperty1AsString)"); ODataUriParser parser = new ODataUriParser(model, root, url); // parse and validate SelectExpandClause clause = parser.ParseSelectAndExpand(); List <SelectItem> items = clause.SelectedItems.ToList(); items.Count.Should().Be(1); ExpandedNavigationSelectItem expanded = items[0] as ExpandedNavigationSelectItem; List <ComputeExpression> computes = expanded.ComputeOption.ComputedItems.ToList(); computes.Count.Should().Be(1); computes[0].Alias.ShouldBeEquivalentTo("NavProperty1AsString"); computes[0].Expression.ShouldBeSingleValueFunctionCallQueryNode(); computes[0].Expression.TypeReference.ShouldBeEquivalentTo(typeReference); }
public static IEdmModel BuildEdmModel() { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(DefaultNamespace, "DefaultContainer"); model.AddElement(defaultContainer); // Define EdmType Custumer var custumerType = new EdmEntityType(DefaultNamespace, "Customer"); var customerIdProperty = new EdmStructuralProperty(custumerType, "Id", EdmCoreModel.Instance.GetInt32(false)); custumerType.AddProperty(customerIdProperty); custumerType.AddKeys(new IEdmStructuralProperty[] { customerIdProperty }); model.AddElement(custumerType); // Define EdmType Product var productType = new EdmEntityType(DefaultNamespace, "Product"); var productIdProperty = new EdmStructuralProperty(productType, "ProductID", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(productIdProperty); productType.AddKeys(productIdProperty); model.AddElement(productType); // Add the Edm Entity Set Customers to container var customerSet = new EdmEntitySet(defaultContainer, "Customers", custumerType); defaultContainer.AddElement(customerSet); // Add the Containment Navigation Property "ShoppingCart" to Product var shoppingCartNavigation = custumerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ShoppingCart", Target = productType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); return(model); }
public void ParseComputeAsQueryOption() { // Create model EdmModel model = new EdmModel(); EdmEntityType elementType = model.AddEntityType("DevHarness", "Entity"); EdmTypeReference typeReference = new EdmStringTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), false); elementType.AddProperty(new EdmStructuralProperty(elementType, "Prop1", typeReference)); EdmEntityContainer container = model.AddEntityContainer("Default", "Container"); container.AddEntitySet("Entities", elementType); // Define queries and new up parser. Uri root = new Uri("http://host"); Uri url = new Uri("http://host/Entities?$compute=cast(Prop1, 'Edm.String') as Property1AsString, tolower(Prop1) as Property1Lower"); ODataUriParser parser = new ODataUriParser(model, root, url); // parse and validate ComputeClause clause = parser.ParseCompute(); List <ComputeExpression> items = clause.ComputedItems.ToList(); items.Count().Should().Be(2); items[0].Alias.ShouldBeEquivalentTo("Property1AsString"); items[0].Expression.ShouldBeSingleValueFunctionCallQueryNode(); items[0].Expression.TypeReference.ShouldBeEquivalentTo(typeReference); items[1].Alias.ShouldBeEquivalentTo("Property1Lower"); items[1].Expression.ShouldBeSingleValueFunctionCallQueryNode(); items[1].Expression.TypeReference.FullName().ShouldBeEquivalentTo("Edm.String"); items[1].Expression.TypeReference.IsNullable.ShouldBeEquivalentTo(true); // tolower is built in function that allows nulls. ComputeExpression copy = new ComputeExpression(items[0].Expression, items[0].Alias, null); copy.Expression.Should().NotBeNull(); copy.TypeReference.Should().BeNull(); ComputeClause varied = new ComputeClause(null); }
static InstanceAnnotationsReaderIntegrationTests() { EdmModel modelTmp = new EdmModel(); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); modelTmp.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne }); var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many }); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub"); modelTmp.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet); EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(EntitySet); Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType); Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet); Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet); defaultContainer.AddElement(Singleton); ComplexType = new EdmComplexType("TestNamespace", "TestComplexType"); ComplexType.AddProperty(new EdmStructuralProperty(ComplexType, "StringProperty", EdmCoreModel.Instance.GetString(false))); modelTmp.AddElement(ComplexType); Model = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", modelTmp); }
public void WriteOpenEntry() { EdmEntityType entityType = new EdmEntityType("NS", "Entity", null, false, true); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("entry", new EdmEntityTypeReference(entityType, false)); Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataResource(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 }, new ODataProperty() { Name = "DynamicProperty", Value = "DynamicValue" } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateResourceWriter("entry"); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"entry\":{\"ID\":1,\"DynamicProperty\":\"DynamicValue\"}}", writingResponse: false); }
public void WriteFeedWithOperation() { EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmStructuralProperty keyProp = new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)); entityType.AddProperty(keyProp); entityType.AddKeys(keyProp); EdmOperation operation = new EdmFunction("NS", "Foo", EdmCoreModel.Instance.GetInt16(true)); operation.AddParameter("feed", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(entityType, false)))); Action <ODataJsonLightOutputContext> test = outputContext => { var entry = new ODataEntry(); entry.Properties = new List <ODataProperty>() { new ODataProperty() { Name = "ID", Value = 1 } }; var parameterWriter = new ODataJsonLightParameterWriter(outputContext, operation: null); parameterWriter.WriteStart(); var entryWriter = parameterWriter.CreateFeedWriter("feed"); entryWriter.WriteStart(new ODataFeed()); entryWriter.WriteStart(entry); entryWriter.WriteEnd(); entryWriter.WriteEnd(); parameterWriter.WriteEnd(); parameterWriter.Flush(); }; WriteAndValidate(test, "{\"feed\":[{\"ID\":1}]}", writingResponse: false); }
public static TestModel Initialize() { EdmModel model = new EdmModel(); var result = new TestModel(model); var productType = new EdmEntityType("TestModel", "Product"); result.ProductType = productType; 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); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default"); result.Container = defaultContainer; result.ProductsSet = defaultContainer.AddEntitySet("Products", productType); model.AddElement(defaultContainer); var derivedProductType = new EdmEntityType("TestModel", "DerivedProduct", productType); result.DerivedProductType = derivedProductType; EdmEntityType multipleKeyType = new EdmEntityType("TestModel", "MultipleKeyType"); result.MultipleKeyType = multipleKeyType; EdmStructuralProperty keyAProperty = new EdmStructuralProperty(multipleKeyType, "KeyA", EdmCoreModel.Instance.GetString(false)); EdmStructuralProperty keyBProperty = new EdmStructuralProperty(multipleKeyType, "KeyB", EdmCoreModel.Instance.GetInt32(false)); multipleKeyType.AddProperty(keyAProperty); multipleKeyType.AddProperty(keyBProperty); multipleKeyType.AddKeys(keyAProperty, keyBProperty); model.AddElement(multipleKeyType); result.MultipleKeysSet = defaultContainer.AddEntitySet("MultipleKeySet", multipleKeyType); EdmEntityType productTypeWithNavProps = new EdmEntityType("TestModel", "ProductWithNavProps", productType); result.ProductWithNavPropsType = productTypeWithNavProps; productTypeWithNavProps.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "RelatedProducts", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }); productTypeWithNavProps.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "RelatedDerivedProduct", Target = derivedProductType, TargetMultiplicity = EdmMultiplicity.One }); model.AddElement(productTypeWithNavProps); EdmAction action = new EdmAction("TestModel", "SimpleAction", null /*returnType*/, true /*isBound*/, null /*entitySetPath*/); model.AddElement(action); defaultContainer.AddActionImport("SimpleAction", action); EdmAction action1 = new EdmAction("TestModel", "SimpleFunctionWithOverload", EdmCoreModel.Instance.GetInt32(false), true /*isbound*/, null); action1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); defaultContainer.AddActionImport("SimpleFunctionWithOverload", action1); EdmAction action2 = new EdmAction("TestModel", "SimpleFunctionWithOverload", EdmCoreModel.Instance.GetInt32(false), true /*isbound*/, null); action2.AddParameter("p1", EdmCoreModel.Instance.GetString(false)); defaultContainer.AddActionImport("SimpleFunctionWithOverload", action2); result.OneProductValue = BuildDefaultProductValue(productType); result.OneDerivedProductValue = BuildDefaultProductValue(derivedProductType); result.OneMultipleKeyValue = BuildDefaultMultipleKeyValue(model); result.OneProductWithNavPropsValue = BuildDefaultProductValue(productTypeWithNavProps); return(result); }
/// <summary> /// Creates a test model shared among parameter reader/writer tests. /// </summary> /// <returns>Returns a model with operation imports.</returns> public static IEdmModel BuildModelWithFunctionImport() { EdmCoreModel coreModel = EdmCoreModel.Instance; EdmModel model = new EdmModel(); const string defaultNamespaceName = DefaultNamespaceName; 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.AddFunctionAndFunctionImport(model, "FunctionImport_Primitive", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("primitive", coreModel.GetString(false)); container.AddFunctionAndFunctionImport(model, "FunctionImport_NullablePrimitive", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("nullablePrimitive", coreModel.GetString(true)); EdmCollectionType stringCollectionType = new EdmCollectionType(coreModel.GetString(true)); container.AddFunctionAndFunctionImport(model, "FunctionImport_PrimitiveCollection", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("primitiveCollection", stringCollectionType.ToTypeReference(false)); container.AddFunctionAndFunctionImport(model, "FunctionImport_Complex", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("complex", complexType.ToTypeReference(true)); EdmCollectionType complexCollectionType = new EdmCollectionType(complexType.ToTypeReference()); container.AddFunctionAndFunctionImport(model, "FunctionImport_ComplexCollection", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("complexCollection", complexCollectionType.ToTypeReference()); container.AddFunctionAndFunctionImport(model, "FunctionImport_Entry", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, true /*bindable*/).Function.AsEdmFunction().AddParameter("entry", entityType.ToTypeReference()); EdmCollectionType entityCollectionType = new EdmCollectionType(entityType.ToTypeReference()); container.AddFunctionAndFunctionImport(model, "FunctionImport_Feed", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, true /*bindable*/).Function.AsEdmFunction().AddParameter("feed", entityCollectionType.ToTypeReference()); container.AddFunctionAndFunctionImport(model, "FunctionImport_Stream", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("stream", coreModel.GetStream(false)); container.AddFunctionAndFunctionImport(model, "FunctionImport_Enum", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("enum", enumType.ToTypeReference()); var functionImport_PrimitiveTwoParameters = container.AddFunctionAndFunctionImport(model, "FunctionImport_PrimitiveTwoParameters", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/); var function_PrimitiveTwoParameters = functionImport_PrimitiveTwoParameters.Function.AsEdmFunction(); function_PrimitiveTwoParameters.AddParameter("p1", coreModel.GetInt32(false)); function_PrimitiveTwoParameters.AddParameter("p2", coreModel.GetString(false)); container.AddFunctionAndFunctionImport(model, "FunctionImport_Int", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().AddParameter("p1", coreModel.GetInt32(false)); container.AddFunctionAndFunctionImport(model, "FunctionImport_Double", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/).Function.AsEdmFunction().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); EdmEnumType enumType1 = new EdmEnumType(defaultNamespaceName, "enumType1"); enumType1.AddMember(new EdmEnumMember(enumType1, "enumType1_value1", new EdmEnumMemberValue(6))); model.AddElement(enumType1); var functionImport_MultipleNullableParameters = container.AddFunctionAndFunctionImport(model, "FunctionImport_MultipleNullableParameters", coreModel.GetString(false) /*returnType*/, null /*entitySet*/, false /*composable*/, false /*bindable*/); var function_MultipleNullableParameters = functionImport_MultipleNullableParameters.Function.AsEdmFunction(); 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*/)); function_MultipleNullableParameters.AddParameter("p17", enumType1.ToTypeReference(true /*isNullable*/)); return(model); }
public void WriterShouldNotIncludeTypeNameForCollectionOfDerivedType() { // JSON Light: writer doesn't include type name for collection of derived type // If I have a collection property declared in metadata as Collection(Edm.Geography), // and at serialization type, it's clearly a Collection(Edm.GeographyPoint), // we won't write the type name for that property by default (i.e., minimal metadata mode). var model = new EdmModel(); var entityType = new EdmEntityType("Var1", "Type"); entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); entityType.AddProperty(new EdmStructuralProperty(entityType, "Geographies", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.Geography, false))))); model.AddElement(entityType); var writerSettings = new ODataMessageWriterSettings(); writerSettings.SetContentType(ODataFormat.Json); writerSettings.EnableMessageStreamDisposal = false; var message = new InMemoryMessage { Stream = new MemoryStream() }; using (ODataMessageWriter odataMessageWriter = new ODataMessageWriter((IODataRequestMessage)message, writerSettings, model)) { ODataWriter odataWriter = odataMessageWriter.CreateODataResourceWriter(); odataWriter.WriteStart( new ODataResource { TypeName = "Var1.Type", Properties = new[] { new ODataProperty() { Name = "Id", Value = 1 }, new ODataProperty() { Name = "Geographies", Value = new ODataCollectionValue { Items = new[] { GeographyPoint.Create(0, 0), GeographyPoint.Create(1, 1), GeographyPoint.Create(2, 2) } } }, } }); odataWriter.WriteEnd(); odataWriter.Flush(); } message.Stream.Position = 0; var output = new StreamReader(message.Stream).ReadToEnd(); Assert.IsFalse(output.Contains("Collection(Edm.GeographyPoint)"), @"output.Contains(""Collection(Edm.GeographyPoint)"" == false"); }