public void CreateOperationForEdmFunctionImportReturnsCorrectOperationId(bool enableOperationId) { // Arrange EdmModel model = new EdmModel(); EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); model.AddElement(customer); EdmFunction function = new EdmFunction("NS", "MyFunction", EdmCoreModel.Instance.GetString(false), false, null, false); function.AddParameter("entity", new EdmEntityTypeReference(customer, false)); function.AddParameter("param", EdmCoreModel.Instance.GetString(false)); model.AddElement(function); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmFunctionImport functionImport = new EdmFunctionImport(container, "MyFunction", function); model.AddElement(container); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableOperationId = enableOperationId }; ODataContext context = new ODataContext(model, settings); ODataPath path = new ODataPath(new ODataOperationImportSegment(functionImport)); // Act var operation = _operationHandler.CreateOperation(context, path); // Assert Assert.NotNull(operation); if (enableOperationId) { Assert.Equal("OperationImport.MyFunction.a5ea52712c5e17e3bd081e4f", operation.OperationId); } else { Assert.Null(operation.OperationId); } }
private static IEdmModel CreateModel() { var model = new EdmModel(); var orderType = new EdmEntityType("Default", "Order"); orderType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); model.AddElement(orderType); var customerType = new EdmEntityType("Default", "Customer"); customerType.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32); model.AddElement(customerType); // Add navigations orderType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Customer", Target = customerType, TargetMultiplicity = EdmMultiplicity.One }); var container = new EdmEntityContainer("Default", "Container"); var orderSet = container.AddEntitySet("Orders", orderType); var customerSet = container.AddEntitySet("Customers", customerType); container.AddFunctionImport( new EdmFunction( "Default", "GetIDs", new EdmCollectionTypeReference( new EdmCollectionType( new EdmPrimitiveTypeReference( EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32), isNullable: false))))); orderSet.AddNavigationTarget(orderType.NavigationProperties().Single(np => np.Name == "Customer"), customerSet); model.AddElement(container); return(model); }
EdmEntityTypeWrapper AddTable(EdmModel model, TableData dataBuilder) { var propertyMap = new Dictionary <Field, EdmStructuralProperty>(); var table = new EdmEntityType("sitecore.com", dataBuilder.Name); foreach (var field in dataBuilder.Schema.Fields) { var prop = table.AddStructuralProperty(field.Name, GetEdmType(field.ValueType), IsNullable(field.ValueType)); if (field.FieldType == FieldType.Key) { table.AddKeys(prop); } propertyMap.Add(field, prop); } model.AddElement(table); return(new EdmEntityTypeWrapper { Type = table, Properties = propertyMap }); }
public static EdmModel AnnotationWithSchemaTagValueModel() { EdmModel model = new EdmModel(); EdmEntityType simpleType = new EdmEntityType("DefaultNamespace", "SimpleType"); EdmStructuralProperty simpleTypeId = simpleType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false)); simpleType.AddKeys(simpleTypeId); model.AddElement(simpleType); XElement annotationElement = new XElement("{http://foo}Annotation", "</Schema>" ); var annotation = new EdmStringConstant(EdmCoreModel.Instance.GetString(false), annotationElement.ToString()); annotation.SetIsSerializedAsElement(model, true); model.SetAnnotationValue(simpleType, "http://foo", "Annotation", annotation); return(model); }
public void GetFirstNonTypeCastSegment_WorksForSelectPathWithFirstNonTypeSegmentAtBegin() { // Arrange EdmEntityType entityType = new EdmEntityType("NS", "Customer"); IEdmStructuralProperty property = entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String); ODataPathSegment firstPropertySegment = new PropertySegment(property); ODataPathSegment secondPropertySegment = new PropertySegment(property); ODataSelectPath selectPath = new ODataSelectPath(firstPropertySegment, secondPropertySegment); // Act IList <ODataPathSegment> remainingSegments; ODataPathSegment firstNonTypeSegment = selectPath.GetFirstNonTypeCastSegment(out remainingSegments); // Assert Assert.NotNull(firstNonTypeSegment); Assert.Same(firstPropertySegment, firstNonTypeSegment); Assert.NotNull(remainingSegments); Assert.Same(secondPropertySegment, Assert.Single(remainingSegments)); }
public void TryMatchMediaType_MatchRequest_WithPrimitiveRawValueRequest() { // Arrange EdmEnumType colorType = new EdmEnumType("NS", "Color"); EdmEntityType entity = new EdmEntityType("NS", "Entity"); EdmStructuralProperty property = entity.AddStructuralProperty("Color", new EdmEnumTypeReference(colorType, false)); PropertySegment propertySegment = new PropertySegment(property); ValueSegment valueSegment = new ValueSegment(property.Type.Definition); HttpRequest request = new DefaultHttpContext().Request; request.ODataFeature().Path = new ODataPath(propertySegment, valueSegment); // Act double mapResult = Mapping.TryMatchMediaType(request); // Assert Assert.Equal(1.0, mapResult); }
public void ODataPathSegmentToTemplateHandler_Handles_Key_AfterNavigationProperty() { // Arrange ODataPathSegmentToTemplateHandler handler = new ODataPathSegmentToTemplateHandler(null); EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); EdmEntityType order = new EdmEntityType("NS", "order"); order.AddKeys(order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many }); NavigationPropertyLinkSegment segment1 = new NavigationPropertyLinkSegment(ordersNavProperty, null); EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default"); EdmEntitySet orders = entityContainer.AddEntitySet("Orders", order); IDictionary <string, object> keys = new Dictionary <string, object> { { "Id", "{relatedKey}" } }; KeySegment segment2 = new KeySegment(keys, order, orders); // Act handler.Handle(segment1); handler.Handle(segment2); // Assert ODataSegmentTemplate segmentTemplate = Assert.Single(handler.Templates); NavigationLinkSegmentTemplate nlTemplate = Assert.IsType <NavigationLinkSegmentTemplate>(segmentTemplate); Assert.NotNull(nlTemplate.Key); }
public void TranslateODataPathTemplate_ToODataPath() { // Assert EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("CustomerId", EdmPrimitiveTypeKind.Int32)); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); var entitySet = container.AddEntitySet("Customers", customer); EdmModel model = new EdmModel(); model.AddElement(customer); model.AddElement(container); ODataPathTemplate template = new ODataPathTemplate( new EntitySetSegmentTemplate(entitySet), KeySegmentTemplate.CreateKeySegment(customer, entitySet)); DefaultODataTemplateTranslator translator = new DefaultODataTemplateTranslator(); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext { RouteValues = new RouteValueDictionary(new { key = "42" }), Model = model }; // Act ODataPath path = translator.Translate(template, context); // Assert Assert.NotNull(path); Assert.Equal(2, path.Count); EntitySetSegment entitySetSegment = Assert.IsType <EntitySetSegment>(path.FirstSegment); Assert.Equal("Customers", entitySetSegment.EntitySet.Name); KeySegment keySegment = Assert.IsType <KeySegment>(path.LastSegment); KeyValuePair <string, object> key = Assert.Single(keySegment.Keys); Assert.Equal("CustomerId", key.Key); Assert.Equal(42, key.Value); }
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); }
private static IEdmModel GetDerivedModel() { var model = new EdmModel(); var entityType = new EdmEntityType("NS", "EntityType"); var id = entityType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); entityType.AddKeys(id); var derivedEntityType = new EdmEntityType("NS", "DerivedEntityType", entityType); var navEntityType = new EdmEntityType("NS", "NavEntityType"); var navEntityId = navEntityType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetString(false)); navEntityType.AddKeys(navEntityId); var nav = derivedEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Nav", Target = navEntityType, TargetMultiplicity = EdmMultiplicity.Many, }); model.AddElement(entityType); model.AddElement(derivedEntityType); model.AddElement(navEntityType); var entityContainer = new EdmEntityContainer("NS", "Container"); model.AddElement(entityContainer); var entitySet = new EdmEntitySet(entityContainer, "EntitySet", entityType); var navEntitySet = new EdmEntitySet(entityContainer, "NavEntitySet", navEntityType); entitySet.AddNavigationTarget(nav, navEntitySet); entityContainer.AddElement(entitySet); entityContainer.AddElement(navEntitySet); return(model); }
public void GetTemplatesWorksForPathWithTypeCastAndFunction() { // Arrange EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); // VipCustomer EdmEntityType vipCustomer = new EdmEntityType("NS", "VipCustomer", customer); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); var entitySet = container.AddEntitySet("Customers", customer); // function with optional parameters EdmFunction getSalaray = new EdmFunction("NS", "GetWholeSalary", IntType, isBound: true, entitySetPathExpression: null, isComposable: false); getSalaray.AddParameter("entityset", new EdmEntityTypeReference(vipCustomer, false)); getSalaray.AddParameter("salary", IntType); getSalaray.AddOptionalParameter("minSalary", IntType); getSalaray.AddOptionalParameter("maxSalary", IntType, "129"); ODataPathTemplate template = new ODataPathTemplate( new EntitySetSegmentTemplate(entitySet), KeySegmentTemplate.CreateKeySegment(customer, entitySet), new CastSegmentTemplate(vipCustomer, customer, entitySet), new FunctionSegmentTemplate(getSalaray, null)); // Act IEnumerable <string> actual = template.GetTemplates(); Assert.Equal(4, actual.Count()); Assert.Equal(new[] { "Customers({key})/NS.VipCustomer/NS.GetWholeSalary(salary={salary},minSalary={minSalary},maxSalary={maxSalary})", "Customers({key})/NS.VipCustomer/GetWholeSalary(salary={salary},minSalary={minSalary},maxSalary={maxSalary})", "Customers/{key}/NS.VipCustomer/NS.GetWholeSalary(salary={salary},minSalary={minSalary},maxSalary={maxSalary})", "Customers/{key}/NS.VipCustomer/GetWholeSalary(salary={salary},minSalary={minSalary},maxSalary={maxSalary})", }, actual); }
public void TryTranslateKeySegmentTemplate_ThrowsODataException_ForInvalidKey() { // Arrange EdmModel model = new EdmModel(); EdmEntityType customerType = new EdmEntityType("NS", "Customer"); EdmStructuralProperty idProperty = customerType.AddStructuralProperty("customerId", EdmPrimitiveTypeKind.Int32); customerType.AddKeys(idProperty); model.AddElement(customerType); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmEntitySet customers = container.AddEntitySet("Customers", customerType); model.AddElement(container); RouteValueDictionary routeValueDictionary = new RouteValueDictionary(new { key = "abc12" }); IDictionary <string, string> keys = new Dictionary <string, string> { { "customerId", "{key}" } }; KeySegmentTemplate template = new KeySegmentTemplate(keys, customerType, customers); RouteEndpoint endpoint = new RouteEndpoint( c => Task.CompletedTask, RoutePatternFactory.Parse("odata/customers/{key}/Name"), 0, EndpointMetadataCollection.Empty, "test"); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext { RouteValues = routeValueDictionary, Model = model, Endpoint = endpoint }; // Act Action test = () => template.TryTranslate(context); // Assert ExceptionAssert.Throws <ODataException>(test, "The key value (abc12) from request is not valid. The key value should be format of type 'Edm.Int32'."); }
/// <summary> /// Creates a test model with one singleton and one collection navigation property. /// </summary> /// <returns>The new model.</returns> private static EdmModel CreateModelWithNavProps() { var model = new EdmModel(); var Order = new EdmEntityType("TestModel", "Order"); Order.AddKeys(Order.AddStructuralProperty("OrderId", EdmCoreModel.Instance.GetInt32(false))); model.AddElement(Order); var CustomerInfo = new EdmEntityType("TestModel", "CustomerInfo"); CustomerInfo.AddKeys(CustomerInfo.AddStructuralProperty("CustomerInfoId", EdmCoreModel.Instance.GetInt32(false))); CustomerInfo.AddStructuralProperty("Information", EdmCoreModel.Instance.GetString(true)); model.AddElement(CustomerInfo); var Customer = new EdmEntityType("TestModel", "Customer"); Customer.AddKeys(Customer.AddStructuralProperty("CustomerId", EdmCoreModel.Instance.GetInt32(false))); Customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Orders", Target = Order, TargetMultiplicity = EdmMultiplicity.Many, }); Customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Name = "Info", Target = CustomerInfo, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, }); model.AddElement(Customer); var container = new EdmEntityContainer("TestModel", "DefaultContainer"); container.AddEntitySet("Customer", Customer); container.AddEntitySet("CustomerInfo", CustomerInfo); container.AddEntitySet("Order", Order); model.AddElement(container); return(model); }
private ODataAsynchronousWriter TestInit() { this.userModel = new EdmModel(); testType = new EdmEntityType("NS", "Test"); testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); this.userModel.AddElement(testType); var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer"); this.userModel.AddElement(defaultContainer); this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.testType); defaultContainer.AddElement(this.singleton); responseStream = new MemoryStream(); responseMessage = new InMemoryMessage { Stream = responseStream }; messageWriter = new ODataMessageWriter(responseMessage); return(messageWriter.CreateODataAsynchronousWriter()); }
public ODataPathTests() { // Single key entity type EdmEntityType entityType = new EdmEntityType("NS", "Order"); entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); _simpleKeyEntityType = entityType; EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmEntitySet entitySet = new EdmEntitySet(container, "Orders", entityType); _simpleKeyEntitySet = entitySet; // Multiple keys entity type entityType = new EdmEntityType("NS", "Customer"); entityType.AddKeys(entityType.AddStructuralProperty("FirstName", EdmPrimitiveTypeKind.String), entityType.AddStructuralProperty("LastName", EdmPrimitiveTypeKind.String)); _compositeKeyEntityType = entityType; entitySet = new EdmEntitySet(container, "Customers", entityType); _compositeKeyEntitySet = entitySet; }
private static IEdmModel GetEdmModel() { EdmModel model = new EdmModel(); // Customer EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); model.AddElement(customer); // VipCustomer EdmEntityType vipCustomer = new EdmEntityType("NS", "VipCustomer", customer); model.AddElement(vipCustomer); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); container.AddEntitySet("Customers", customer); container.AddEntitySet("AnotherCustomers", customer); model.AddElement(container); return(model); }
public void GenerateFunctionTemplatesWorksForEdmFunctionWithoutOptionalParameters(bool bound, string[] expects) { // Arrange EdmFunction getSalaray = new EdmFunction("NS", "GetWholeSalary", IntType, isBound: bound, entitySetPathExpression: null, isComposable: false); if (bound) { EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); getSalaray.AddParameter("entityset", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false)))); } getSalaray.AddParameter("minSalary", IntType); getSalaray.AddParameter("maxSalary", IntType); // Act IList <string> items = getSalaray.GenerateFunctionTemplates(); // Assert Assert.Equal(expects.Length, items.Count); Assert.Equal(expects, items); }
static NavigationLinkTemplateSegmentTemplateTests() { EdmModel model = new EdmModel(); // Employee type EdmEntityType employee = new EdmEntityType("NS", "Employee"); EdmStructuralProperty idProperty = employee.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); employee.AddKeys(idProperty); model.AddElement(employee); _employeeType = employee; // Entity container EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); model.AddElement(container); // Navigation property _directReportsNav = employee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DirectReports", Target = employee, TargetMultiplicity = EdmMultiplicity.Many }); EdmEntitySet employees = container.AddEntitySet("Employees", employee); employees.AddNavigationTarget(_directReportsNav, employees); _subordinatesNav = employee.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Subordinates", Target = employee, TargetMultiplicity = EdmMultiplicity.Many }); employees.AddNavigationTarget(_subordinatesNav, employees); _entitySet = employees; _model = model; }
public void GetTemplatesWorksForODataPathWithDollarRefOnCollectionNavigation() { // Arrange EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); var entitySet = container.AddEntitySet("Customers", customer); var navigation = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { TargetMultiplicity = EdmMultiplicity.Many, Name = "SubCustomers", Target = customer }); KeyValuePair <string, object>[] keys = new KeyValuePair <string, object>[] { new KeyValuePair <string, object>("Id", "{nextKey}") }; KeySegment keySegment = new KeySegment(keys, customer, entitySet); ODataPathTemplate template = new ODataPathTemplate( new EntitySetSegmentTemplate(entitySet), KeySegmentTemplate.CreateKeySegment(customer, entitySet), new NavigationLinkSegmentTemplate(navigation, entitySet), new KeySegmentTemplate(keySegment)); // Act IEnumerable <(string, string)> actual = template.GetTemplates(); // Assert Assert.Equal(4, actual.Count()); Assert.Equal(new[] { "Customers({key})/SubCustomers({nextKey})/$ref", "Customers({key})/SubCustomers/{nextKey}/$ref", "Customers/{key}/SubCustomers({nextKey})/$ref", "Customers/{key}/SubCustomers/{nextKey}/$ref" }, actual.Select(a => a.Item1)); }
public void BuildKeyMappingsKeySegmentTemplate_ReturnsKeyMapping_NormalStringTemplate() { // Arrange EdmEntityType customerType = new EdmEntityType("NS", "Customer"); EdmStructuralProperty idProperty = customerType.AddStructuralProperty("customerId", EdmPrimitiveTypeKind.Int32); customerType.AddKeys(idProperty); IDictionary <string, object> keys = new Dictionary <string, object> { { "customerId", "{youkey}" } }; // Act IDictionary <string, string> mapped = KeySegmentTemplate.BuildKeyMappings(keys, customerType); // Assert Assert.NotNull(mapped); KeyValuePair <string, string> actual = Assert.Single(mapped); Assert.Equal("customerId", actual.Key); Assert.Equal("youkey", actual.Value); }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, IEnumerable <string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) { _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString, property.ConcurrencyMode); } } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties, Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : null, TargetMultiplicity = property.Partner != null ? property.Partner.Multiplicity() : property.Type.TypeKind() == EdmTypeKind.Collection ? EdmMultiplicity.Many : EdmMultiplicity.Unknown, }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
public void BuildKeyMappings_ReturnsKeyMapping_UriTemplateExpression() { // Arrange EdmEntityType customerType = new EdmEntityType("NS", "Customer"); EdmStructuralProperty idProperty = customerType.AddStructuralProperty("customerId", EdmPrimitiveTypeKind.Int32); customerType.AddKeys(idProperty); // The properties of UriTemplateExpression are internal set. // We use the reflect to set the value. PropertyInfo literalText = typeof(UriTemplateExpression).GetProperty("LiteralText"); Assert.NotNull(literalText); PropertyInfo expectedType = typeof(UriTemplateExpression).GetProperty("ExpectedType"); Assert.NotNull(expectedType); UriTemplateExpression tempateExpression = new UriTemplateExpression(); literalText.SetValue(tempateExpression, "{yourId}"); expectedType.SetValue(tempateExpression, idProperty.Type); IDictionary <string, object> keys = new Dictionary <string, object> { { "customerId", tempateExpression } }; // Arrange IDictionary <string, string> mapped = KeySegmentTemplate.BuildKeyMappings(keys, customerType); // Assert Assert.NotNull(mapped); KeyValuePair <string, string> actual = Assert.Single(mapped); Assert.Equal("customerId", actual.Key); Assert.Equal("yourId", actual.Value); }
public static IEdmModel MultipleSchemasWithDifferentNamespacesEdm() { var namespaces = new string[] { "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.first", "FindMethodsTestModelBuilder.MultipleSchemasWithDifferentNamespaces.second" }; var model = new EdmModel(); foreach (var namespaceName in namespaces) { var entityType1 = new EdmEntityType(namespaceName, "validEntityType1"); entityType1.AddKeys(entityType1.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var entityType2 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE2"); entityType2.AddKeys(entityType2.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var entityType3 = new EdmEntityType(namespaceName, "VALIDeNTITYtYPE3"); entityType3.AddKeys(entityType3.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); entityType1.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Mumble", Target = entityType2, TargetMultiplicity = EdmMultiplicity.Many }); var complexType = new EdmComplexType(namespaceName, "ValidNameComplexType1"); complexType.AddStructuralProperty("aPropertyOne", new EdmComplexTypeReference(complexType, false)); model.AddElements(new IEdmSchemaElement[] { entityType1, entityType2, entityType3, complexType }); var function1 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); var function2 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); function2.AddParameter("param1", new EdmEntityTypeReference(entityType1, false)); var function3 = new EdmFunction(namespaceName, "ValidFunction1", EdmCoreModel.Instance.GetSingle(false)); function3.AddParameter("param1", EdmCoreModel.Instance.GetSingle(false)); model.AddElements(new IEdmSchemaElement[] { function1, function2, function3 }); } return(model); }
public void ODataPathSegmentHandler_Handles_KeySegment_AfterNavigationProperty() { // Arrange ODataPathSegmentHandler handler = new ODataPathSegmentHandler(); EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); EdmEntityType order = new EdmEntityType("NS", "order"); order.AddKeys(order.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); IEdmNavigationProperty ordersNavProperty = customer.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Orders", Target = order, TargetMultiplicity = EdmMultiplicity.Many }); NavigationPropertyLinkSegment segment1 = new NavigationPropertyLinkSegment(ordersNavProperty, null); EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default"); EdmEntitySet orders = entityContainer.AddEntitySet("Orders", order); IDictionary <string, object> keys = new Dictionary <string, object> { { "Id", 42 } }; KeySegment segment2 = new KeySegment(keys, order, orders); // Act handler.Handle(segment1); handler.Handle(segment2); // Assert Assert.Equal("Orders(42)/$ref", handler.PathLiteral); Assert.Same(orders, handler.NavigationSource); }
private static void EdmWriteAnnotationDemo() { Console.WriteLine("EdmWriteAnnotationDemo"); var model = new EdmModel(); var mail = new EdmEntityType("ns", "Mail"); model.AddElement(mail); mail.AddKeys(mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var person = new EdmEntityType("ns", "Person"); model.AddElement(person); person.AddKeys(person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32)); var mails = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Mails", TargetMultiplicity = EdmMultiplicity.Many, Target = mail, }); var ann1 = new EdmAnnotation(mails, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test1")); ann1.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline); model.AddVocabularyAnnotation(ann1); var container = new EdmEntityContainer("ns", "container"); model.AddElement(container); var people = container.AddEntitySet("People", person); var ann2 = new EdmAnnotation(people, CoreVocabularyModel.DescriptionTerm, new EdmStringConstant("test2")); model.AddVocabularyAnnotation(ann2); ShowModel(model); }
public EdmDeltaModel(IEdmModel source, IEdmEntityType entityType, ICollection <string> propertyNames) { _source = source; _entityType = new EdmEntityType(entityType.Namespace, entityType.Name, null, entityType.IsAbstract, entityType.IsOpen, entityType.HasStream); foreach (var property in entityType.StructuralProperties()) { if (propertyNames.Contains(property.Name)) { _entityType.AddStructuralProperty(property.Name, property.Type, property.DefaultValueString); } } foreach (var property in entityType.NavigationProperties()) { if (propertyNames.Contains(property.Name)) { var navInfo = new EdmNavigationPropertyInfo() { ContainsTarget = property.ContainsTarget, DependentProperties = property.DependentProperties(), PrincipalProperties = property.PrincipalProperties(), Name = property.Name, OnDelete = property.OnDelete, Target = property.Partner != null ? property.Partner.DeclaringEntityType() : property.Type.TypeKind() == EdmTypeKind.Collection ? (property.Type.Definition as IEdmCollectionType).ElementType.Definition as IEdmEntityType : property.Type.TypeKind() == EdmTypeKind.Entity ? property.Type.Definition as IEdmEntityType : null, TargetMultiplicity = property.TargetMultiplicity(), }; _entityType.AddUnidirectionalNavigation(navInfo); } } }
private static IEdmModel BuildEdmModel() { var entityType = new EdmEntityType("Squidex", "Asset"); void AddProperty(string name, EdmPrimitiveTypeKind type) { entityType.AddStructuralProperty(name.ToCamelCase(), type); } AddProperty(nameof(IAssetEntity.Id), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.Created), EdmPrimitiveTypeKind.DateTimeOffset); AddProperty(nameof(IAssetEntity.CreatedBy), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.LastModified), EdmPrimitiveTypeKind.DateTimeOffset); AddProperty(nameof(IAssetEntity.LastModifiedBy), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.Version), EdmPrimitiveTypeKind.Int64); AddProperty(nameof(IAssetEntity.FileName), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.FileHash), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.FileSize), EdmPrimitiveTypeKind.Int64); AddProperty(nameof(IAssetEntity.FileVersion), EdmPrimitiveTypeKind.Int64); AddProperty(nameof(IAssetEntity.IsImage), EdmPrimitiveTypeKind.Boolean); AddProperty(nameof(IAssetEntity.MimeType), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.PixelHeight), EdmPrimitiveTypeKind.Int32); AddProperty(nameof(IAssetEntity.PixelWidth), EdmPrimitiveTypeKind.Int32); AddProperty(nameof(IAssetEntity.Slug), EdmPrimitiveTypeKind.String); AddProperty(nameof(IAssetEntity.Tags), EdmPrimitiveTypeKind.String); var container = new EdmEntityContainer("Squidex", "Container"); container.AddEntitySet("AssetSet", entityType); var model = new EdmModel(); model.AddElement(container); model.AddElement(entityType); return(model); }
public void ToDictionary_ContainsAllProperties_FromContainer() { // Arrange EdmModel model = new EdmModel(); EdmEntityType entityType = new EdmEntityType("NS", "Name"); model.AddElement(entityType); model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity))); entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32); MockPropertyContainer container = new MockPropertyContainer(); container.Properties.Add("Property", 42); SelectExpandWrapper <TestEntity> wrapper = new SelectExpandWrapper <TestEntity> { Container = container, Model = model }; // Act var result = wrapper.ToDictionary(); // Assert Assert.Equal(42, result["Property"]); }
public void ToDictionary_ContainsAllStructuralProperties_IfInstanceIsNotNull() { // Arrange EdmModel model = new EdmModel(); EdmEntityType entityType = new EdmEntityType("NS", "Name"); model.AddElement(entityType); model.SetAnnotationValue(entityType, new ClrTypeAnnotation(typeof(TestEntity))); entityType.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Int32); IEdmTypeReference edmType = new EdmEntityTypeReference(entityType, isNullable: false); SelectExpandWrapper <TestEntity> testWrapper = new SelectExpandWrapper <TestEntity> { Instance = new TestEntity { SampleProperty = 42 }, ModelID = ModelContainer.GetModelID(model) }; // Act var result = testWrapper.ToDictionary(); // Assert Assert.Equal(42, result["SampleProperty"]); }
public CraftModel() { model = new EdmModel(); var address = new EdmComplexType("NS", "Address"); model.AddElement(address); var mail = new EdmEntityType("NS", "Mail"); var mailId = mail.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); mail.AddKeys(mailId); model.AddElement(mail); var person = new EdmEntityType("NS", "Person"); model.AddElement(person); var personId = person.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32); person.AddKeys(personId); person.AddStructuralProperty("Addr", new EdmComplexTypeReference(address, /*Nullable*/ false)); MailBox = person.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { ContainsTarget = true, Name = "Mails", TargetMultiplicity = EdmMultiplicity.Many, Target = mail, }); var container = new EdmEntityContainer("NS", "DefaultContainer"); model.AddElement(container); MyLogin = container.AddSingleton("MyLogin", person); }