public void TryMatch_ReturnTrue_IfSameFunction() { // Arrange IEdmEntityType returnType = new Mock<IEdmEntityType>().Object; EdmFunction function = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)); Dictionary<string, string> parameterValues = new Dictionary<string, string>() { { "Parameter1", "1" }, { "Parameter2", "2" } }; Dictionary<string, string> parameterMappings = new Dictionary<string, string>() { { "Parameter1", "{param1}" }, { "Parameter2", "{param2}" } }; BoundFunctionPathSegment segment = new BoundFunctionPathSegment(function, model: null, parameterValues: parameterValues); BoundFunctionPathSegmentTemplate template = new BoundFunctionPathSegmentTemplate( new BoundFunctionPathSegment(function, model: null, parameterValues: parameterMappings)); // Act Dictionary<string, object> values = new Dictionary<string,object>(); bool result = template.TryMatch(segment, values); // Assert Assert.True(result); Assert.Equal(2, values.Count); Assert.Equal("1", values["param1"]); Assert.Equal("2", values["param2"]); }
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); EdmUtil.FullyQualifiedName(functionImport).Should().Be("d.s.container/testFunction"); }
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 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); }
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 void EdmFunctionConstructorWithNullReturnTypeShouldNotThrow() { var edmFunction = new EdmFunction(defaultNamespaceName, checkout, this.boolType); edmFunction.Namespace.Should().Be(defaultNamespaceName); edmFunction.Name.Should().Be(checkout); edmFunction.ReturnType.Should().Be(this.boolType); edmFunction.IsComposable.Should().BeFalse(); }
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); }
public void EdmFunctionConstructorShouldDefaultNonSpecifiedPropertiesCorrectly() { var edmFunction = new EdmFunction(defaultNamespaceName, checkout, this.boolType); edmFunction.Namespace.Should().Be(defaultNamespaceName); edmFunction.Name.Should().Be(checkout); edmFunction.ReturnType.Should().Be(this.boolType); edmFunction.EntitySetPath.Should().BeNull(); edmFunction.IsBound.Should().BeFalse(); edmFunction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Function); edmFunction.IsComposable.Should().BeFalse(); }
public void DuplicateFunctionOverloadsWithDifferentBindingTypesAndSameNameWithDifferentReturnTypesShouldNotError() { var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true)); var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetInt16(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt32(true)); EdmModel model = new EdmModel(); model.AddElement(edmFunction); model.AddElement(edmFunction2); ValidateNoError(model); }
public void DuplicateUnBoundFunctionOverloadsSameParameterNamesShouldError() { var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); edmFunction.AddParameter("bindingParameter1", EdmCoreModel.Instance.GetInt16(true)); var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetInt16(true), false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); edmFunction2.AddParameter("bindingParameter1", EdmCoreModel.Instance.GetInt32(true)); EdmModel model = new EdmModel(); model.AddElement(edmFunction); model.AddElement(edmFunction2); ValidateError(model, EdmErrorCode.DuplicateFunctions, Strings.EdmModel_Validator_Semantic_ModelDuplicateUnBoundFunctionsParameterNames("n.s.GetStuff")); }
public void EnsureDuplicateTermAndFunctionReturnTrue() { EdmModel model = new EdmModel(); var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); model.AddElement(edmFunction); EdmModel otherModel = new EdmModel(); var edmTerm = new EdmTerm("n.s", "GetStuff", EdmPrimitiveTypeKind.Int32); otherModel.AddElement(edmTerm); model.AddReferencedModel(otherModel); model.OperationOrNameExistsInReferencedModel(edmFunction, edmFunction.FullName()).Should().BeTrue(); }
public void EdmFunctionConstructorShouldHaveSpecifiedConstructorValues() { var entitySetPath = new EdmPathExpression("Param1/Nav"); var edmFunction = new EdmFunction(defaultNamespaceName, checkout, this.boolType, true, entitySetPath, true /*IsComposable*/); edmFunction.AddParameter(new EdmOperationParameter(edmFunction, "Param1", new EdmEntityTypeReference(personType, false))); edmFunction.Namespace.Should().Be(defaultNamespaceName); edmFunction.Name.Should().Be(checkout); edmFunction.ReturnType.Should().Be(this.boolType); edmFunction.EntitySetPath.Should().Be(entitySetPath); edmFunction.IsBound.Should().BeTrue(); edmFunction.SchemaElementKind.Should().Be(EdmSchemaElementKind.Function); edmFunction.IsComposable.Should().BeTrue(); }
public void EnsureNoDuplicateFoundForFunctionShouldReturnFalse() { EdmModel otherModel = new EdmModel(); var entityType = new EdmEntityType("n.s", "GetStuff2"); otherModel.AddElement(entityType); var edmFunction = new EdmFunction("n.s", "GetStuff", new EdmEntityTypeReference(entityType, false), false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); EdmModel model = new EdmModel(); model.AddElement(edmFunction); model.AddReferencedModel(otherModel); model.OperationOrNameExistsInReferencedModel(edmFunction, edmFunction.FullName()).Should().BeFalse(); }
public void EnsureDuplicateContainerFunctionReturnTrue() { EdmModel model = new EdmModel(); var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), false /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); model.AddElement(edmFunction); EdmModel otherModel = new EdmModel(); EdmEntityContainer container = new EdmEntityContainer("n.s", "GetStuff"); otherModel.AddElement(container); model.AddReferencedModel(otherModel); model.OperationOrNameExistsInReferencedModel(edmFunction, edmFunction.FullName()).Should().BeTrue(); }
public void GetEdmType_Returns_FunctionReturnType() { // Arrange IEdmEntityType returnType = new Mock<IEdmEntityType>().Object; EdmFunction function = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)); BoundFunctionPathSegment segment = new BoundFunctionPathSegment(function, model: null, parameterValues: null); // Act var result = segment.GetEdmType(returnType); // Assert Assert.Same(returnType, result); }
public void AmbigiousOperationBindingShouldReferToFirstOperationAlwaysWhenNotNull() { var action1 = new EdmAction("DS", "name", EdmCoreModel.Instance.GetBoolean(false)); action1.AddParameter("param", EdmCoreModel.Instance.GetBoolean(false)); var function = new EdmFunction("DS2", "name2", EdmCoreModel.Instance.GetBoolean(false), true, new EdmPathExpression("path1"), true); AmbiguousOperationBinding ambigiousOperationBinding = new AmbiguousOperationBinding(action1, function); ambigiousOperationBinding.Namespace.Should().Be("DS"); ambigiousOperationBinding.Name.Should().Be("name"); ambigiousOperationBinding.ReturnType.Should().BeNull(); ambigiousOperationBinding.Parameters.Should().HaveCount(1); ambigiousOperationBinding.SchemaElementKind.Should().Be(EdmSchemaElementKind.Action); ambigiousOperationBinding.IsBound.Should().BeFalse(); ambigiousOperationBinding.EntitySetPath.Should().BeNull(); }
public void DuplicateFunctionsUnBoundFunctionsWithSameNameWhereBindingTypeDifferentonNullabilityAndSameParametersShouldError() { var edmFunction = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); edmFunction.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true)); edmFunction.AddParameter("differentName", EdmCoreModel.Instance.GetInt16(true)); var edmFunction2 = new EdmFunction("n.s", "GetStuff", EdmCoreModel.Instance.GetString(true), true /*isBound*/, null /*entitySetPath*/, false /*isComposable*/); edmFunction2.AddParameter("bindingParameter", EdmCoreModel.Instance.GetInt16(true)); edmFunction2.AddParameter("otherParameter", EdmCoreModel.Instance.GetInt16(false)); EdmModel model = new EdmModel(); model.AddElement(edmFunction); model.AddElement(edmFunction2); ValidateError(model, EdmErrorCode.DuplicateFunctions, Strings.EdmModel_Validator_Semantic_ModelDuplicateBoundFunctionParameterTypes("n.s.GetStuff")); }
public MissingOperationGeneratorTests() { this.model = new EdmModel(); this.container = new EdmEntityContainer("Fake", "Container"); this.functionEdmMetadata = new EdmFunction("Fake", "FakeFunction", EdmCoreModel.Instance.GetInt32(false), true /*isBound*/, null, true /*isComposable*/); this.actionEdmMetadata = new EdmAction("Fake", "FakeAction", EdmCoreModel.Instance.GetInt32(false), true/*isBound*/, null /*entitySetPath*/); this.model.AddElement(this.container); this.model.AddElement(this.actionEdmMetadata); this.model.AddElement(this.functionEdmMetadata); this.allOperations = new EdmOperation[] { this.actionEdmMetadata, this.functionEdmMetadata }; this.odataAction = new ODataAction {Metadata = new Uri("http://temp.org/$metadata#Fake.FakeAction")}; this.odataFunction = new ODataFunction {Metadata = new Uri("http://temp.org/$metadata#Fake.FakeFunction")}; }
public void TestInitialize() { 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 AddOperationWhileTypeHasSameNameButOneIsAction() { EdmModel model = new EdmModel(); EdmComplexType c1 = new EdmComplexType("Ambiguous", "Binding"); IEdmOperation o1 = new EdmFunction("Ambiguous", "Binding", EdmCoreModel.Instance.GetInt16(true)); IEdmOperation o2 = new EdmAction("Ambiguous", "Binding", EdmCoreModel.Instance.GetInt16(true)); IEdmOperation o3 = new EdmFunction("Ambiguous", "Binding", EdmCoreModel.Instance.GetInt16(true)); model.AddElement(o1); Assert.AreEqual(1, model.FindOperations("Ambiguous.Binding").Count(), "First function was correctly added to operation group"); model.AddElement(o2); Assert.AreEqual(2, model.FindOperations("Ambiguous.Binding").Count(), "Second function was correctly added to operation group"); model.AddElement(c1); model.AddElement(o3); Assert.AreEqual(3, model.FindOperations("Ambiguous.Binding").Count(), "Third function was correctly added to operation group"); Assert.AreEqual(c1, model.FindType("Ambiguous.Binding"), "Single item resolved"); }
public void HeterogeneousCollectionReaderTest() { EdmModel model = new EdmModel(); var cityType = new EdmComplexType("TestModel", "CityType"); cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(true)); model.AddElement(cityType); var addressType = new EdmComplexType("TestModel", "AddressType"); addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(true)); model.AddElement(addressType); var testContainer = new EdmEntityContainer("TestModel", "TestContainer"); model.AddElement(testContainer); EdmFunction citiesFunction = new EdmFunction("TestModel", "Cities", EdmCoreModel.GetCollection(cityType.ToTypeReference())); model.AddElement(citiesFunction); EdmOperationImport citiesFunctionImport = testContainer.AddFunctionImport("Cities", citiesFunction); model.Fixup(); // Add some hand-crafted payloads IEnumerable<PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[] { // expected type without type names in the payload and heterogeneous items new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = new ComplexInstanceCollection( PayloadBuilder.ComplexValue().Property("Name", PayloadBuilder.PrimitiveValue("Vienna")), PayloadBuilder.ComplexValue().Property("Street", PayloadBuilder.PrimitiveValue("Am Euro Platz"))) .ExpectedFunctionImport(citiesFunctionImport) .CollectionName(null), PayloadEdmModel = model, ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "Street", "TestModel.CityType"), }, }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { testDescriptor.RunTest(testConfiguration); }); }
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 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 Ctor_InitializeParameterMappingsProperty_Function() { // 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)); Dictionary<string, string> parameterMappings = new Dictionary<string, string>() { { "Parameter1", "{param1}" }, { "Parameter2", "{param2}" } }; // Act var template = new BoundFunctionPathSegmentTemplate( new BoundFunctionPathSegment(function, model, parameterMappings)); // Assert Assert.Equal(2, template.ParameterMappings.Count); }
private IEdmModel CreateTestModel() { EdmModel model = new EdmModel(); EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "Default"); model.AddElement(defaultContainer); var productType = new EdmEntityType("TestModel", "Product"); EdmStructuralProperty idProperty = new EdmStructuralProperty(productType, "Id", EdmCoreModel.Instance.GetInt32(false)); productType.AddProperty(idProperty); productType.AddKeys(idProperty); productType.AddProperty(new EdmStructuralProperty(productType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(productType); var customerType = new EdmEntityType("TestModel", "Customer"); idProperty = new EdmStructuralProperty(customerType, "Id", EdmCoreModel.Instance.GetInt32(false)); customerType.AddProperty(idProperty); customerType.AddKeys(idProperty); customerType.AddProperty(new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(true))); model.AddElement(productType); defaultContainer.AddEntitySet("Products", productType); defaultContainer.AddEntitySet("Customers", customerType); defaultContainer.AddSingleton("SingleProduct", productType); defaultContainer.AddSingleton("SingleCustomer", customerType); EdmAction action = new EdmAction("TestModel", "SimpleAction", null/*returnType*/, false /*isBound*/, null /*entitySetPath*/); model.AddElement(action); defaultContainer.AddActionImport("SimpleActionImport", action); EdmFunction function1 = new EdmFunction("TestModel", "SimpleFunction1", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true); function1.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); defaultContainer.AddFunctionImport("SimpleFunctionImport1", function1); EdmFunction function2 = new EdmFunction("TestModel", "SimpleFunction2", EdmCoreModel.Instance.GetInt32(false), false /*isbound*/, null, true); function2.AddParameter("p1", EdmCoreModel.Instance.GetInt32(false)); defaultContainer.AddFunctionImport("SimpleFunctionImport2", function1, null, true /*IncludeInServiceDocument*/); return model; }
static ODataEntryMetadataContextTest() { ActualEntityType = new EdmEntityType("ns", "TypeName"); ActualEntityType.AddKeys(new IEdmStructuralProperty[] {ActualEntityType.AddStructuralProperty("ID2", EdmPrimitiveTypeKind.Int32), ActualEntityType.AddStructuralProperty("ID3", EdmPrimitiveTypeKind.Int32)}); ActualEntityType.AddStructuralProperty("Name2", EdmCoreModel.Instance.GetString(isNullable:true), /*defaultValue*/null, EdmConcurrencyMode.Fixed); ActualEntityType.AddStructuralProperty("Name3", EdmCoreModel.Instance.GetString(isNullable: true), /*defaultValue*/null, EdmConcurrencyMode.Fixed); ActualEntityType.AddStructuralProperty("StreamProp1", EdmPrimitiveTypeKind.Stream); ActualEntityType.AddStructuralProperty("StreamProp2", EdmPrimitiveTypeKind.Stream); var navProp1 = ActualEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = ActualEntityType, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavProp1" }); var navProp2 = ActualEntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = ActualEntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne, Name = "NavProp2" }); var container = new EdmEntityContainer("Namespace", "Container"); EdmEntitySet entitySet = container.AddEntitySet("EntitySet", ActualEntityType); entitySet.AddNavigationTarget(navProp1, entitySet); entitySet.AddNavigationTarget(navProp2, entitySet); Action1 = new EdmAction("Namespace", "Action1", null, true /*isBound*/, null /*entitySetPath*/); Action2 = new EdmAction("Namespace", "Action2", null, true /*isBound*/, null /*entitySetPath*/); ActionImport1 = new EdmActionImport(container, "ActionImport1", Action1); ActionImport2 = new EdmActionImport(container, "ActionImport2", Action2); Function1 = new EdmFunction("Namespace", "Function1", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, true /*isComposable*/); Function2 = new EdmFunction("Namespace", "Function2", EdmCoreModel.Instance.GetString(isNullable: true), true /*isBound*/, null /*entitySetPath*/, true /*isComposable*/); FunctionImport1 = new EdmFunctionImport(container, "FunctionImport1", Function1); FunctionImport2 = new EdmFunctionImport(container, "FunctionImport2", Function2); }
static ODataJsonLightEntryAndFeedDeserializerTests() { EdmModel tmpModel = new EdmModel(); EdmComplexType complexType = new EdmComplexType("TestNamespace", "TestComplexType"); complexType.AddProperty(new EdmStructuralProperty(complexType, "StringProperty", EdmCoreModel.Instance.GetString(false))); tmpModel.AddElement(complexType); EntityType = new EdmEntityType("TestNamespace", "TestEntityType"); tmpModel.AddElement(EntityType); var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false)); EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty }); EntityType.AddProperty(keyProperty); var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub"); tmpModel.AddElement(defaultContainer); EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType); defaultContainer.AddElement(EntitySet); Action = new EdmAction("TestNamespace", "DoSomething", null, true, null); Action.AddParameter("p1", new EdmEntityTypeReference(EntityType, false)); tmpModel.AddElement(Action); ActionImport = defaultContainer.AddActionImport("DoSomething", Action); var serviceOperationFunction = new EdmFunction("TestNamespace", "ServiceOperation", EdmCoreModel.Instance.GetInt32(true)); defaultContainer.AddFunctionImport("ServiceOperation", serviceOperationFunction); tmpModel.AddElement(serviceOperationFunction); tmpModel.AddElement(new EdmTerm("custom", "DateTimeOffsetAnnotation", EdmPrimitiveTypeKind.DateTimeOffset)); tmpModel.AddElement(new EdmTerm("custom", "DateAnnotation", EdmPrimitiveTypeKind.Date)); tmpModel.AddElement(new EdmTerm("custom", "TimeOfDayAnnotation", EdmPrimitiveTypeKind.TimeOfDay)); EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel); MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") }; MessageReaderSettingsIgnoreInstanceAnnotations = new ODataMessageReaderSettings(); }
public void TryMatch_ReturnsTrue_IfSameFunction() { // Arrange IEdmEntityType returnType = new Mock<IEdmEntityType>().Object; EdmFunction function = new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)); BoundFunctionPathSegment template = new BoundFunctionPathSegment(function, model: null, parameterValues: null); BoundFunctionPathSegment segment = new BoundFunctionPathSegment(function, model: null, parameterValues: null); // Act Dictionary<string, object> values = new Dictionary<string,object>(); bool result = template.TryMatch(segment, values); // Assert Assert.True(result); Assert.Empty(values); }
public void GetParameterValue_Returns_FunctionParameterValue() { // Arrange string parameterName = "Parameter"; EdmModel model = new EdmModel(); var entityType = new EdmEntityType("NS", "Customer"); model.AddElement(entityType); IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false); IEdmTypeReference bindingParamterType = new EdmEntityTypeReference(entityType, isNullable: false); EdmFunction function = new EdmFunction("NS", "Function", returnType); function.AddParameter("bindingParameter", bindingParamterType); function.AddParameter(parameterName, parameterType); model.AddElement(function); IDictionary<string, string> parameterValues = new Dictionary<string, string>(); parameterValues.Add(parameterName, "101"); // Act BoundFunctionPathSegment segment = new BoundFunctionPathSegment(function, model, parameterValues); var result = segment.GetParameterValue(parameterName); // Assert Assert.Equal("System.Int32", result.GetType().FullName); Assert.Equal("101", result.ToString()); }
private static EdmOperationImport CreateFunctionImport( FunctionConfiguration function, EdmEntityContainer container, IEdmTypeReference returnReference, IEdmExpression expression, IEdmPathExpression pathExpression) { EdmFunction operation = new EdmFunction( container.Namespace, function.Name, returnReference, function.IsBindable, pathExpression, function.IsComposable); return new EdmFunctionImport(container, function.Name, operation, expression, includeInServiceDocument: function.IncludeInServiceDocument); }