private static void AddOperationParameters(EdmOperation operation, OperationConfiguration operationConfiguration, Dictionary <Type, IEdmType> edmTypeMap) { foreach (ParameterConfiguration parameter in operationConfiguration.Parameters) { bool isParameterOptional = parameter.OptionalParameter; IEdmTypeReference parameterTypeReference = GetEdmTypeReference(edmTypeMap, parameter.TypeConfiguration, nullable: isParameterOptional); IEdmOperationParameter operationParameter = new EdmOperationParameter(operation, parameter.Name, parameterTypeReference); operation.AddParameter(operationParameter); } }
public void CanRemoveOperation() { // Arrange // Act ODataModelBuilder builder = new ODataModelBuilder(); ActionConfiguration action = builder.Action("Format"); OperationConfiguration operation = builder.Operations.SingleOrDefault(); bool removed = builder.RemoveOperation(operation); // Assert Assert.True(removed); Assert.Equal(0, builder.Operations.Count()); }
public void AttemptToRemoveNonExistantEntityReturnsFalse() { // Arrange ODataModelBuilder builder = new ODataModelBuilder(); ODataModelBuilder builder2 = new ODataModelBuilder(); OperationConfiguration toRemove = builder2.Action("ToRemove"); // Act bool removedByName = builder.RemoveOperation("ToRemove"); bool removed = builder.RemoveOperation(toRemove); //Assert Assert.False(removedByName); Assert.False(removed); }
private static EdmOperationImport CreateActionImport( OperationConfiguration operationConfiguration, EdmEntityContainer container, IEdmTypeReference returnReference, IEdmExpression expression, IEdmPathExpression pathExpression) { EdmAction operation = new EdmAction( operationConfiguration.Namespace, operationConfiguration.Name, returnReference, operationConfiguration.IsBindable, pathExpression); return(new EdmActionImport(container, operationConfiguration.Name, operation, expression)); }
private static IEdmExpression GetEdmEntitySetExpression(IDictionary <string, EdmNavigationSource> navigationSources, OperationConfiguration operationConfiguration) { if (operationConfiguration.NavigationSource != null) { EdmNavigationSource navigationSource; if (navigationSources.TryGetValue(operationConfiguration.NavigationSource.Name, out navigationSource)) { EdmEntitySet entitySet = navigationSource as EdmEntitySet; if (entitySet != null) { return(new EdmPathExpression(entitySet.Name)); } } else { throw Error.InvalidOperation(SRResources.EntitySetNotFoundForName, operationConfiguration.NavigationSource.Name); } } else if (operationConfiguration.EntitySetPath != null) { return(new EdmPathExpression(operationConfiguration.EntitySetPath)); } return(null); }
private static void ValidateOperationEntitySetPath(IEdmModel model, IEdmOperationImport operationImport, OperationConfiguration operationConfiguration) { IEdmOperationParameter operationParameter; Dictionary <IEdmNavigationProperty, IEdmPathExpression> relativeNavigations; IEnumerable <EdmError> edmErrors; if (operationConfiguration.EntitySetPath != null && !operationImport.TryGetRelativeEntitySetPath(model, out operationParameter, out relativeNavigations, out edmErrors)) { throw Error.InvalidOperation(SRResources.OperationHasInvalidEntitySetPath, String.Join("/", operationConfiguration.EntitySetPath), operationConfiguration.FullyQualifiedName); } }
private static void AddOperationLinkBuilder(IEdmModel model, IEdmOperation operation, OperationConfiguration operationConfiguration) { ActionConfiguration actionConfiguration = operationConfiguration as ActionConfiguration; IEdmAction action = operation as IEdmAction; FunctionConfiguration functionConfiguration = operationConfiguration as FunctionConfiguration; IEdmFunction function = operation as IEdmFunction; if (operationConfiguration.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity) { if (actionConfiguration != null && actionConfiguration.GetActionLink() != null && action != null) { model.SetOperationLinkBuilder( action, new OperationLinkBuilder(actionConfiguration.GetActionLink(), actionConfiguration.FollowsConventions)); } else if (functionConfiguration != null && functionConfiguration.GetFunctionLink() != null && function != null) { model.SetOperationLinkBuilder( function, new OperationLinkBuilder(functionConfiguration.GetFunctionLink(), functionConfiguration.FollowsConventions)); } } else if (operationConfiguration.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Collection) { CollectionTypeConfiguration collectionTypeConfiguration = (CollectionTypeConfiguration)operationConfiguration.BindingParameter.TypeConfiguration; if (collectionTypeConfiguration.ElementType.Kind == EdmTypeKind.Entity) { if (actionConfiguration != null && actionConfiguration.GetFeedActionLink() != null && action != null) { model.SetOperationLinkBuilder( action, new OperationLinkBuilder(actionConfiguration.GetFeedActionLink(), actionConfiguration.FollowsConventions)); } else if (functionConfiguration != null && functionConfiguration.GetFeedFunctionLink() != null && function != null) { model.SetOperationLinkBuilder( function, new OperationLinkBuilder(functionConfiguration.GetFeedFunctionLink(), functionConfiguration.FollowsConventions)); } } } }
/// <summary> /// Adds a operation to the model. /// </summary> public virtual void AddOperation(OperationConfiguration operation) { _operations.Add(operation); }