public void Translate_ReturnsODataFunctionImportSegment() { // Arrange var primitive = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, false); EdmFunction function = new EdmFunction("NS", "MyFunction", primitive, false, null, false); function.AddParameter("name", primitive); function.AddParameter("title", primitive); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmFunctionImport functionImport = new EdmFunctionImport(container, "MyFunctionImport", function); FunctionImportSegmentTemplate template = new FunctionImportSegmentTemplate(functionImport, null); Mock <HttpContext> httpContext = new Mock <HttpContext>(); Mock <IEdmModel> edmModel = new Mock <IEdmModel>(); ODataTemplateTranslateContext context = new ODataTemplateTranslateContext(httpContext.Object, new RouteValueDictionary(), edmModel.Object); // Act ODataPathSegment actual = template.Translate(context); // Assert Assert.NotNull(actual); OperationImportSegment functionImportSegment = Assert.IsType <OperationImportSegment>(actual); Assert.Same(function, functionImportSegment.OperationImports.First().Operation); }
public void TryMatch_ReturnsFalse_IfDifferentUnboundFunctionWithSameParamerters() { // Arrange IEdmModel model = new Mock <IEdmModel>().Object; IEdmEntityType returnType = new Mock <IEdmEntityType>().Object; EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmFunction function = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)); EdmFunctionImport functionImport1 = new EdmFunctionImport(container, "FunctionImport1", function); EdmFunctionImport functionImport2 = new EdmFunctionImport(container, "FunctionImport2", function); Dictionary <string, string> parameterValues = new Dictionary <string, string>() { { "Parameter1", "1" }, { "Parameter2", "2" } }; Dictionary <string, string> parameterMappings = new Dictionary <string, string>() { { "Parameter1", "{param1}" }, { "Parameter2", "{param2}" } }; UnboundFunctionPathSegment segment = new UnboundFunctionPathSegment(functionImport1, model, parameterValues); var template = new UnboundFunctionPathSegmentTemplate( new UnboundFunctionPathSegment(functionImport2, model, parameterMappings)); Dictionary <string, object> values = new Dictionary <string, object>(); // Act bool result = template.TryMatch(segment, values); // Assert Assert.False(result); }
public OperationImportSegmentTests() { 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); }
/// <summary> /// Initializes a new <see cref="IEdmOperationImport"/> instance. /// </summary> /// <param name="name">name of the service operation.</param> /// <param name="function">Function imported in.</param> /// <param name="resultSet">EntitySet of the result expected from this operation.</param> public EdmFunctionImport AddFunctionImport(string name, IEdmFunction function, IEdmEntitySet resultSet, bool includeInServiceDocument) { var functionImport = new EdmFunctionImport(this, name, function, new EdmEntitySetReferenceExpression(resultSet), includeInServiceDocument); this.AddOperationImport(name, functionImport); return(functionImport); }
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); }
private static void AddProcedures(this EdmEntityContainer container, IEnumerable <ProcedureConfiguration> configurations, Dictionary <string, IEdmStructuredType> edmTypeMap, Dictionary <string, EdmEntitySet> edmEntitySetMap) { foreach (ProcedureConfiguration procedure in configurations) { switch (procedure.Kind) { case ProcedureKind.Action: ActionConfiguration action = procedure as ActionConfiguration; IEdmTypeReference returnReference = GetEdmTypeReference(edmTypeMap, action.ReturnType, nullable: true); IEdmExpression expression = GetEdmEntitySetExpression(edmEntitySetMap, action); EdmFunctionImport functionImport = new EdmFunctionImport(container, action.Name, returnReference, expression, action.IsSideEffecting, action.IsComposable, action.IsBindable); foreach (ParameterConfiguration parameter in action.Parameters) { // TODO: http://aspnetwebstack.codeplex.com/workitem/417 IEdmTypeReference parameterTypeReference = GetEdmTypeReference(edmTypeMap, parameter.TypeConfiguration, nullable: true); EdmFunctionParameter functionParameter = new EdmFunctionParameter(functionImport, parameter.Name, parameterTypeReference, EdmFunctionParameterMode.In); functionImport.AddParameter(functionParameter); } container.AddElement(functionImport); break; case ProcedureKind.Function: Contract.Assert(false, "Functions are not supported."); break; case ProcedureKind.ServiceOperation: Contract.Assert(false, "ServiceOperations are not supported."); break; } } }
public void ValidateEntitySetAtttributeCorrectlyWritesEntitySetPath() { EdmFunctionImport functionImport = new EdmFunctionImport(defaultContainer, "GetStuff", defaultGetStuffFunction, new EdmPathExpression("Customers", "Orders"), false); this.EdmModelCsdlSchemaWriterTest(writer => writer.WriteFunctionImportElementHeader(functionImport), @"<FunctionImport Name=""GetStuff"" Function=""Default.NameSpace2.GetStuff"" EntitySet=""Customers/Orders"""); }
public void ValidateFunctionIncludeInServiceDocumentWrittenAsTrue() { EdmFunctionImport functionImport = new EdmFunctionImport(defaultContainer, "GetStuff", defaultGetStuffFunction, new EdmPathExpression("Customers", "Orders"), true); this.EdmModelCsdlSchemaWriterTest(writer => writer.WriteFunctionImportElementHeader(functionImport), @"<FunctionImport Name=""GetStuff"" Function=""Default.NameSpace2.GetStuff"" EntitySet=""Customers/Orders"" IncludeInServiceDocument=""true"""); }
public void GetFunctionParamterMappings_Works_FunctionParameter() { // Arrange IEdmTypeReference strType = EdmCoreModel.Instance.GetString(false); EdmFunction function = new EdmFunction("NS", "Function", strType); function.AddParameter("Name", strType); function.AddParameter("Title", strType); // Act IDictionary <string, string> parameters = function.GetFunctionParamterMappings(); // Assert Assert.Collection(parameters, e => { Assert.Equal("Name", e.Key); Assert.Equal("{Name}", e.Value); }, e => { Assert.Equal("Title", e.Key); Assert.Equal("{Title}", e.Value); }); // Act EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmFunctionImport functionImport = new EdmFunctionImport(container, "FunctionImport", function); IDictionary <string, string> parametersImport = parameters = function.GetFunctionParamterMappings(); // Assert Assert.Equal(parameters, parametersImport); }
public FunctionImportSegmentTemplateTests() { _function = new EdmFunction("NS", "MyFunctionImport", IntPrimitive, false, null, false); _function.AddParameter("name", StringPrimitive); _function.AddParameter("title", StringPrimitive); _container = new EdmEntityContainer("NS", "Default"); _functionImport = new EdmFunctionImport(_container, "MyFunctionImport", _function); }
public void VerifyFunctionImportWrittenCorrectly() { var functionImport = new EdmFunctionImport(defaultContainer, "GetStuff", defaultGetStuffFunction, null, true); VisitAndVerifyXml( (visitor) => visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { functionImport }), @"<FunctionImport Name=""GetStuff"" Function=""Default.NameSpace2.GetStuff"" IncludeInServiceDocument=""true"" />"); }
public void FunctionImportShouldProduceCorrectFullyQualifiedNameAndNotHaveParameters() { var function = new EdmFunction("d.s", "testFunction", EdmCoreModel.Instance.GetString(true)); function.AddParameter("param1", EdmCoreModel.Instance.GetString(false)); var functionImport = new EdmFunctionImport(new EdmEntityContainer("d.s", "container"), "testFunction", function); //Assert.Equals("d.s.container/testFunction", EdmUtil.(functionImport)); }
public void EdmFunctionImportShouldBeFunctionImport() { var function = new EdmFunction("d.s", "checkout", EdmCoreModel.Instance.GetString(true)); var functionImport = new EdmFunctionImport(new EdmEntityContainer("d", "c"), "checkout", function); functionImport.IsActionImport().Should().BeFalse(); functionImport.IsFunctionImport().Should().BeTrue(); }
public void GetActionLinkBuilder_ReturnsDefaultActionLinkBuilder_IfNotSet() { // Arrange IEdmModel model = new EdmModel(); IEdmEntityContainer container = new EdmEntityContainer("NS", "Container"); IEdmFunctionImport action = new EdmFunctionImport(container, "Action", returnType: null); Assert.NotNull(model.GetActionLinkBuilder(action)); }
public void VerifyTwoIdenticalNamedFunctionImportsWithSameEntitySetPathValueOnlyWrittenOnce() { var functionImport = new EdmFunctionImport(defaultContainer, "GetStuff", defaultGetStuffFunction, new EdmPathExpression("path1", "path2"), true); var functionImport2 = new EdmFunctionImport(defaultContainer, "GetStuff", defaultGetStuffFunction, new EdmPathExpression("path1", "path2"), true); VisitAndVerifyXml( (visitor) => visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { functionImport, functionImport2 }), @"<FunctionImport Name=""GetStuff"" Function=""Default.NameSpace2.GetStuff"" EntitySet=""path1/path2"" IncludeInServiceDocument=""true"" />"); }
public void CreateResponseForOperationThrowArgumentNullPath() { // Arrange ODataContext context = new ODataContext(EdmCoreModel.Instance); EdmFunction function = new EdmFunction("NS", "MyFunction", EdmCoreModel.Instance.GetString(false)); EdmFunctionImport functionImport = new EdmFunctionImport(new EdmEntityContainer("NS", "Default"), "MyFunctionImport", function); // Act & Assert Assert.Throws <ArgumentNullException>("path", () => context.CreateResponses(operation: function, path: null)); }
public ODataJsonLightUtilsTests() { this.MetadataDocumentUri = new Uri("http://www.myhost.com/myservice.svc/$metadata"); this.model = new EdmModel(); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer"); this.model.AddElement(defaultContainer); this.cityType = new EdmEntityType("TestModel", "City"); EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false)); cityType.AddKeys(cityIdProperty); cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/ false)); cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false)); this.model.AddElement(cityType); EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType"); this.model.AddElement(complexType); this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationImportWithNoOverload = defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload); this.model.AddElement(operationWithNoOverload); this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param); this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); this.model.AddElement(operationWithOverloadAnd1Param); this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param); this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); var cityTypeReference = new EdmEntityTypeReference(this.cityType, isNullable: false); this.operationWithOverloadAnd2Params.AddParameter("p1", cityTypeReference); this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true)); this.model.AddElement(operationWithOverloadAnd2Params); this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params); this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(cityTypeReference))); this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)))); this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true)); EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false); this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference); this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference))); this.model.AddElement(operationWithOverloadAnd5Params); this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params); }
public void CreateOperationIdWithSHA5ForOverloadEdmFunctionImport(bool enableOperationId) { // Arrange EdmModel model = new EdmModel(); EdmEntityType customer = new EdmEntityType("NS", "Customer"); customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32)); model.AddElement(customer); EdmFunction function1 = new EdmFunction("NS", "MyFunction1", EdmCoreModel.Instance.GetString(false), false, null, false); function1.AddParameter("entity", new EdmEntityTypeReference(customer, false)); function1.AddParameter("param", EdmCoreModel.Instance.GetString(false)); model.AddElement(function1); EdmFunction function2 = new EdmFunction("NS", "MyFunction1", EdmCoreModel.Instance.GetString(false), false, null, false); function2.AddParameter("entity", new EdmEntityTypeReference(customer, false)); function2.AddParameter("param", EdmCoreModel.Instance.GetString(false)); function2.AddParameter("otherParam", EdmCoreModel.Instance.GetString(false)); model.AddElement(function2); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmFunctionImport functionImport1 = new EdmFunctionImport(container, "MyFunction", function1); EdmFunctionImport functionImport2 = new EdmFunctionImport(container, "MyFunction", function2); container.AddElement(functionImport1); container.AddElement(functionImport2); model.AddElement(container); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableOperationId = enableOperationId, AddSingleQuotesForStringParameters = true, }; ODataContext context = new ODataContext(model, settings); ODataPath path = new ODataPath(new ODataOperationImportSegment(functionImport1)); // Act var operation = _operationHandler.CreateOperation(context, path); // Assert Assert.NotNull(operation); if (enableOperationId) { Assert.Equal("FunctionImport.MyFunction-cc1c", operation.OperationId); } else { Assert.Null(operation.OperationId); } }
public void AmbigiousOperationBindingShouldReferToFirstOperationAlwaysWhenNotNull() { var container1 = new EdmEntityContainer("n", "d"); var container2 = new EdmEntityContainer("n", "d"); var action1Import = new EdmActionImport(container1, "name", new EdmAction("n", "name", null)); var functionImport = new EdmFunctionImport(container2, "name", new EdmFunction("n", "name", EdmCoreModel.Instance.GetString(true))); var ambigiousOperationBinding = new AmbiguousOperationImportBinding(action1Import, functionImport); Assert.Equal(EdmContainerElementKind.ActionImport, ambigiousOperationBinding.ContainerElementKind); Assert.Equal("name", ambigiousOperationBinding.Name); Assert.Null(ambigiousOperationBinding.EntitySet); Assert.Same(container1, ambigiousOperationBinding.Container); }
public void VerifyIdenticalNamedFunctionImportsWithDifferentEntitySetPropertiesAreWritten() { var functionImportOnSet = new EdmFunctionImport(defaultContainer, "Checkout", defaultGetStuffFunction, new EdmPathExpression("Set"), false); var functionImportOnSet2 = new EdmFunctionImport(defaultContainer, "Checkout", defaultGetStuffFunction, new EdmPathExpression("Set2"), false); var functionmportWithNoEntitySet = new EdmFunctionImport(defaultContainer, "Checkout", defaultGetStuffFunction, null, false); var functionImportWithUniqueEdmPath = new EdmFunctionImport(defaultContainer, "Checkout", defaultGetStuffFunction, new EdmPathExpression("path1", "path2"), false); VisitAndVerifyXml( (visitor) => { visitor.VisitEntityContainerElements(new IEdmEntityContainerElement[] { functionImportOnSet, functionImportOnSet2, functionmportWithNoEntitySet, functionImportWithUniqueEdmPath }); }, @"<FunctionImport Name=""Checkout"" Function=""Default.NameSpace2.GetStuff"" EntitySet=""Set"" /><FunctionImport Name=""Checkout"" Function=""Default.NameSpace2.GetStuff"" EntitySet=""Set2"" /><FunctionImport Name=""Checkout"" Function=""Default.NameSpace2.GetStuff"" /><FunctionImport Name=""Checkout"" Function=""Default.NameSpace2.GetStuff"" EntitySet=""path1/path2"" />"); }
private static void AddProcedures(this IEdmModel model, IEnumerable <ProcedureConfiguration> configurations, EdmEntityContainer container, Dictionary <Type, IEdmStructuredType> edmTypeMap, Dictionary <string, EdmEntitySet> edmEntitySetMap) { foreach (ProcedureConfiguration procedure in configurations) { switch (procedure.Kind) { case ProcedureKind.Action: ActionConfiguration action = procedure as ActionConfiguration; IEdmTypeReference returnReference = GetEdmTypeReference(edmTypeMap, action.ReturnType, nullable: true); IEdmExpression expression = GetEdmEntitySetExpression(edmEntitySetMap, action); EdmFunctionImport functionImport = new EdmFunctionImport(container, action.Name, returnReference, expression, action.IsSideEffecting, action.IsComposable, action.IsBindable); if (action.IsBindable) { model.SetIsAlwaysBindable(functionImport, action.IsAlwaysBindable); if (action.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity) { Func <EntityInstanceContext, Uri> actionFactory = action.GetActionLink(); if (actionFactory != null) { model.SetActionLinkBuilder(functionImport, new ActionLinkBuilder(actionFactory, action.FollowsConventions)); } } } foreach (ParameterConfiguration parameter in action.Parameters) { // TODO: http://aspnetwebstack.codeplex.com/workitem/417 bool isParameterOptional = EdmLibHelpers.IsNullable(parameter.TypeConfiguration.ClrType); IEdmTypeReference parameterTypeReference = GetEdmTypeReference(edmTypeMap, parameter.TypeConfiguration, nullable: isParameterOptional); EdmFunctionParameter functionParameter = new EdmFunctionParameter(functionImport, parameter.Name, parameterTypeReference, EdmFunctionParameterMode.In); functionImport.AddParameter(functionParameter); } container.AddElement(functionImport); break; case ProcedureKind.Function: Contract.Assert(false, "Functions are not supported."); break; case ProcedureKind.ServiceOperation: Contract.Assert(false, "ServiceOperations are not supported."); break; } } }
public void ODataPathSegmentHandler_Handles_FunctionImportSegment() { // Arrange ODataPathSegmentHandler handler = new ODataPathSegmentHandler(); IEdmTypeReference intType = EdmCoreModel.Instance.GetInt32(false); EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default"); IEdmFunction function = new EdmFunction("NS", "function", intType); IEdmFunctionImport functionImport = new EdmFunctionImport(entityContainer, "function", function); OperationImportSegment segment = new OperationImportSegment(functionImport, null); // Act handler.Handle(segment); // Assert Assert.Equal("function()", handler.PathLiteral); Assert.Null(handler.NavigationSource); }
public EdmLibraryExtensionsTests() { this.model = TestModel.BuildDefaultTestModel(); this.defaultContainer = (EdmEntityContainer)this.model.FindEntityContainer("Default"); this.productsSet = this.defaultContainer.FindEntitySet("Products"); this.productType = (IEdmEntityType)this.model.FindDeclaredType("TestModel.Product"); this.productTypeReference = new EdmEntityTypeReference(this.productType, false); EdmComplexType complexType = new EdmComplexType("TestModel", "MyComplexType"); this.operationWithNoOverload = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithNoOverload.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); this.model.AddElement(operationWithNoOverload); this.operationImportWithNoOverload = this.defaultContainer.AddFunctionImport("FunctionImportWithNoOverload", operationWithNoOverload); this.operationWithOverloadAnd0Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.model.AddElement(operationWithOverloadAnd0Param); this.operationImportWithOverloadAnd0Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd0Param); this.operationWithOverloadAnd1Param = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd1Param.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); this.model.AddElement(operationWithOverloadAnd1Param); this.operationImportWithOverloadAnd1Param = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd1Param); this.operationWithOverloadAnd2Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); var productTypeReference = new EdmEntityTypeReference(productType, isNullable: false); this.operationWithOverloadAnd2Params.AddParameter("p1", productTypeReference); this.operationWithOverloadAnd2Params.AddParameter("p2", EdmCoreModel.Instance.GetString(true)); this.model.AddElement(operationWithOverloadAnd2Params); this.operationImportWithOverloadAnd2Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd2Params); this.operationWithOverloadAnd5Params = new EdmFunction("TestModel", "FunctionImportWithNoOverload", EdmCoreModel.Instance.GetInt32(true)); this.operationWithOverloadAnd5Params.AddParameter("p1", new EdmCollectionTypeReference(new EdmCollectionType(productTypeReference))); this.operationWithOverloadAnd5Params.AddParameter("p2", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)))); this.operationWithOverloadAnd5Params.AddParameter("p3", EdmCoreModel.Instance.GetString(isNullable: true)); EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false); this.operationWithOverloadAnd5Params.AddParameter("p4", complexTypeReference); this.operationWithOverloadAnd5Params.AddParameter("p5", new EdmCollectionTypeReference(new EdmCollectionType(complexTypeReference))); this.model.AddElement(operationWithOverloadAnd5Params); this.operationImportWithOverloadAnd5Params = defaultContainer.AddFunctionImport("FunctionImportWithOverload", operationWithOverloadAnd5Params); }
public void ValidateCorrectEntitySetPathOnOperationImport() { EdmFunction function = new EdmFunction("ns", "GetStuff", EdmCoreModel.Instance.GetString(false), true /*isBound*/, null, false); function.AddParameter("param", DefaultValidCollectionEntityTypeRef); EdmFunctionImport functionImport = new EdmFunctionImport(new EdmEntityContainer("ds", "d"), "GetStuff", function, new EdmPathExpression("param"), false); EdmModel model = new EdmModel(); model.AddElement(function); IEnumerable <EdmError> errorsFound = null; IEdmOperationParameter operationParameter = null; IEnumerable <IEdmNavigationProperty> navigationProperties = null; functionImport.TryGetRelativeEntitySetPath(model, out operationParameter, out navigationProperties, out errorsFound).Should().BeTrue(); errorsFound.ToList().Should().HaveCount(0); operationParameter.Should().NotBeNull(); navigationProperties.Should().HaveCount(0); }
public void ODataPathSegmentToTemplateHandler_Handles_FunctionImport() { // Arrange ODataPathSegmentToTemplateHandler handler = new ODataPathSegmentToTemplateHandler(null); IEdmTypeReference intType = EdmCoreModel.Instance.GetInt32(false); EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default"); IEdmFunction function = new EdmFunction("NS", "function", intType); IEdmFunctionImport functionImport = new EdmFunctionImport(entityContainer, "function", function); OperationImportSegment segment = new OperationImportSegment(functionImport, null); // Act handler.Handle(segment); // Assert ODataSegmentTemplate segmentTemplate = Assert.Single(handler.Templates); Assert.IsType <FunctionImportSegmentTemplate>(segmentTemplate); }
public void TryMatch_ReturnTrue_IfSameUnboundFunction() { // Arrange IEdmModel model = new Mock <IEdmModel>().Object; IEdmEntityType returnType = new Mock <IEdmEntityType>().Object; EdmEntityContainer container = new EdmEntityContainer("NS", "Container"); EdmFunction func = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)); func.AddParameter("Parameter1", EdmCoreModel.Instance.GetInt32(isNullable: false)); func.AddParameter("Parameter2", EdmCoreModel.Instance.GetInt32(isNullable: false)); EdmFunctionImport function = new EdmFunctionImport(container, "Function", func); Dictionary <string, string> parameterValues = new Dictionary <string, string> { { "Parameter1", "1" }, { "Parameter2", "2" } }; Dictionary <string, string> parameterMappings = new Dictionary <string, string> { { "Parameter1", "{param1}" }, { "Parameter2", "{param2}" } }; UnboundFunctionPathSegment segment = new UnboundFunctionPathSegment(function, model, parameterValues); UnboundFunctionPathSegmentTemplate template = new UnboundFunctionPathSegmentTemplate( new UnboundFunctionPathSegment(function, model, parameterMappings)); // Act Dictionary <string, object> values = new Dictionary <string, object>(); bool result = template.TryMatch(segment, values); // Assert Assert.True(result); Assert.Equal(4, values.Count); Assert.Equal("1", values["param1"]); Assert.Equal("2", values["param2"]); Assert.Equal(1, (values[ODataParameterValue.ParameterValuePrefix + "param1"] as ODataParameterValue).Value); Assert.Equal(2, (values[ODataParameterValue.ParameterValuePrefix + "param2"] as ODataParameterValue).Value); }
public void FunctionCommonProperties_ReturnsAsExpected() { // Assert var primitive = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, false); EdmFunction function = new EdmFunction("NS", "MyFunction", primitive, false, null, false); function.AddParameter("name", primitive); function.AddParameter("title", primitive); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmFunctionImport functionImport = new EdmFunctionImport(container, "MyFunctionImport", function); FunctionImportSegmentTemplate functionImportSegment = new FunctionImportSegmentTemplate(functionImport, null); // Act & Assert Assert.Equal("MyFunctionImport(name={name},title={title})", functionImportSegment.Literal); Assert.Equal(ODataSegmentKind.FunctionImport, functionImportSegment.Kind); Assert.True(functionImportSegment.IsSingle); Assert.Same(primitive.Definition, functionImportSegment.EdmType); Assert.Null(functionImportSegment.NavigationSource); }
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.790300f48b60d73292a9c056", operation.OperationId); } else { Assert.Null(operation.OperationId); } }
public void GetTemplatesFunctionImportSegmentTemplate_ReturnsTemplates_ForEmptyParameter() { // Arrange EdmFunction function = new EdmFunction("NS", "MyFunctionImport", IntPrimitive, false, null, false); EdmEntityContainer container = new EdmEntityContainer("NS", "Default"); EdmFunctionImport functionImport = new EdmFunctionImport(container, "MyFunctionImport", function); FunctionImportSegmentTemplate functionImportSegment = new FunctionImportSegmentTemplate(functionImport, null); // Act & Assert IEnumerable <string> templates = functionImportSegment.GetTemplates(); string template = Assert.Single(templates); Assert.Equal("/MyFunctionImport()", template); // Act & Assert templates = functionImportSegment.GetTemplates(new ODataRouteOptions { EnableNonParenthesisForEmptyParameterFunction = true }); template = Assert.Single(templates); Assert.Equal("/MyFunctionImport", template); }
/// <summary> /// Initializes a new <see cref="IEdmOperationImport"/> instance. /// </summary> /// <param name="name">name of the service operation.</param> /// <param name="function">Function imported in.</param> /// <param name="resultSet">EntitySet of the result expected from this operation.</param> public EdmFunctionImport AddFunctionAndFunctionImport(string name, IEdmTypeReference bindingType, IEdmTypeReference resultType, IEdmEntitySet resultSet, bool isBindable) { var edmFunction = new EdmFunction(this.Namespace, name, resultType, isBindable, null, false /*isComposable*/); if (isBindable) { edmFunction.AddParameter("bindingparameter", bindingType); } EdmEntitySetReferenceExpression entitySetExpression = null; if (resultSet != null) { entitySetExpression = new EdmEntitySetReferenceExpression(resultSet); } this.AddOperation(edmFunction); var functionImport = new EdmFunctionImport(this, name, edmFunction, entitySetExpression, false); this.AddOperationImport(name, functionImport); return(functionImport); }