public static IEdmModel BuildEdmModel(ODataModelBuilder builder) { if (builder == null) { throw Error.ArgumentNull("builder"); } EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName); // add types and sets, building an index on the way. Dictionary<Type, IEdmType> edmTypeMap = model.AddTypes(builder.StructuralTypes, builder.EnumTypes); Dictionary<string, EdmEntitySet> edmEntitySetMap = model.AddEntitySets(builder, container, edmTypeMap); // add procedures model.AddProcedures(builder.Procedures, container, edmTypeMap, edmEntitySetMap); // finish up model.AddElement(container); // build the map from IEdmEntityType to IEdmFunctionImport model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model)); // set the data service version annotations. model.SetDataServiceVersion(builder.DataServiceVersion); model.SetMaxDataServiceVersion(builder.MaxDataServiceVersion); return model; }
public static IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); // Create and add product entity type. EdmEntityType product = new EdmEntityType("NS", "Product"); product.AddKeys(product.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); product.AddStructuralProperty("Price", EdmPrimitiveTypeKind.Double); model.AddElement(product); // Create and add category entity type. EdmEntityType category = new EdmEntityType("NS", "Category"); category.AddKeys(category.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); category.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); model.AddElement(category); // Set navigation from product to category. EdmNavigationPropertyInfo propertyInfo = new EdmNavigationPropertyInfo(); propertyInfo.Name = "Category"; propertyInfo.TargetMultiplicity = EdmMultiplicity.One; propertyInfo.Target = category; EdmNavigationProperty productCategory = product.AddUnidirectionalNavigation(propertyInfo); // Create and add entity container. EdmEntityContainer container = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(container); // Create and add entity set for product and category. EdmEntitySet products = container.AddEntitySet("Products", product); EdmEntitySet categories = container.AddEntitySet("Categories", category); products.AddNavigationTarget(productCategory, categories); return model; }
private static Dictionary<string, EdmEntitySet> AddEntitySets(this EdmModel model, ODataModelBuilder builder, EdmEntityContainer container, Dictionary<Type, IEdmType> edmTypeMap) { IEnumerable<EntitySetConfiguration> configurations = builder.EntitySets; // build the entitysets and their annotations IEnumerable<Tuple<EdmEntitySet, EntitySetConfiguration>> entitySets = AddEntitySets(configurations, container, edmTypeMap); var entitySetAndAnnotations = entitySets.Select(e => new { EntitySet = e.Item1, Configuration = e.Item2, Annotations = new { LinkBuilder = new EntitySetLinkBuilderAnnotation(e.Item2), Url = new EntitySetUrlAnnotation { Url = e.Item2.GetUrl() } } }).ToArray(); // index the entitySets by name Dictionary<string, EdmEntitySet> edmEntitySetMap = entitySetAndAnnotations.ToDictionary(e => e.EntitySet.Name, e => e.EntitySet); // apply the annotations foreach (var iter in entitySetAndAnnotations) { EdmEntitySet entitySet = iter.EntitySet; model.SetAnnotationValue<EntitySetUrlAnnotation>(entitySet, iter.Annotations.Url); model.SetEntitySetLinkBuilder(entitySet, iter.Annotations.LinkBuilder); AddNavigationBindings(iter.Configuration, iter.EntitySet, iter.Annotations.LinkBuilder, builder, edmTypeMap, edmEntitySetMap); } return edmEntitySetMap; }
private static ODataEntry CreateEntryWithKeyAsSegmentConvention(bool addAnnotation, bool? useKeyAsSegment) { var model = new EdmModel(); var container = new EdmEntityContainer("Fake", "Container"); model.AddElement(container); if (addAnnotation) { model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue)); } EdmEntityType entityType = new EdmEntityType("Fake", "FakeType"); entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); model.AddElement(entityType); var entitySet = new EdmEntitySet(container, "FakeSet", entityType); container.AddElement(entitySet); var metadataContext = new ODataMetadataContext( true, ODataReaderBehavior.DefaultBehavior.OperationsBoundToEntityTypeMustBeContainerQualified, new EdmTypeReaderResolver(model, ODataReaderBehavior.DefaultBehavior), model, new Uri("http://temp.org/$metadata"), null /*requestUri*/); var thing = new ODataEntry {Properties = new[] {new ODataProperty {Name = "Id", Value = 1}}}; thing.SetAnnotation(new ODataTypeAnnotation(entitySet, entityType)); thing.MetadataBuilder = metadataContext.GetEntityMetadataBuilderForReader(new TestJsonLightReaderEntryState { Entry = thing, SelectedProperties = new SelectedPropertiesNode("*")}, useKeyAsSegment); return thing; }
static ODataFeedAndEntryTypeContextTests() { Model = new EdmModel(); EntitySetElementType = new EdmEntityType("ns", "Customer"); ExpectedEntityType = new EdmEntityType("ns", "VipCustomer", EntitySetElementType); ActualEntityType = new EdmEntityType("ns", "DerivedVipCustomer", ExpectedEntityType); EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "DefaultContainer"); Model.AddElement(defaultContainer); Model.AddVocabularyAnnotation(new EdmAnnotation(defaultContainer, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue)); EntitySet = new EdmEntitySet(defaultContainer, "Customers", EntitySetElementType); Model.AddElement(EntitySetElementType); Model.AddElement(ExpectedEntityType); Model.AddElement(ActualEntityType); defaultContainer.AddElement(EntitySet); SerializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MyCustomers", NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer" }; SerializationInfoWithEdmUnknowEntitySet = new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = null, NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer", NavigationSourceKind = EdmNavigationSourceKind.UnknownEntitySet }; TypeContextWithoutModel = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true); TypeContextWithModel = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/null, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true); TypeContextWithEdmUnknowEntitySet = ODataFeedAndEntryTypeContext.Create(SerializationInfoWithEdmUnknowEntitySet, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true); BaseTypeContextThatThrows = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true); BaseTypeContextThatWillNotThrow = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: false); }
public void WriteComplexParameterWithoutTypeInformationErrorTest() { EdmModel edmModel = new EdmModel(); var container = new EdmEntityContainer("DefaultNamespace", "DefaultContainer"); edmModel.AddElement(container); var testDescriptors = new PayloadWriterTestDescriptor<ODataParameters>[] { new PayloadWriterTestDescriptor<ODataParameters>( this.Settings, new ODataParameters() { new KeyValuePair<string, object>("p1", new ODataComplexValue()) }, tc => new WriterTestExpectedResults(this.ExpectedResultSettings) { ExpectedException2 = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueSerializer_NoExpectedTypeOrTypeNameSpecifiedForComplexValueRequest") }) { DebugDescription = "Complex value without expected type or type name.", Model = edmModel }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => tc.IsRequest), (testDescriptor, testConfiguration) => { TestWriterUtils.WriteAndVerifyODataParameterPayload(testDescriptor, testConfiguration, this.Assert, this.Logger); }); }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType student = new EdmEntityType("ns", "Student"); student.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = student.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); student.AddKeys(key); model.AddElement(student); EdmEntitySet students = container.AddEntitySet("Students", student); EdmEntityType school = new EdmEntityType("ns", "School"); school.AddKeys(school.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); school.AddStructuralProperty("CreatedDay", EdmPrimitiveTypeKind.DateTimeOffset); model.AddElement(school); EdmEntitySet schools = container.AddEntitySet("Schools", student); EdmNavigationProperty schoolNavProp = student.AddUnidirectionalNavigation( new EdmNavigationPropertyInfo { Name = "School", TargetMultiplicity = EdmMultiplicity.One, Target = school }); students.AddNavigationTarget(schoolNavProp, schools); _school = school; }
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 ODataSingletonDeserializerTest() { EdmModel model = new EdmModel(); var employeeType = new EdmEntityType("NS", "Employee"); employeeType.AddStructuralProperty("EmployeeId", EdmPrimitiveTypeKind.Int32); employeeType.AddStructuralProperty("EmployeeName", EdmPrimitiveTypeKind.String); model.AddElement(employeeType); EdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "Default"); model.AddElement(defaultContainer); _singleton = new EdmSingleton(defaultContainer, "CEO", employeeType); defaultContainer.AddElement(_singleton); model.SetAnnotationValue<ClrTypeAnnotation>(employeeType, new ClrTypeAnnotation(typeof(EmployeeModel))); _edmModel = model; _edmContainer = defaultContainer; _readContext = new ODataDeserializerContext { Path = new ODataPath(new SingletonPathSegment(_singleton)), Model = _edmModel, ResourceType = typeof(EmployeeModel) }; _deserializerProvider = new DefaultODataDeserializerProvider(); }
public EdmSingletonTests() { this.entityContainer = new EdmEntityContainer(myNamespace, "Container"); this.customerType = new EdmEntityType(myNamespace, "Customer"); this.orderType = new EdmEntityType(myNamespace, "Order"); this.productType = new EdmEntityType(myNamespace, "Product"); }
public SQLDataSource(string name, string connectionString, Func<MethodType, string, bool> permissionCheck = null, string modelCommand = "GetEdmModelInfo", string funcCommand = "GetEdmSPInfo", string tvfCommand = "GetEdmTVFInfo", string relationCommand = "GetEdmRelationship", string storedProcedureResultSetCommand = "GetEdmSPResultSet", string userDefinedTableCommand = "GetEdmUDTInfo", string tableValuedResultSetCommand = "GetEdmTVFResultSet") { this.Name = name; this.ConnectionString = connectionString; this.PermissionCheck = permissionCheck; _Model = new Lazy<EdmModel>(() => { ModelCommand = modelCommand; FuncCommand = funcCommand; TableValuedCommand = tvfCommand; RelationCommand = relationCommand; StoredProcedureResultSetCommand = storedProcedureResultSetCommand; UserDefinedTableCommand = userDefinedTableCommand; TableValuedResultSetCommand = tableValuedResultSetCommand; var model = new EdmModel(); var container = new EdmEntityContainer("ns", "container"); model.AddElement(container); AddEdmElement(model); AddEdmFunction(model); AddTableValueFunction(model); BuildRelation(model); return model; }); }
public WriterTypeNameEndToEndTests() { var model = new EdmModel(); var type = new EdmEntityType("TestModel", "TestEntity", /* baseType */ null, /* isAbstract */ false, /* isOpen */ true); var keyProperty = type.AddStructuralProperty("DeclaredInt16", EdmPrimitiveTypeKind.Int16); type.AddKeys(new[] { keyProperty }); // Note: DerivedPrimitive is declared as a Geography, but its value below will be set to GeographyPoint, which is derived from Geography. type.AddStructuralProperty("DerivedPrimitive", EdmPrimitiveTypeKind.Geography); var container = new EdmEntityContainer("TestModel", "Container"); var set = container.AddEntitySet("Set", type); model.AddElement(type); model.AddElement(container); var writerStream = new MemoryStream(); this.settings = new ODataMessageWriterSettings(); this.settings.SetServiceDocumentUri(ServiceDocumentUri); // Make the message writer and entry writer lazy so that individual tests can tweak the settings before the message writer is created. this.messageWriter = new Lazy<ODataMessageWriter>(() => new ODataMessageWriter( (IODataResponseMessage)new InMemoryMessage { Stream = writerStream }, this.settings, model)); var entryWriter = new Lazy<ODataWriter>(() => this.messageWriter.Value.CreateODataEntryWriter(set, type)); var valueWithAnnotation = new ODataPrimitiveValue(45); valueWithAnnotation.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = "TypeNameFromSTNA" }); var propertiesToWrite = new List<ODataProperty> { new ODataProperty { Name = "DeclaredInt16", Value = (Int16)42 }, new ODataProperty { Name = "UndeclaredDecimal", Value = (Decimal)4.5 }, new ODataProperty { // Note: value is more derived than the declared type. Name = "DerivedPrimitive", Value = Microsoft.Spatial.GeographyPoint.Create(42, 45) }, new ODataProperty() { Name = "PropertyWithSTNA", Value = valueWithAnnotation } }; this.writerOutput = new Lazy<string>(() => { entryWriter.Value.WriteStart(new ODataEntry { Properties = propertiesToWrite }); entryWriter.Value.WriteEnd(); entryWriter.Value.Flush(); writerStream.Seek(0, SeekOrigin.Begin); return new StreamReader(writerStream).ReadToEnd(); }); }
private IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("NS", "Name"); model.AddElement(container); IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); container.AddFunctionImport(new EdmFunction("NS", "FunctionWithoutParams", returnType)); var functionWithOneParam = new EdmFunction("NS", "FunctionWithOneParam", returnType); functionWithOneParam.AddParameter("Parameter", parameterType); container.AddFunctionImport(functionWithOneParam); var functionWithMultipleParams = new EdmFunction("NS", "FunctionWithMultipleParams", returnType); functionWithMultipleParams.AddParameter("Parameter1", parameterType); functionWithMultipleParams.AddParameter("Parameter2", parameterType); functionWithMultipleParams.AddParameter("Parameter3", parameterType); container.AddFunctionImport(functionWithMultipleParams); container.AddFunctionImport(new EdmFunction("NS", "FunctionWithOverloads", returnType)); var functionWithOverloads2 = new EdmFunction("NS", "FunctionWithOverloads", returnType); functionWithOverloads2.AddParameter("Parameter", parameterType); container.AddFunctionImport(functionWithOverloads2); var functionWithOverloads3 = new EdmFunction("NS", "FunctionWithOverloads", returnType); functionWithOverloads3.AddParameter("Parameter1", parameterType); functionWithOverloads3.AddParameter("Parameter2", parameterType); functionWithOverloads3.AddParameter("Parameter3", parameterType); container.AddFunctionImport(functionWithOverloads3); return model; }
public OperationImportSegmentUnitTests() { nullableIntType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), true); nullableDecimalType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Decimal), true); nullableBinaryType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Binary), true); nullableStringType = new EdmPrimitiveTypeReference(EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.String), true); container = ModelBuildingHelpers.BuildValidEntityContainer(); model = new EdmModel(); model.AddElement(container); this.functionIntToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType); this.functionIntToInt.AddParameter("Parameter1", this.nullableIntType); this.functionImportIntToInt = new EdmFunctionImport(this.container, "Function", this.functionIntToInt); this.functionDecimalToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType); this.functionDecimalToInt.AddParameter("Parameter1", this.nullableDecimalType); this.functionImportDecimalToInt = new EdmFunctionImport(this.container, "Function", this.functionDecimalToInt); this.functionBinaryToInt = new EdmFunction("Name.Space", "Function", this.nullableIntType); this.functionBinaryToInt.AddParameter("Parameter1", this.nullableBinaryType); this.functionImportBinaryToInt = new EdmFunctionImport(this.container, "Function", this.functionBinaryToInt); this.functionIntToString = new EdmFunction("Name.Space", "Function", this.nullableStringType); this.functionIntToString.AddParameter("Parameter1", this.nullableIntType); this.functionImportIntToString = new EdmFunctionImport(this.container, "Function", this.functionIntToString); model.AddElement(functionIntToInt); model.AddElement(functionDecimalToInt); model.AddElement(functionBinaryToInt); model.AddElement(functionIntToString); }
public void Ctor_InitializeParameterMappingsProperty_UnboundFunction() { // Arrange IEdmModel model = new Mock<IEdmModel>().Object; IEdmEntityType returnType = new Mock<IEdmEntityType>().Object; EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmFunctionImport function = new EdmFunctionImport( container, "Function", new EdmFunction( "NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false))); Dictionary<string, string> parameterMappings = new Dictionary<string, string> { { "Parameter1", "{param1}" }, { "Parameter2", "{param2}" } }; // Act var template = new UnboundFunctionPathSegmentTemplate( new UnboundFunctionPathSegment(function, model, parameterMappings)); // Assert Assert.Equal(2, template.ParameterMappings.Count); }
public static IEdmModel GetEdmModel() { if (_edmModel != null) { return _edmModel; } EdmModel model = new EdmModel(); // entity type 'Customer' with single alternate keys EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); var ssn = customer.AddStructuralProperty("SSN", EdmPrimitiveTypeKind.String); model.AddAlternateKeyAnnotation(customer, new Dictionary<string, IEdmProperty> { {"SSN", ssn} }); model.AddElement(customer); // entity type 'Order' with multiple alternate keys EdmEntityType order = new EdmEntityType("NS", "Order"); order.AddKeys(order.AddStructuralProperty("OrderId", EdmPrimitiveTypeKind.Int32)); var orderName = order.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); var orderToken = order.AddStructuralProperty("Token", EdmPrimitiveTypeKind.Guid); order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32); model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty> { {"Name", orderName} }); model.AddAlternateKeyAnnotation(order, new Dictionary<string, IEdmProperty> { {"Token", orderToken} }); model.AddElement(order); // entity type 'Person' with composed alternate keys EdmEntityType person = new EdmEntityType("NS", "Person"); person.AddKeys(person.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); var country = person.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String); var passport = person.AddStructuralProperty("Passport", EdmPrimitiveTypeKind.String); model.AddAlternateKeyAnnotation(person, new Dictionary<string, IEdmProperty> { {"Country", country}, {"Passport", passport} }); model.AddElement(person); // entity sets EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); model.AddElement(container); container.AddEntitySet("Customers", customer); container.AddEntitySet("Orders", order); container.AddEntitySet("People", person); return _edmModel = model; }
public void UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationHasWrongValue() { var container = new EdmEntityContainer("Fake", "Container"); var model = new EdmModel(); model.AddElement(container); model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, new EdmStringConstant("fake"))); UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeFalse(); }
public void UrlConventionFromAnnotationShouldReturnKeyAsSegmentIfAnnotationFound() { var container = new EdmEntityContainer("Fake", "Container"); var model = new EdmModel(); model.AddElement(container); model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue)); UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeTrue(); }
public void UrlConventionFromAnnotationShouldReturnDefaultIfAnnotationMissing() { var container = new EdmEntityContainer("Fake", "Container"); var model = new EdmModel(); model.AddElement(container); model.AddVocabularyAnnotation(new EdmAnnotation(container, new EdmTerm("Fake", "Fake", EdmPrimitiveTypeKind.Stream), EdmNullExpression.Instance)); UrlConvention.ForModel(model).GenerateKeyAsSegment.Should().BeFalse(); }
public void GetModel(EdmModel model, EdmEntityContainer container) { EdmEntityType product = new EdmEntityType("ns", "Student"); product.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String); EdmStructuralProperty key = product.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); product.AddKeys(key); model.AddElement(product); container.AddEntitySet("Students", product); }
public void TestEntityType() { var container = new EdmEntityContainer("NS", "C"); var entityType = new EdmEntityType("NS", "People"); var entitySet = new EdmEntitySet(container, "Peoples", entityType); Assert.AreEqual(entityType, entitySet.EntityType()); var singleton = new EdmSingleton(container, "Boss", entityType); Assert.AreEqual(entityType, singleton.EntityType()); }
public void GetEntitySetLinkBuilder_ReturnsDefaultEntitySetBuilder_IfNotSet() { IEdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmEntityType entityType = new EdmEntityType("NS", "Entity"); IEdmEntitySet entitySet = new EdmEntitySet(container, "EntitySet", entityType); Assert.NotNull(model.GetEntitySetLinkBuilder(entitySet)); }
public void GetActionLinkBuilder_ReturnsDefaultActionLinkBuilder_IfNotSet() { // Arrange IEdmModel model = new EdmModel(); IEdmEntityContainer container = new EdmEntityContainer("NS", "Container"); IEdmAction action = new EdmAction("NS", "Action", returnType: null); Assert.NotNull(model.GetActionLinkBuilder(action)); }
public static IEdmModel CreateModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer"); model.AddElement(defaultContainer); var addressType = new EdmComplexType(ns, "Address"); addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", EdmCoreModel.Instance.GetString(false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false))); model.AddElement(addressType); var personType = new EdmEntityType(ns, "Person"); var personIdProperty = new EdmStructuralProperty(personType, "PersonId", EdmCoreModel.Instance.GetInt32(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, "Address", new EdmComplexTypeReference(addressType, true))); personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false))))); model.AddElement(personType); var peopleSet = new EdmEntitySet(defaultContainer, "People", personType); defaultContainer.AddElement(peopleSet); var numberComboType = new EdmComplexType(ns, "NumberCombo"); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", EdmCoreModel.Instance.GetInt32(false))); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", EdmCoreModel.Instance.GetInt64(false))); numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", EdmCoreModel.Instance.GetDecimal(false))); model.AddElement(numberComboType); var productType = new EdmEntityType(ns, "Product"); var productIdProperty = new EdmStructuralProperty(productType, "ProductId", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(productIdProperty); productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty }); productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", EdmCoreModel.Instance.GetInt64(false))); productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", EdmCoreModel.Instance.GetDecimal(false))); productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true))); productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDecimal(false))))); model.AddElement(productType); var productsSet = new EdmEntitySet(defaultContainer, "Products", productType); defaultContainer.AddElement(productsSet); var productsProperty = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Products", Target = productType, TargetMultiplicity = EdmMultiplicity.Many }); peopleSet.AddNavigationTarget(productsProperty, productsSet); IEnumerable<EdmError> errors; model.Validate(out errors); return model; }
public static IEdmModel CreateServiceEdmModel(string ns) { EdmModel model = new EdmModel(); var defaultContainer = new EdmEntityContainer(ns, "PerfInMemoryContainer"); model.AddElement(defaultContainer); var personType = new EdmEntityType(ns, "Person"); var personIdProperty = new EdmStructuralProperty(personType, "PersonID", EdmCoreModel.Instance.GetInt32(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, "MiddleName", EdmCoreModel.Instance.GetString(true))); personType.AddProperty(new EdmStructuralProperty(personType, "Age", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(personType); var simplePersonSet = new EdmEntitySet(defaultContainer, "SimplePeopleSet", personType); defaultContainer.AddElement(simplePersonSet); var largetPersonSet = new EdmEntitySet(defaultContainer, "LargePeopleSet", personType); defaultContainer.AddElement(largetPersonSet); var addressType = new EdmComplexType(ns, "Address"); addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false))); addressType.AddProperty(new EdmStructuralProperty(addressType, "PostalCode", EdmCoreModel.Instance.GetString(false))); model.AddElement(addressType); var companyType = new EdmEntityType(ns, "Company"); var companyId = new EdmStructuralProperty(companyType, "CompanyID", EdmCoreModel.Instance.GetInt32(false)); companyType.AddProperty(companyId); companyType.AddKeys(companyId); companyType.AddProperty(new EdmStructuralProperty(companyType, "Name", EdmCoreModel.Instance.GetString(true))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Address", new EdmComplexTypeReference(addressType, true))); companyType.AddProperty(new EdmStructuralProperty(companyType, "Revenue", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(companyType); var companySet = new EdmEntitySet(defaultContainer, "CompanySet", companyType); defaultContainer.AddElement(companySet); var companyEmployeeNavigation = companyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Employees", Target = personType, TargetMultiplicity = EdmMultiplicity.Many }); companySet.AddNavigationTarget(companyEmployeeNavigation, largetPersonSet); // ResetDataSource var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null); model.AddElement(resetDataSourceAction); defaultContainer.AddActionImport(resetDataSourceAction); return model; }
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); }
private void BuildEntitySets(EdmEntityContainer container, IEnumerable<EntityElement> rootElements, TypeBuilder typeBuilder) { foreach (var rootEntity in rootElements) { var entitySetName = rootEntity.EntitySetName ?? rootEntity.ResolveName(); var schemaType = typeBuilder.BuildSchemaType(rootEntity); container.AddEntitySet(entitySetName, (IEdmEntityType)schemaType); } }
public void EnsureActionImportIsAddedWithActionSuppliedName() { EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmAction action = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false)); var actionImport = container.AddActionImport(action); actionImport.Action.Should().Be(action); actionImport.Name.Should().Be(action.Name); container.Elements.ToArray()[0].Should().Be(actionImport); }
public static IEdmModel GetEdmModel(string dataSourceName) { EdmModel model = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("ns", "container"); model.AddElement(container); GetDataSource(dataSourceName).GetModel(model, container); return model; }
public void EnsureFunctionImportIsAddedAndWithCorrectSuppliedName() { EdmEntityContainer container = new EdmEntityContainer("Default", "Container"); EdmFunction function = new EdmFunction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false)); var functionImport = container.AddFunctionImport("OtherName", function); functionImport.Function.Should().Be(function); functionImport.Name.Should().Be("OtherName"); container.Elements.ToArray()[0].Should().Be(functionImport); }