private static void EnumMemberExpressionDemo() { Console.WriteLine("EnumMemberExpressionDemo"); var model = new EdmModel(); var personType = new EdmEntityType("TestNS", "Person"); model.AddElement(personType); var pid = personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false); personType.AddKeys(pid); personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); var colorType = new EdmEnumType("TestNS2", "Color", true); model.AddElement(colorType); colorType.AddMember("Cyan", new EdmIntegerConstant(1)); colorType.AddMember("Blue", new EdmIntegerConstant(2)); var outColorTerm = new EdmTerm("TestNS", "OutColor", new EdmEnumTypeReference(colorType, true)); model.AddElement(outColorTerm); var exp = new EdmEnumMemberExpression( new EdmEnumMember(colorType, "Blue", new EdmIntegerConstant(2)) ); var annotation = new EdmAnnotation(personType, outColorTerm, exp); annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.SetVocabularyAnnotation(annotation); ShowModel(model); var ann = model.FindVocabularyAnnotations<IEdmValueAnnotation>(personType, "TestNS.OutColor").First(); var memberExp = (IEdmEnumMemberExpression)ann.Value; foreach (var member in memberExp.EnumMembers) { Console.WriteLine(member.Name); } }
public ODataJsonLightInheritComplexCollectionWriterTests() { collectionStartWithoutSerializationInfo = new ODataCollectionStart(); collectionStartWithSerializationInfo = new ODataCollectionStart(); collectionStartWithSerializationInfo.SetSerializationInfo(new ODataCollectionStartSerializationInfo { CollectionTypeName = "Collection(ns.Address)" }); address = new ODataComplexValue { Properties = new[] { new ODataProperty { Name = "Street", Value = "1 Microsoft Way" }, new ODataProperty { Name = "Zipcode", Value = 98052 }, new ODataProperty { Name = "State", Value = new ODataEnumValue("WA", "ns.StateEnum") }, new ODataProperty { Name = "City", Value = "Shanghai" } }, TypeName = "TestNamespace.DerivedAddress" }; items = new[] { address }; EdmComplexType addressType = new EdmComplexType("ns", "Address"); addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(isNullable: true))); addressType.AddProperty(new EdmStructuralProperty(addressType, "Zipcode", EdmCoreModel.Instance.GetInt32(isNullable: true))); var stateEnumType = new EdmEnumType("ns", "StateEnum", isFlags: true); stateEnumType.AddMember("IL", new EdmIntegerConstant(1)); stateEnumType.AddMember("WA", new EdmIntegerConstant(2)); addressType.AddProperty(new EdmStructuralProperty(addressType, "State", new EdmEnumTypeReference(stateEnumType, true))); EdmComplexType derivedAddressType = new EdmComplexType("ns", "DerivedAddress", addressType, false); derivedAddressType.AddProperty(new EdmStructuralProperty(derivedAddressType, "City", EdmCoreModel.Instance.GetString(isNullable: true))); addressTypeReference = new EdmComplexTypeReference(addressType, isNullable: false); derivedAddressTypeReference = new EdmComplexTypeReference(derivedAddressType, isNullable: false); }
public void GetEdmType_HasSameDefinition_AsInitializedEdmType() { var enumType = new EdmEnumType("NS", "Enum"); var edmObject = new TestEdmEnumObject(enumType, "test"); Assert.Equal(enumType, edmObject.GetEdmType().Definition); }
public void GetEdmType_AgreesWithPropertyIsNullable() { var enumType = new EdmEnumType("NS", "Enum"); var edmObject = new TestEdmEnumObject(enumType, "test"); edmObject.IsNullable = true; Assert.True(edmObject.GetEdmType().IsNullable); }
public void Initialize() { this.model = new EdmModel(); EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo"); personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16); personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String); personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String); personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid); EdmComplexType derivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedPersonalInfo", personalInfo); derivedPersonalInfo.AddStructuralProperty("Hobby", EdmPrimitiveTypeKind.String); EdmComplexType derivedDerivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedPersonalInfo", derivedPersonalInfo); derivedDerivedPersonalInfo.AddStructuralProperty("Education", EdmPrimitiveTypeKind.String); EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject"); subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16); EdmComplexType derivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedSubject", subjectInfo); derivedSubjectInfo.AddStructuralProperty("Teacher", EdmPrimitiveTypeKind.String); EdmComplexType derivedDerivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedSubject", derivedSubjectInfo); derivedDerivedSubjectInfo.AddStructuralProperty("Classroom", EdmPrimitiveTypeKind.String); EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable: true))); studentInfo = new EdmEntityType(MyNameSpace, "Student"); studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false)); studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection)); // enum with flags var enumFlagsType = new EdmEnumType(MyNameSpace, "ColorFlags", isFlags: true); enumFlagsType.AddMember("Red", new EdmIntegerConstant(1)); enumFlagsType.AddMember("Green", new EdmIntegerConstant(2)); enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4)); studentInfo.AddStructuralProperty("ClothesColors", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(enumFlagsType, true)))); EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false))); studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection)); model.AddElement(enumFlagsType); model.AddElement(studentInfo); model.AddElement(personalInfo); model.AddElement(derivedPersonalInfo); model.AddElement(derivedDerivedPersonalInfo); model.AddElement(subjectInfo); model.AddElement(derivedSubjectInfo); model.AddElement(derivedDerivedSubjectInfo); IEdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(defaultContainer); this.studentSet = new EdmEntitySet(defaultContainer, "MySet", this.studentInfo); }
public void TryParseEnumMemberOfInvalidPathShouldBeFalse() { var enumType = new EdmEnumType("Ns", "Color"); enumType.AddMember("Blue", new EdmIntegerConstant(0)); enumType.AddMember("White", new EdmIntegerConstant(1)); var complexType = new EdmComplexType("Ns", "Address"); string enumPath = "Ns.Color//Blue"; List<IEdmSchemaType> types = new List<IEdmSchemaType> { enumType, complexType }; IEnumerable<IEdmEnumMember> parsedMember; EdmEnumValueParser.TryParseEnumMember(enumPath, BuildModelFromTypes(types), null, out parsedMember).Should().BeFalse(); }
public ODataJsonLightReaderEnumIntegrationTests() { EdmModel tmpModel = new EdmModel(); // enum without flags var enumType = new EdmEnumType("NS", "Color"); var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1)); enumType.AddMember(red); enumType.AddMember("Green", new EdmIntegerConstant(2)); enumType.AddMember("Blue", new EdmIntegerConstant(3)); tmpModel.AddElement(enumType); // enum with flags var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true); enumFlagsType.AddMember("Red", new EdmIntegerConstant(1)); enumFlagsType.AddMember("Green", new EdmIntegerConstant(2)); enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4)); tmpModel.AddElement(enumFlagsType); this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null); EdmStructuralProperty floatId = new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetSingle(false)); this.entityType.AddKeys(floatId); this.entityType.AddProperty(floatId); var enumTypeReference = new EdmEnumTypeReference(enumType, true); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference)); var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference)); // enum in complex type EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType"); myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference)); myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false))); tmpModel.AddElement(myComplexType); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true))); // enum in derived complex type EdmComplexType myDerivedComplexType = new EdmComplexType("NS", "MyDerivedComplexType", myComplexType, false); myDerivedComplexType.AddProperty(new EdmStructuralProperty(myDerivedComplexType, "MyDerivedColorFlags", new EdmEnumTypeReference(enumFlagsType, false))); tmpModel.AddElement(myDerivedComplexType); // enum in collection type EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType))); tmpModel.AddElement(this.entityType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub"); this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType); defaultContainer.AddEntitySet(this.entitySet.Name, this.entityType); tmpModel.AddElement(defaultContainer); this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", tmpModel); }
public ODataAtomWriterEnumIntegrationTests() { this.userModel = new EdmModel(); var enumType = new EdmEnumType("NS", "Color"); var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1)); enumType.AddMember(red); enumType.AddMember("Green", new EdmIntegerConstant(2)); enumType.AddMember("Blue", new EdmIntegerConstant(3)); // enum with flags var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true); enumFlagsType.AddMember("Red", new EdmIntegerConstant(1)); enumFlagsType.AddMember("Green", new EdmIntegerConstant(2)); enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4)); this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null); this.entityType.AddKeys(new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetDouble(false))); var enumTypeReference = new EdmEnumTypeReference(enumType, true); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference)); // add enum with flags var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference)); // enum in complex type EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType"); myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference)); myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false))); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true))); // enum in collection type EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType))); this.userModel.AddElement(this.entityType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); this.userModel.AddElement(defaultContainer); this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType); }
public EnumFilterFunctionalTests() { // set up the edm model etc this.userModel = new EdmModel(); var enumType = new EdmEnumType("NS", "Color", EdmPrimitiveTypeKind.Int32, false); var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1)); enumType.AddMember(red); enumType.AddMember("Green", new EdmIntegerConstant(2)); enumType.AddMember("Blue", new EdmIntegerConstant(3)); enumType.AddMember("White", new EdmIntegerConstant(-10)); // add to model this.userModel.AddElement(enumType); // add enum property this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null); var enumTypeReference = new EdmEnumTypeReference(enumType, true); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference)); // enum with flags var enumFlagsType = new EdmEnumType("NS", "ColorFlags", EdmPrimitiveTypeKind.Int64, true); enumFlagsType.AddMember("Red", new EdmIntegerConstant(1L)); enumFlagsType.AddMember("Green", new EdmIntegerConstant(2L)); enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4L)); enumFlagsType.AddMember("GreenRed", new EdmIntegerConstant(3L)); // add to model this.userModel.AddElement(enumFlagsType); // add enum with flags var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, true); this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference)); this.userModel.AddElement(this.entityType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); this.userModel.AddElement(defaultContainer); this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType); defaultContainer.AddElement(this.entitySet); }
public void RoundTripEnumsWithUnderlyingValuesOtherThanInt32() { var underlyingTypes = new[] { EdmPrimitiveTypeKind.Byte, EdmPrimitiveTypeKind.SByte, EdmPrimitiveTypeKind.Int16, EdmPrimitiveTypeKind.Int64, }; int counter = 0; var enumTypes = underlyingTypes.Select(t => { var enumType = new EdmEnumType("NS1", "Direction" + counter++, t, false); enumType.AddMember("East", new EdmIntegerConstant(0L)); return (IEdmEnumType)enumType; }); this.BasicRoundtripTest(ModelBuilder.ModelWithEnumEdm(enumTypes.ToArray())); }
public void RoundTripEnumsWithFlagsandUnderlyingInt64() { var directionType = new EdmEnumType("NS1", "Direction", EdmPrimitiveTypeKind.Int64, isFlags: true); directionType.AddMember("East", new EdmIntegerConstant(0L)); directionType.AddMember("West", new EdmIntegerConstant(1L)); directionType.AddMember("South", new EdmIntegerConstant(2L)); directionType.AddMember("North", new EdmIntegerConstant(3L)); this.BasicRoundtripTest(ModelBuilder.ModelWithEnumEdm(directionType)); }
public void TryParseEnumMemberWithoutFlagsOfTwoValueShouldBeFalse() { var enumType = new EdmEnumType("Ns", "Permission"); enumType.AddMember("Read", new EdmIntegerConstant(0)); enumType.AddMember("Write", new EdmIntegerConstant(1)); var complexType = new EdmComplexType("Ns", "Address"); string enumPath = "Ns.Permission/Read Ns.Permission/Write"; List<IEdmSchemaType> types = new List<IEdmSchemaType> { enumType, complexType }; IEnumerable<IEdmEnumMember> parsedMember; EdmEnumValueParser.TryParseEnumMember(enumPath, BuildModelFromTypes(types), null, out parsedMember).Should().BeFalse(); }
public static IEdmModel CreateTripPinServiceModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var genderType = new EdmEnumType(ns, "PersonGender", isFlags: false); genderType.AddMember("Male", new EdmIntegerConstant(0)); genderType.AddMember("Female", new EdmIntegerConstant(1)); genderType.AddMember("Unknown", new EdmIntegerConstant(2)); model.AddElement(genderType); var cityType = new EdmComplexType(ns, "City"); cityType.AddProperty(new EdmStructuralProperty(cityType, "CountryRegion", EdmCoreModel.Instance.GetString(false))); cityType.AddProperty(new EdmStructuralProperty(cityType, "Name", EdmCoreModel.Instance.GetString(false))); cityType.AddProperty(new EdmStructuralProperty(cityType, "Region", EdmCoreModel.Instance.GetString(false))); model.AddElement(cityType); var locationType = new EdmComplexType(ns, "Location", null, false, true); locationType.AddProperty(new EdmStructuralProperty(locationType, "Address", EdmCoreModel.Instance.GetString(false))); locationType.AddProperty(new EdmStructuralProperty(locationType, "City", new EdmComplexTypeReference(cityType, false))); model.AddElement(locationType); var eventLocationType = new EdmComplexType(ns, "EventLocation", locationType, false, true); eventLocationType.AddProperty(new EdmStructuralProperty(eventLocationType, "BuildingInfo", EdmCoreModel.Instance.GetString(true))); model.AddElement(eventLocationType); var airportLocationType = new EdmComplexType(ns, "AirportLocation", locationType, false, true); airportLocationType.AddProperty(new EdmStructuralProperty(airportLocationType, "Loc", EdmCoreModel.Instance.GetSpatial(EdmPrimitiveTypeKind.GeographyPoint, false))); model.AddElement(airportLocationType); var photoType = new EdmEntityType(ns, "Photo", null, false, false, true); var photoIdProperty = new EdmStructuralProperty(photoType, "Id", EdmCoreModel.Instance.GetInt64(false)); photoType.AddProperty(photoIdProperty); photoType.AddKeys(photoIdProperty); photoType.AddProperty(new EdmStructuralProperty(photoType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(photoType); var photoSet = new EdmEntitySet(defaultContainer, "Photos", photoType); defaultContainer.AddElement(photoSet); var personType = new EdmEntityType(ns, "Person", null, false, /* isOpen */ true); var personIdProperty = new EdmStructuralProperty(personType, "UserName", EdmCoreModel.Instance.GetString(false)); personType.AddProperty(personIdProperty); personType.AddKeys(personIdProperty); personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false))); personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false))); personType.AddProperty(new EdmStructuralProperty(personType, "Emails", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))))); personType.AddProperty(new EdmStructuralProperty(personType, "AddressInfo", new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(locationType, true))))); personType.AddProperty(new EdmStructuralProperty(personType, "Gender", new EdmEnumTypeReference(genderType, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Concurrency", EdmCoreModel.Instance.GetInt64(false))); model.AddElement(personType); var personSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(personSet); var airlineType = new EdmEntityType(ns, "Airline"); var airlineCodeProp = new EdmStructuralProperty(airlineType, "AirlineCode", EdmCoreModel.Instance.GetString(false)); airlineType.AddKeys(airlineCodeProp); airlineType.AddProperty(airlineCodeProp); airlineType.AddProperty(new EdmStructuralProperty(airlineType, "Name", EdmCoreModel.Instance.GetString(false))); model.AddElement(airlineType); var airlineSet = new EdmEntitySet(defaultContainer, "Airlines", airlineType); defaultContainer.AddElement(airlineSet); var airportType = new EdmEntityType(ns, "Airport"); var airportIdType = new EdmStructuralProperty(airportType, "IcaoCode", EdmCoreModel.Instance.GetString(false)); airportType.AddProperty(airportIdType); airportType.AddKeys(airportIdType); airportType.AddProperty(new EdmStructuralProperty(airportType, "Name", EdmCoreModel.Instance.GetString(false))); airportType.AddProperty(new EdmStructuralProperty(airportType, "IataCode", EdmCoreModel.Instance.GetString(false))); airportType.AddProperty(new EdmStructuralProperty(airportType, "Location", new EdmComplexTypeReference(airportLocationType, false))); model.AddElement(airportType); var airportSet = new EdmEntitySet(defaultContainer, "Airports", airportType); defaultContainer.AddElement(airportSet); var planItemType = new EdmEntityType(ns, "PlanItem"); var planItemIdType = new EdmStructuralProperty(planItemType, "PlanItemId", EdmCoreModel.Instance.GetInt32(false)); planItemType.AddProperty(planItemIdType); planItemType.AddKeys(planItemIdType); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "ConfirmationCode", EdmCoreModel.Instance.GetString(true))); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(true))); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(true))); planItemType.AddProperty(new EdmStructuralProperty(planItemType, "Duration", EdmCoreModel.Instance.GetDuration(true))); model.AddElement(planItemType); var publicTransportationType = new EdmEntityType(ns, "PublicTransportation", planItemType); publicTransportationType.AddProperty(new EdmStructuralProperty(publicTransportationType, "SeatNumber", EdmCoreModel.Instance.GetString(true))); model.AddElement(publicTransportationType); var flightType = new EdmEntityType(ns, "Flight", publicTransportationType); var flightNumberType = new EdmStructuralProperty(flightType, "FlightNumber", EdmCoreModel.Instance.GetString(false)); flightType.AddProperty(flightNumberType); model.AddElement(flightType); var eventType = new EdmEntityType(ns, "Event", planItemType, false, true); eventType.AddProperty(new EdmStructuralProperty(eventType, "Description", EdmCoreModel.Instance.GetString(true))); eventType.AddProperty(new EdmStructuralProperty(eventType, "OccursAt", new EdmComplexTypeReference(eventLocationType, false))); model.AddElement(eventType); var tripType = new EdmEntityType(ns, "Trip"); var tripIdType = new EdmStructuralProperty(tripType, "TripId", EdmCoreModel.Instance.GetInt32(false)); tripType.AddProperty(tripIdType); tripType.AddKeys(tripIdType); tripType.AddProperty(new EdmStructuralProperty(tripType, "ShareId", EdmCoreModel.Instance.GetGuid(true))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Description", EdmCoreModel.Instance.GetString(true))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Name", EdmCoreModel.Instance.GetString(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Budget", EdmCoreModel.Instance.GetSingle(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "StartsAt", EdmCoreModel.Instance.GetDateTimeOffset(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "EndsAt", EdmCoreModel.Instance.GetDateTimeOffset(false))); tripType.AddProperty(new EdmStructuralProperty(tripType, "Tags", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); model.AddElement(tripType); var friendsnNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Friends", Target = personType, TargetMultiplicity = EdmMultiplicity.Many }); var personTripNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Trips", Target = tripType, TargetMultiplicity = EdmMultiplicity.Many, ContainsTarget = true }); var personPhotoNavigation = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Photo", Target = photoType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, }); var tripPhotosNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Photos", Target = photoType, TargetMultiplicity = EdmMultiplicity.Many, }); var tripItemNavigation = tripType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "PlanItems", Target = planItemType, ContainsTarget = true, TargetMultiplicity = EdmMultiplicity.Many }); var flightFromAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "From", Target = airportType, TargetMultiplicity = EdmMultiplicity.One }); var flightToAirportNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "To", Target = airportType, TargetMultiplicity = EdmMultiplicity.One }); var flightAirlineNavigation = flightType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Airline", Target = airlineType, TargetMultiplicity = EdmMultiplicity.One }); var me = new EdmSingleton(defaultContainer, "Me", personType); defaultContainer.AddElement(me); personSet.AddNavigationTarget(friendsnNavigation, personSet); me.AddNavigationTarget(friendsnNavigation, personSet); personSet.AddNavigationTarget(flightAirlineNavigation, airlineSet); me.AddNavigationTarget(flightAirlineNavigation, airlineSet); personSet.AddNavigationTarget(flightFromAirportNavigation, airportSet); me.AddNavigationTarget(flightFromAirportNavigation, airportSet); personSet.AddNavigationTarget(flightToAirportNavigation, airportSet); me.AddNavigationTarget(flightToAirportNavigation, airportSet); personSet.AddNavigationTarget(personPhotoNavigation, photoSet); me.AddNavigationTarget(personPhotoNavigation, photoSet); personSet.AddNavigationTarget(tripPhotosNavigation, photoSet); me.AddNavigationTarget(tripPhotosNavigation, photoSet); var getFavoriteAirlineFunction = new EdmFunction(ns, "GetFavoriteAirline", new EdmEntityTypeReference(airlineType, false), true, new EdmPathExpression("person/Trips/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Flight/Airline"), true); getFavoriteAirlineFunction.AddParameter("person", new EdmEntityTypeReference(personType, false)); model.AddElement(getFavoriteAirlineFunction); var getInvolvedPeopleFunction = new EdmFunction(ns, "GetInvolvedPeople", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(personType, false))), true, null, true); getInvolvedPeopleFunction.AddParameter("trip", new EdmEntityTypeReference(tripType, false)); model.AddElement(getInvolvedPeopleFunction); var getFriendsTripsFunction = new EdmFunction(ns, "GetFriendsTrips", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(tripType, false))), true, new EdmPathExpression("person/Friends/Trips"), true); getFriendsTripsFunction.AddParameter("person", new EdmEntityTypeReference(personType, false)); getFriendsTripsFunction.AddParameter("userName", EdmCoreModel.Instance.GetString(false)); model.AddElement(getFriendsTripsFunction); var getNearestAirport = new EdmFunction(ns, "GetNearestAirport", new EdmEntityTypeReference(airportType, false), false, null, true); getNearestAirport.AddParameter("lat", EdmCoreModel.Instance.GetDouble(false)); getNearestAirport.AddParameter("lon", EdmCoreModel.Instance.GetDouble(false)); model.AddElement(getNearestAirport); var getNearestAirportFunctionImport = (IEdmFunctionImport)defaultContainer.AddFunctionImport("GetNearestAirport", getNearestAirport, new EdmEntitySetReferenceExpression(airportSet), true); var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null); model.AddElement(resetDataSourceAction); defaultContainer.AddActionImport(resetDataSourceAction); var shareTripAction = new EdmAction(ns, "ShareTrip", null, true, null); shareTripAction.AddParameter("person", new EdmEntityTypeReference(personType, false)); shareTripAction.AddParameter("userName", EdmCoreModel.Instance.GetString(false)); shareTripAction.AddParameter("tripId", EdmCoreModel.Instance.GetInt32(false)); model.AddElement(shareTripAction); model.SetDescriptionAnnotation(defaultContainer, "TripPin service is a sample service for OData V4."); model.SetOptimisticConcurrencyAnnotation(personSet, personType.StructuralProperties().Where(p => p.Name == "Concurrency")); // TODO: currently singleton does not support ETag feature // model.SetOptimisticConcurrencyAnnotation(me, personType.StructuralProperties().Where(p => p.Name == "Concurrency")); model.SetResourcePathCoreAnnotation(personSet, "People"); model.SetResourcePathCoreAnnotation(me, "Me"); model.SetResourcePathCoreAnnotation(airlineSet, "Airlines"); model.SetResourcePathCoreAnnotation(airportSet, "Airports"); model.SetResourcePathCoreAnnotation(photoSet, "Photos"); model.SetResourcePathCoreAnnotation(getNearestAirportFunctionImport, "Microsoft.OData.SampleService.Models.TripPin.GetNearestAirport"); model.SetDereferenceableIDsCoreAnnotation(defaultContainer, true); model.SetConventionalIDsCoreAnnotation(defaultContainer, true); model.SetPermissionsCoreAnnotation(personType.FindProperty("UserName"), CorePermission.Read); model.SetPermissionsCoreAnnotation(airlineType.FindProperty("AirlineCode"), CorePermission.Read); model.SetPermissionsCoreAnnotation(airportType.FindProperty("IcaoCode"), CorePermission.Read); model.SetPermissionsCoreAnnotation(planItemType.FindProperty("PlanItemId"), CorePermission.Read); model.SetPermissionsCoreAnnotation(tripType.FindProperty("TripId"), CorePermission.Read); model.SetPermissionsCoreAnnotation(photoType.FindProperty("Id"), CorePermission.Read); model.SetImmutableCoreAnnotation(airportType.FindProperty("IataCode"), true); model.SetComputedCoreAnnotation(personType.FindProperty("Concurrency"), true); model.SetAcceptableMediaTypesCoreAnnotation(photoType, new[] { "image/jpeg" }); model.SetConformanceLevelCapabilitiesAnnotation(defaultContainer, CapabilitiesConformanceLevelType.Advanced); model.SetSupportedFormatsCapabilitiesAnnotation(defaultContainer, new[] { "application/json;odata.metadata=full;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=minimal;IEEE754Compatible=false;odata.streaming=true", "application/json;odata.metadata=none;IEEE754Compatible=false;odata.streaming=true" }); model.SetAsynchronousRequestsSupportedCapabilitiesAnnotation(defaultContainer, true); model.SetBatchContinueOnErrorSupportedCapabilitiesAnnotation(defaultContainer, false); model.SetNavigationRestrictionsCapabilitiesAnnotation(personSet, CapabilitiesNavigationType.None, new[] { new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>(friendsnNavigation, CapabilitiesNavigationType.Recursive) }); model.SetFilterFunctionsCapabilitiesAnnotation(defaultContainer, new[] { "contains", "endswith", "startswith", "length", "indexof", "substring", "tolower", "toupper", "trim", "concat", "year", "month", "day", "hour", "minute", "second", "round", "floor", "ceiling", "cast", "isof" }); model.SetSearchRestrictionsCapabilitiesAnnotation(personSet, true, CapabilitiesSearchExpressions.None); model.SetSearchRestrictionsCapabilitiesAnnotation(airlineSet, true, CapabilitiesSearchExpressions.None); model.SetSearchRestrictionsCapabilitiesAnnotation(airportSet, true, CapabilitiesSearchExpressions.None); model.SetSearchRestrictionsCapabilitiesAnnotation(photoSet, true, CapabilitiesSearchExpressions.None); model.SetInsertRestrictionsCapabilitiesAnnotation(personSet, true, new[] { personTripNavigation, friendsnNavigation }); model.SetInsertRestrictionsCapabilitiesAnnotation(airlineSet, true, null); model.SetInsertRestrictionsCapabilitiesAnnotation(airportSet, false, null); model.SetInsertRestrictionsCapabilitiesAnnotation(photoSet, true, null); // TODO: model.SetUpdateRestrictionsCapabilitiesAnnotation(); model.SetDeleteRestrictionsCapabilitiesAnnotation(airportSet, false, null); model.SetISOCurrencyMeasuresAnnotation(tripType.FindProperty("Budget"), "USD"); model.SetScaleMeasuresAnnotation(tripType.FindProperty("Budget"), 2); return model; }
public static IEdmModel CreateModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var orderDetail = new EdmComplexType(ns, "orderDetail"); orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "amount", EdmCoreModel.Instance.GetDecimal(false))); orderDetail.AddProperty(new EdmStructuralProperty(orderDetail, "quantity", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(orderDetail); var billingType = new EdmEnumType(ns, "billingType", EdmPrimitiveTypeKind.Int64, false); billingType.AddMember("fund", new EdmIntegerConstant(0)); billingType.AddMember("refund", new EdmIntegerConstant(1)); billingType.AddMember("chargeback", new EdmIntegerConstant(2)); model.AddElement(billingType); var category = new EdmEnumType(ns, "category", true); category.AddMember("toy", new EdmIntegerConstant(1)); category.AddMember("food", new EdmIntegerConstant(2)); category.AddMember("cloth", new EdmIntegerConstant(4)); category.AddMember("drink", new EdmIntegerConstant(8)); category.AddMember("computer", new EdmIntegerConstant(16)); model.AddElement(category); var namedObject = new EdmEntityType(ns, "namedObject"); var idProperty = new EdmStructuralProperty(namedObject, "id", EdmCoreModel.Instance.GetInt32(false)); namedObject.AddProperty(idProperty); namedObject.AddKeys(idProperty); namedObject.AddProperty(new EdmStructuralProperty(namedObject, "name", EdmCoreModel.Instance.GetString(false))); model.AddElement(namedObject); var order = new EdmEntityType(ns, "order", namedObject); order.AddProperty(new EdmStructuralProperty(order, "description", EdmCoreModel.Instance.GetString(false))); order.AddProperty(new EdmStructuralProperty(order, "detail", new EdmComplexTypeReference(orderDetail, true))); order.AddProperty(new EdmStructuralProperty(order, "lineItems", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); order.AddProperty(new EdmStructuralProperty(order, "categories", new EdmEnumTypeReference(category, false))); model.AddElement(order); var billingRecord = new EdmEntityType(ns, "billingRecord", namedObject); billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "amount", EdmCoreModel.Instance.GetDecimal(false))); billingRecord.AddProperty(new EdmStructuralProperty(billingRecord, "type", new EdmEnumTypeReference(billingType, false))); model.AddElement(billingRecord); var store = new EdmEntityType(ns, "store", namedObject); store.AddProperty(new EdmStructuralProperty(store, "address", EdmCoreModel.Instance.GetString(false))); model.AddElement(store); var orders = new EdmEntitySet(defaultContainer, "orders", order); defaultContainer.AddElement(orders); var billingRecords = new EdmEntitySet(defaultContainer, "billingRecords", billingRecord); defaultContainer.AddElement(billingRecords); var myStore = new EdmSingleton(defaultContainer, "myStore", store); defaultContainer.AddElement(myStore); var order2billingRecord = order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "billingRecords", Target = billingRecord, TargetMultiplicity = EdmMultiplicity.Many }); ((EdmEntitySet)orders).AddNavigationTarget(order2billingRecord, billingRecords); IEnumerable<EdmError> errors = null; model.Validate(out errors); return model; }
public void ConstructibleModelODataTestModelWithFunctionImport() { EdmModel model = new EdmModel(); EdmComplexType complexType = new EdmComplexType("TestModel", "ComplexType"); EdmStructuralProperty primitiveProperty = complexType.AddStructuralProperty("PrimitiveProperty", EdmCoreModel.Instance.GetString(false)); EdmStructuralProperty complexProperty = complexType.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType, false)); model.AddElement(complexType); EdmEntityType entity = new EdmEntityType("TestNS", "EntityType"); EdmStructuralProperty entityId = entity.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)); entity.AddKeys(entityId); EdmStructuralProperty entityComplexProperty = entity.AddStructuralProperty("ComplexProperty", new EdmComplexTypeReference(complexType, false)); model.AddElement(entity); EdmEnumType enumType = new EdmEnumType("TestNS", "EnumType"); model.AddElement(enumType); EdmEntityContainer container = new EdmEntityContainer("TestNS", "TestContainer"); EdmAction primitiveOperationAction = new EdmAction("TestNS", "FunctionImport_Primitive", null); EdmOperationParameter primitiveParameter = new EdmOperationParameter(primitiveOperationAction, "primitive", EdmCoreModel.Instance.GetString(true)); primitiveOperationAction.AddParameter(primitiveParameter); model.AddElement(primitiveOperationAction); container.AddActionImport("FunctionImport_Primitive", primitiveOperationAction); EdmAction primitiveCollectionOperationAction = new EdmAction("TestNS", "FunctionImport_PrimitiveCollection", null); EdmOperationParameter primitiveCollectionParameter = new EdmOperationParameter(primitiveCollectionOperationAction, "primitiveCollection", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(true))); primitiveCollectionOperationAction.AddParameter(primitiveCollectionParameter); model.AddElement(primitiveCollectionOperationAction); container.AddActionImport("FunctionImport_PrimitiveCollection", primitiveCollectionOperationAction); EdmAction complexOperationAction = new EdmAction("TestNS", "FunctionImport_Complex", null); EdmOperationParameter complexParameter = new EdmOperationParameter(complexOperationAction, "complex", new EdmComplexTypeReference(complexType, true)); complexOperationAction.AddParameter(complexParameter); model.AddElement(complexOperationAction); container.AddActionImport("FunctionImport_Complex", complexOperationAction); EdmAction complexCollectionOperationAction = new EdmAction("TestNS", "FunctionImport_ComplexCollection", null); EdmOperationParameter complexCollectionParameter = new EdmOperationParameter(complexCollectionOperationAction, "complexCollection", EdmCoreModel.GetCollection(new EdmComplexTypeReference(complexType, true))); complexCollectionOperationAction.AddParameter(complexCollectionParameter); model.AddElement(complexCollectionOperationAction); container.AddActionImport("FunctionImport_ComplexCollection", complexCollectionOperationAction); EdmAction entityOperationAction = new EdmAction("TestNS", "FunctionImport_Entry", null); EdmOperationParameter entityParameter = new EdmOperationParameter(entityOperationAction, "entry", new EdmEntityTypeReference(entity, true)); entityOperationAction.AddParameter(entityParameter); model.AddElement(entityOperationAction); container.AddActionImport("FunctionImport_Entry", entityOperationAction); EdmAction feedOperationAction = new EdmAction("TestNS", "FunctionImport_Feed", null); EdmOperationParameter feedParameter = new EdmOperationParameter(feedOperationAction, "feed", EdmCoreModel.GetCollection(new EdmEntityTypeReference(entity, true))); feedOperationAction.AddParameter(feedParameter); model.AddElement(feedOperationAction); container.AddActionImport("FunctionImport_Feed", feedOperationAction); EdmAction streamOperationAction = new EdmAction("TestNS", "FunctionImport_Stream", null); EdmOperationParameter streamParameter = new EdmOperationParameter(streamOperationAction, "stream", EdmCoreModel.Instance.GetStream(true)); streamOperationAction.AddParameter(streamParameter); model.AddElement(streamOperationAction); container.AddActionImport("FunctionImport_Stream", streamOperationAction); EdmAction enumOperationAction = new EdmAction("TestNS", "FunctionImport_Enum", null); EdmOperationParameter enumParameter = new EdmOperationParameter(enumOperationAction, "enum", new EdmEnumTypeReference(enumType, true)); enumOperationAction.AddParameter(enumParameter); model.AddElement(enumOperationAction); container.AddActionImport("FunctionImport_Enum", enumOperationAction); model.AddElement(container); this.BasicConstructibleModelTestSerializingStockModel(ODataTestModelBuilder.ODataTestModelWithFunctionImport, model); }
public void EnumTypeReferenceFullNameTest() { var enumType = new EdmEnumType("n", "enumtype"); enumType.FullTypeName().Should().Be("n.enumtype"); }
private void CreateEnumTypeBody(EdmEnumType type, EnumTypeConfiguration config) { Contract.Assert(type != null); Contract.Assert(config != null); foreach (EnumMemberConfiguration member in config.Members) { // EdmIntegerConstant can only support a value of long type. long value; try { value = Convert.ToInt64(member.MemberInfo, CultureInfo.InvariantCulture); } catch { throw Error.Argument("value", SRResources.EnumValueCannotBeLong, Enum.GetName(member.MemberInfo.GetType(), member.MemberInfo)); } EdmEnumMember edmMember = new EdmEnumMember(type, member.Name, new EdmIntegerConstant(value)); type.AddMember(edmMember); _members[member.MemberInfo] = edmMember; } }
private static EdmModel SetNullAnnotationNameModel() { EdmModel model = new EdmModel(); EdmEnumType spicy = new EdmEnumType("DefaultNamespace", "Spicy"); model.AddElement(spicy); XElement annotationElement = new XElement("{http://foo}Annotation", new XElement("{http://foo1}Child", "1" ) ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(spicy, "http://foo", null, annotation); return model; }
public void TryParseEnumMemberOfTwoValuesWithInvalidEnumTypeShouldBeFalse() { var enumType = new EdmEnumType("Ns", "Permission", EdmPrimitiveTypeKind.String, true); enumType.AddMember("Read", new EdmStringConstant("1")); enumType.AddMember("Write", new EdmStringConstant("2")); var complexType = new EdmComplexType("Ns", "Address"); string enumPath = "Ns.Permission/Read Ns.Permissions/Write"; List<IEdmSchemaType> types = new List<IEdmSchemaType> { enumType, complexType }; IEnumerable<IEdmEnumMember> parsedMember; EdmEnumValueParser.TryParseEnumMember(enumPath, BuildModelFromTypes(types), null, out parsedMember).Should().BeFalse(); }
public void EvaluateEnumExpressionOfMultiValues() { var color = new EdmEnumType("Ns", "Color", true); var blue = color.AddMember("Blue", new EdmIntegerConstant(1)); var white = color.AddMember("White", new EdmIntegerConstant(2)); var enumExpression = new EdmEnumMemberExpression(blue, white); EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null); var value = evaluator.Evaluate(enumExpression) as IEdmEnumValue; value.Type.Definition.Should().Be(color); (value.Value as EdmIntegerConstant).Value.Should().Be(3); }
public void TryParseEnumMemberWithFlagsOfMultiValueShouldBeTrue() { var enumType = new EdmEnumType("Ns", "Permission", true); var read = enumType.AddMember("Read", new EdmIntegerConstant(1)); var write = enumType.AddMember("Write", new EdmIntegerConstant(2)); var readwrite = enumType.AddMember("ReadWrite", new EdmIntegerConstant(3)); var complexType = new EdmComplexType("Ns", "Address"); string enumPath = "Ns.Permission/Read Ns.Permission/Write Ns.Permission/ReadWrite"; List<IEdmSchemaType> types = new List<IEdmSchemaType> { enumType, complexType }; IEnumerable<IEdmEnumMember> parsedMember; EdmEnumValueParser.TryParseEnumMember(enumPath, BuildModelFromTypes(types), null, out parsedMember).Should().BeTrue(); parsedMember.Count().Should().Be(3); parsedMember.Should().Contain(read).And.Contain(write).And.Contain(readwrite); }
public void EvaluateEnumExpressionOfMultiValuesWithoutFlagsShouldThrow() { var color = new EdmEnumType("Ns", "Color"); var blue = color.AddMember("Blue", new EdmIntegerConstant(1)); var white = color.AddMember("White", new EdmIntegerConstant(2)); var enumExpression = new EdmEnumMemberExpression(blue, white); EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null); Action action = () => evaluator.Evaluate(enumExpression); action.ShouldThrow<InvalidOperationException>().WithMessage("Type Ns.Color cannot be assigned with multi-values."); }
private static IEdmModel GetUnTypedEdmModel() { EdmModel model = new EdmModel(); // Enum type "Color" EdmEnumType colorEnum = new EdmEnumType("NS", "Color"); colorEnum.AddMember(new EdmEnumMember(colorEnum, "Red", new EdmIntegerConstant(0))); colorEnum.AddMember(new EdmEnumMember(colorEnum, "Blue", new EdmIntegerConstant(1))); colorEnum.AddMember(new EdmEnumMember(colorEnum, "Green", new EdmIntegerConstant(2))); model.AddElement(colorEnum); // complex type "Address" EdmComplexType address = new EdmComplexType("NS", "Address"); address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String); address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); model.AddElement(address); // derived complex type "SubAddress" EdmComplexType subAddress = new EdmComplexType("NS", "SubAddress", address); subAddress.AddStructuralProperty("Code", EdmPrimitiveTypeKind.Double); model.AddElement(subAddress); // entity type "Customer" EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); customer.AddStructuralProperty("Location", new EdmComplexTypeReference(address, isNullable: true)); model.AddElement(customer); // derived entity type special customer EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer); specialCustomer.AddStructuralProperty("Title", EdmPrimitiveTypeKind.Guid); model.AddElement(specialCustomer); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); model.AddElement(container); container.AddEntitySet("FCustomers", customer); EdmComplexTypeReference complexType = new EdmComplexTypeReference(address, isNullable: false); EdmCollectionTypeReference complexCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(complexType)); EdmEnumTypeReference enumType = new EdmEnumTypeReference(colorEnum, isNullable: false); EdmCollectionTypeReference enumCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(enumType)); EdmEntityTypeReference entityType = new EdmEntityTypeReference(customer, isNullable: false); EdmCollectionTypeReference entityCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(entityType)); IEdmTypeReference intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true); EdmCollectionTypeReference primitiveCollectionType = new EdmCollectionTypeReference(new EdmCollectionType(intType)); // bound functions BoundFunction(model, "IntCollectionFunction", "intValues", primitiveCollectionType, entityType); BoundFunction(model, "ComplexFunction", "address", complexType, entityType); BoundFunction(model, "ComplexCollectionFunction", "addresses", complexCollectionType, entityType); BoundFunction(model, "EnumFunction", "color", enumType, entityType); BoundFunction(model, "EnumCollectionFunction", "colors", enumCollectionType, entityType); BoundFunction(model, "EntityFunction", "customer", entityType, entityType); BoundFunction(model, "CollectionEntityFunction", "customers", entityCollectionType, entityType); // unbound functions UnboundFunction(container, "UnboundIntCollectionFunction", "intValues", primitiveCollectionType); UnboundFunction(container, "UnboundComplexFunction", "address", complexType); UnboundFunction(container, "UnboundComplexCollectionFunction", "addresses", complexCollectionType); UnboundFunction(container, "UnboundEnumFunction", "color", enumType); UnboundFunction(container, "UnboundEnumCollectionFunction", "colors", enumCollectionType); UnboundFunction(container, "UnboundEntityFunction", "customer", entityType); UnboundFunction(container, "UnboundCollectionEntityFunction", "customers", entityCollectionType); model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model)); return model; }
public void EvaluateEnumExpressionOfMultiValuesWithStringUnderlyingTypeShouldThrow() { var color = new EdmEnumType("Ns", "Color", EdmPrimitiveTypeKind.String, true); var blue = color.AddMember("Blue", new EdmStringConstant("1")); var white = color.AddMember("White", new EdmStringConstant("2")); var enumExpression = new EdmEnumMemberExpression(blue, white); EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null); Action action = () => evaluator.Evaluate(enumExpression); action.ShouldThrow<InvalidOperationException>().WithMessage("Type Ns.Color cannot be assigned with multi-values."); }
public void RoundTripEnumsWithValues() { var directionType = new EdmEnumType("NS1", "Direction"); directionType.AddMember("East", new EdmIntegerConstant(100L)); directionType.AddMember("West", new EdmIntegerConstant(1L)); directionType.AddMember("South", new EdmIntegerConstant(-2L)); directionType.AddMember("North", new EdmIntegerConstant(3L)); this.BasicRoundtripTest(ModelBuilder.ModelWithEnumEdm(directionType)); }
public void EvaluateEnumReferenceExpression() { var color = new EdmEnumType("Ns", "Color", true); var blue = color.AddMember("Blue", new EdmIntegerConstant(1)); color.AddMember("White", new EdmIntegerConstant(2)); var enumReferenceExpression = new EdmEnumMemberReferenceExpression(blue); EdmExpressionEvaluator evaluator = new EdmExpressionEvaluator(null); var value = evaluator.Evaluate(enumReferenceExpression) as IEdmEnumValue; value.Type.Definition.Should().Be(color); value.Value.As<EdmIntegerConstant>().Value.Should().Be(1); }
public static IEdmModel ModelWithDefaultEnumEdm() { var defaultEnum = new EdmEnumType("NS1", "Color", EdmPrimitiveTypeKind.Int32, false); defaultEnum.AddMember("Red", new EdmIntegerConstant(0)); defaultEnum.AddMember("Orange", new EdmIntegerConstant(1)); defaultEnum.AddMember("Yellow", new EdmIntegerConstant(2)); defaultEnum.AddMember("Green", new EdmIntegerConstant(3)); defaultEnum.AddMember("Cyan", new EdmIntegerConstant(4)); defaultEnum.AddMember("Blue", new EdmIntegerConstant(5)); defaultEnum.AddMember("Purple", new EdmIntegerConstant(6)); return ModelWithEnumEdm(defaultEnum); }
public void EqualityEnumTypeTest() { var baseline = new EdmEnumType("NS", "Baseline", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true); var match = new EdmEnumType("NS", "Baseline", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true); var differentNamespace = new EdmEnumType("foo", "Baseline", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true); var differentName = new EdmEnumType("NS", "foo", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true); var differentPrimitiveType = new EdmEnumType("NS", "Baseline", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int16), true); var differentFlag = new EdmEnumType("NS", "Baseline", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), false); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmEnumType(null, "Baseline", EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true)); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmEnumType("NS", null, EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true)); this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmEnumType("NS", "Baseline", null, true)); Assert.IsTrue(baseline.IsEquivalentTo(baseline), "Is the same."); Assert.IsFalse(baseline.IsEquivalentTo(match), "Same but different obj refs"); Assert.IsFalse(baseline.IsEquivalentTo(differentNamespace), "Different namespace."); Assert.IsFalse(baseline.IsEquivalentTo(differentName), "Different name."); Assert.IsFalse(baseline.IsEquivalentTo(differentPrimitiveType), "Different primitive type."); Assert.IsFalse(baseline.IsEquivalentTo(differentFlag), "Different flag."); }
private static IEdmEnumTypeReference GetEnumTypeReference( EdmProperty efProperty, EdmModel model, IDictionary<MetadataItem, IEdmElement> elementMap) { var efEnumType = efProperty.EnumType; EdmEnumType enumType; IEdmElement element; if (elementMap.TryGetValue(efEnumType, out element)) { enumType = (EdmEnumType)element; } else { enumType = new EdmEnumType(efEnumType.NamespaceName, efEnumType.Name); elementMap.Add(efEnumType, enumType); model.AddElement(enumType); foreach (var member in efEnumType.Members) { var longValue = Convert.ToInt64(member.Value, CultureInfo.InvariantCulture); enumType.AddMember(member.Name, new EdmIntegerConstant(longValue)); } } return new EdmEnumTypeReference(enumType, efProperty.Nullable); }
public CustomersModelWithInheritance() { EdmModel model = new EdmModel(); // Enum type simpleEnum EdmEnumType simpleEnum = new EdmEnumType("NS", "SimpleEnum"); simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "First", new EdmIntegerConstant(0))); simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Second", new EdmIntegerConstant(1))); simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Third", new EdmIntegerConstant(2))); model.AddElement(simpleEnum); // 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); // open complex type "Account" EdmComplexType account = new EdmComplexType("NS", "Account", null, false, true); account.AddStructuralProperty("Bank", EdmPrimitiveTypeKind.String); account.AddStructuralProperty("CardNum", EdmPrimitiveTypeKind.Int64); model.AddElement(account); EdmComplexType specialAccount = new EdmComplexType("NS", "SpecialAccount", account, false, true); specialAccount.AddStructuralProperty("SpecialCard", EdmPrimitiveTypeKind.String); model.AddElement(specialAccount); // entity type customer EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); IEdmProperty customerName = customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); customer.AddStructuralProperty("SimpleEnum", simpleEnum.ToEdmTypeReference(isNullable: false)); customer.AddStructuralProperty("Address", new EdmComplexTypeReference(address, isNullable: true)); customer.AddStructuralProperty("Account", new EdmComplexTypeReference(account, isNullable: true)); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( EdmPrimitiveTypeKind.String, isNullable: true); var city = customer.AddStructuralProperty( "City", primitiveTypeReference, 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); specialCustomer.AddStructuralProperty("SpecialAddress", new EdmComplexTypeReference(address, isNullable: true)); model.AddElement(specialCustomer); // entity type order (open entity type) EdmEntityType order = new EdmEntityType("NS", "Order", null, false, true); // EdmEntityType order = new EdmEntityType("NS", "Order"); order.AddKeys(order.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); order.AddStructuralProperty("City", EdmPrimitiveTypeKind.String); order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32); model.AddElement(order); // derived entity type special order EdmEntityType specialOrder = new EdmEntityType("NS", "SpecialOrder", order, false, true); specialOrder.AddStructuralProperty("SpecialOrderProperty", EdmPrimitiveTypeKind.Guid); model.AddElement(specialOrder); // test entity EdmEntityType testEntity = new EdmEntityType("System.Web.OData.Query.Expressions", "TestEntity"); testEntity.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Binary); model.AddElement(testEntity); // containment // my order EdmEntityType myOrder = new EdmEntityType("NS", "MyOrder"); myOrder.AddKeys(myOrder.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); myOrder.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(myOrder); // order line EdmEntityType orderLine = new EdmEntityType("NS", "OrderLine"); orderLine.AddKeys(orderLine.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); orderLine.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(orderLine); EdmNavigationProperty orderLinesNavProp = myOrder.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "OrderLines", TargetMultiplicity = EdmMultiplicity.Many, Target = orderLine, ContainsTarget = true, }); EdmNavigationProperty nonContainedOrderLinesNavProp = myOrder.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "NonContainedOrderLines", TargetMultiplicity = EdmMultiplicity.Many, Target = orderLine, ContainsTarget = false, }); EdmAction tag = new EdmAction("NS", "tag", returnType: null, isBound: true, entitySetPathExpression: null); tag.AddParameter("entity", new EdmEntityTypeReference(orderLine, false)); model.AddElement(tag); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance"); model.AddElement(container); EdmEntitySet customers = container.AddEntitySet("Customers", customer); EdmEntitySet orders = container.AddEntitySet("Orders", order); EdmEntitySet myOrders = container.AddEntitySet("MyOrders", myOrder); // singletons EdmSingleton vipCustomer = container.AddSingleton("VipCustomer", customer); EdmSingleton mary = container.AddSingleton("Mary", customer); EdmSingleton rootOrder = container.AddSingleton("RootOrder", order); // annotations model.SetOptimisticConcurrencyAnnotation(customers, new[] { city }); // containment IEdmContainedEntitySet orderLines = (IEdmContainedEntitySet)myOrders.FindNavigationTarget(orderLinesNavProp); // no-containment IEdmNavigationSource nonContainedOrderLines = myOrders.FindNavigationTarget(nonContainedOrderLinesNavProp); // actions EdmAction upgrade = new EdmAction("NS", "upgrade", returnType: null, isBound: true, entitySetPathExpression: null); upgrade.AddParameter("entity", new EdmEntityTypeReference(customer, false)); model.AddElement(upgrade); EdmAction specialUpgrade = new EdmAction("NS", "specialUpgrade", returnType: null, isBound: true, entitySetPathExpression: null); specialUpgrade.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false)); model.AddElement(specialUpgrade); // actions bound to collection EdmAction upgradeAll = new EdmAction("NS", "UpgradeAll", returnType: null, isBound: true, entitySetPathExpression: null); upgradeAll.AddParameter("entityset", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false)))); model.AddElement(upgradeAll); EdmAction upgradeSpecialAll = new EdmAction("NS", "UpgradeSpecialAll", returnType: null, isBound: true, entitySetPathExpression: null); upgradeSpecialAll.AddParameter("entityset", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(specialCustomer, false)))); model.AddElement(upgradeSpecialAll); // functions 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); EdmFunction IsUpgraded = new EdmFunction( "NS", "IsUpgraded", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); IsUpgraded.AddParameter("entity", new EdmEntityTypeReference(customer, false)); model.AddElement(IsUpgraded); EdmFunction orderByCityAndAmount = new EdmFunction( "NS", "OrderByCityAndAmount", stringType, isBound: true, entitySetPathExpression: null, isComposable: false); orderByCityAndAmount.AddParameter("entity", new EdmEntityTypeReference(customer, false)); orderByCityAndAmount.AddParameter("city", stringType); orderByCityAndAmount.AddParameter("amount", intType); model.AddElement(orderByCityAndAmount); EdmFunction getOrders = new EdmFunction( "NS", "GetOrders", EdmCoreModel.GetCollection(order.ToEdmTypeReference(false)), isBound: true, entitySetPathExpression: null, isComposable: true); getOrders.AddParameter("entity", new EdmEntityTypeReference(customer, false)); getOrders.AddParameter("parameter", intType); model.AddElement(getOrders); EdmFunction IsSpecialUpgraded = new EdmFunction( "NS", "IsSpecialUpgraded", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); IsSpecialUpgraded.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false)); model.AddElement(IsSpecialUpgraded); EdmFunction getSalary = new EdmFunction( "NS", "GetSalary", stringType, isBound: true, entitySetPathExpression: null, isComposable: false); getSalary.AddParameter("entity", new EdmEntityTypeReference(customer, false)); model.AddElement(getSalary); getSalary = new EdmFunction( "NS", "GetSalary", stringType, isBound: true, entitySetPathExpression: null, isComposable: false); getSalary.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false)); model.AddElement(getSalary); EdmFunction IsAnyUpgraded = new EdmFunction( "NS", "IsAnyUpgraded", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); EdmCollectionType edmCollectionType = new EdmCollectionType(new EdmEntityTypeReference(customer, false)); IsAnyUpgraded.AddParameter("entityset", new EdmCollectionTypeReference(edmCollectionType)); model.AddElement(IsAnyUpgraded); EdmFunction isCustomerUpgradedWithParam = new EdmFunction( "NS", "IsUpgradedWithParam", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); isCustomerUpgradedWithParam.AddParameter("entity", new EdmEntityTypeReference(customer, false)); isCustomerUpgradedWithParam.AddParameter("city", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false)); model.AddElement(isCustomerUpgradedWithParam); EdmFunction isCustomerLocal = new EdmFunction( "NS", "IsLocal", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); isCustomerLocal.AddParameter("entity", new EdmEntityTypeReference(customer, false)); model.AddElement(isCustomerLocal); EdmFunction entityFunction = new EdmFunction( "NS", "GetCustomer", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); entityFunction.AddParameter("entity", new EdmEntityTypeReference(customer, false)); entityFunction.AddParameter("customer", new EdmEntityTypeReference(customer, false)); model.AddElement(entityFunction); EdmFunction getOrder = new EdmFunction( "NS", "GetOrder", order.ToEdmTypeReference(false), isBound: true, entitySetPathExpression: null, isComposable: true); // Composable getOrder.AddParameter("entity", new EdmEntityTypeReference(customer, false)); getOrder.AddParameter("orderId", intType); model.AddElement(getOrder); // functions bound to collection EdmFunction isAllUpgraded = new EdmFunction("NS", "IsAllUpgraded", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); isAllUpgraded.AddParameter("entityset", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false)))); isAllUpgraded.AddParameter("param", intType); model.AddElement(isAllUpgraded); EdmFunction isSpecialAllUpgraded = new EdmFunction("NS", "IsSpecialAllUpgraded", returnType, isBound: true, entitySetPathExpression: null, isComposable: false); isSpecialAllUpgraded.AddParameter("entityset", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(specialCustomer, false)))); isSpecialAllUpgraded.AddParameter("param", intType); model.AddElement(isSpecialAllUpgraded); // navigation properties EdmNavigationProperty ordersNavProp = customer.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "Orders", TargetMultiplicity = EdmMultiplicity.Many, Target = order }); mary.AddNavigationTarget(ordersNavProp, orders); vipCustomer.AddNavigationTarget(ordersNavProp, orders); customers.AddNavigationTarget(ordersNavProp, orders); orders.AddNavigationTarget( order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Customer", TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Target = customer }), customers); // navigation properties on derived types. EdmNavigationProperty specialOrdersNavProp = specialCustomer.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "SpecialOrders", TargetMultiplicity = EdmMultiplicity.Many, Target = order }); vipCustomer.AddNavigationTarget(specialOrdersNavProp, orders); customers.AddNavigationTarget(specialOrdersNavProp, 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; Account = account; SpecialCustomer = specialCustomer; SpecialOrder = specialOrder; Orders = orders; Customers = customers; VipCustomer = vipCustomer; Mary = mary; RootOrder = rootOrder; OrderLine = orderLine; OrderLines = orderLines; NonContainedOrderLines = nonContainedOrderLines; UpgradeCustomer = upgrade; UpgradeSpecialCustomer = specialUpgrade; CustomerName = customerName; IsCustomerUpgraded = isCustomerUpgradedWithParam; IsSpecialCustomerUpgraded = IsSpecialUpgraded; Tag = tag; }