public void Init()
        {
            EdmModel model = new EdmModel();

            EdmComplexType complex1 = new EdmComplexType("ns", "complex1");
            complex1.AddProperty(new EdmStructuralProperty(complex1, "p1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            model.AddElement(complex1);            
            
            EdmComplexType complex2 = new EdmComplexType("ns", "complex2");
            complex2.AddProperty(new EdmStructuralProperty(complex2, "p1", EdmCoreModel.Instance.GetInt32(isNullable: false)));
            model.AddElement(complex2);

            EdmComplexTypeReference complex2Reference = new EdmComplexTypeReference(complex2, isNullable: false);
            EdmCollectionType primitiveCollectionType = new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false));
            EdmCollectionType complexCollectionType = new EdmCollectionType(complex2Reference);
            EdmCollectionTypeReference primitiveCollectionTypeReference = new EdmCollectionTypeReference(primitiveCollectionType);
            EdmCollectionTypeReference complexCollectionTypeReference = new EdmCollectionTypeReference(complexCollectionType);

            model.AddElement(new EdmTerm("custom", "int", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "string", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "double", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "bool", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: true)));
            model.AddElement(new EdmTerm("custom", "decimal", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "timespan", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Duration, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "guid", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Guid, isNullable: false)));
            model.AddElement(new EdmTerm("custom", "complex", complex2Reference));
            model.AddElement(new EdmTerm("custom", "primitiveCollection", primitiveCollectionTypeReference));
            model.AddElement(new EdmTerm("custom", "complexCollection", complexCollectionTypeReference));

            this.stream = new MemoryStream();
            this.settings = new ODataMessageWriterSettings { Version = ODataVersion.V4, ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
            this.settings.SetServiceDocumentUri(ServiceDocumentUri);
            this.serializer = new ODataAtomPropertyAndValueSerializer(this.CreateAtomOutputContext(model, this.stream));
        }
Ejemplo n.º 2
0
        public void FindAction_CannotFind_BindableAction_DerivedEntityCollection()
        {
            // Arrange
            var entityCollection = new EdmCollectionType(_entityType);

            // Act & Assert
            Assert.Null(_model.FindAction("NS.ActionBoundToDerivedEntityCollection", entityCollection));
        }
Ejemplo n.º 3
0
        public void CollectionType_IsDeltaFeed_ReturnsFalseForNonDeltaCollectionType()
        {
            IEdmEntityType _entityType = new EdmEntityType("NS", "Entity");
            EdmCollectionType _edmType = new EdmCollectionType(new EdmEntityTypeReference(_entityType, isNullable: true));
            IEdmCollectionTypeReference _edmTypeReference = new EdmCollectionTypeReference(_edmType);

            Assert.False(_edmTypeReference.Definition.IsDeltaFeed());
        }
Ejemplo n.º 4
0
        public void FindAction_CannotFind_BindableAction_DerivedEntityCollection()
        {
            // Arrange
            var entityCollection = new EdmCollectionType(_entityType);
            IEdmEntityContainer container = GetEntityContainer();

            // Act & Assert
            Assert.Null(container.FindAction("ActionBoundToDerivedEntityCollection", bindingParameterType: entityCollection));
        }
Ejemplo n.º 5
0
 public void CalculateBindableOperationsForEntityCollectionTypeWithoutTypeResolver()
 {
     var bindingType = new EdmCollectionType(this.model.FindType("TestModel.Movie").ToTypeReference(nullable:false));
     var bindableOperations = MetadataUtils.CalculateBindableOperationsForType(bindingType, this.model, new EdmTypeReaderResolver(this.model, ODataReaderBehavior.DefaultBehavior));
     Assert.AreEqual(2, bindableOperations.Length);
     foreach (var operation in bindableOperations)
     {
         Assert.AreEqual("RateMultiple", operation.Name);
     }
 }
        public ODataJsonLightReaderEnumIntegrationTests()
        {
            EdmModel tmpModel = new EdmModel();

            // enum without flags
            var enumType = new EdmEnumType("NS", "Color");
            var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1));
            enumType.AddMember(red);
            enumType.AddMember("Green", new EdmIntegerConstant(2));
            enumType.AddMember("Blue", new EdmIntegerConstant(3));
            tmpModel.AddElement(enumType);

            // enum with flags
            var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));
            tmpModel.AddElement(enumFlagsType);

            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            EdmStructuralProperty floatId = new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetSingle(false));
            this.entityType.AddKeys(floatId);
            this.entityType.AddProperty(floatId);
            var enumTypeReference = new EdmEnumTypeReference(enumType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference));
            var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference));

            // enum in complex type
            EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType");
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference));
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false)));
            tmpModel.AddElement(myComplexType);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true)));

            // enum in derived complex type
            EdmComplexType myDerivedComplexType = new EdmComplexType("NS", "MyDerivedComplexType", myComplexType, false);
            myDerivedComplexType.AddProperty(new EdmStructuralProperty(myDerivedComplexType, "MyDerivedColorFlags", new EdmEnumTypeReference(enumFlagsType, false)));
            tmpModel.AddElement(myDerivedComplexType);
            
            // enum in collection type
            EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType)));

            tmpModel.AddElement(this.entityType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub");
            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
            defaultContainer.AddEntitySet(this.entitySet.Name, this.entityType);
            tmpModel.AddElement(defaultContainer);

            this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", tmpModel);
        }
Ejemplo n.º 7
0
        public void FindAction_CanFind_BindableAction_EntityCollection(string segment, bool isDerivedType)
        {
            // Arrange
            IEdmTypeReference entityType = isDerivedType ? _derivedEntityType : _entityType;
            var entityCollection = new EdmCollectionType(entityType);

            // Act
            var result = _model.FindAction(segment, entityCollection);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("NS.ActionBoundToEntityCollection", result.FullName());
        }
Ejemplo n.º 8
0
        public void GetEdmType_ReturnsCollectionCastType_IfPreviousTypeIsCollection()
        {
            // Arrange
            EdmEntityType castType = new EdmEntityType("NS", "Entity");
            EdmCollectionType previousEdmType = new EdmCollectionType(new EdmEntityType("NS", "PreviousType").AsReference());
            CastPathSegment castSegment = new CastPathSegment(castType);

            // Act
            var result = castSegment.GetEdmType(previousEdmType);

            // Assert
            Assert.Equal(EdmTypeKind.Collection, result.TypeKind);
            Assert.Equal(castType, (result as IEdmCollectionType).ElementType.Definition);
        }
Ejemplo n.º 9
0
        public void FindAction_CanFind_BindableAction_EntityCollection(string segment, bool isDerivedType)
        {
            // Arrange
            IEdmTypeReference entityType = isDerivedType ? _derivedEntityType : _entityType;
            var entityCollection = new EdmCollectionType(entityType);
            IEdmEntityContainer container = GetEntityContainer();

            // Act
            var result = container.FindAction(segment, bindingParameterType: entityCollection);

            // Assert
            Assert.NotNull(result);
            Assert.Equal("NS.Name.ActionBoundToEntityCollection", result.Container.FullName() + "." + result.Name);
        }
        public ODataAtomAnnotationReaderTests()
        {
            this.model = new EdmModel();
            this.model.AddElement(new EdmComplexType("foo", "complex"));
            EdmComplexType complexType = new EdmComplexType("ns", "complex");
            this.model.AddElement(complexType);
            EdmComplexTypeReference complexTypeReference = new EdmComplexTypeReference(complexType, isNullable: false);
            EdmCollectionType primitiveCollectionType = new EdmCollectionType(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Guid, isNullable: false));
            EdmCollectionType complexCollectionType = new EdmCollectionType(complexTypeReference);
            EdmCollectionTypeReference primitiveCollectionTypeReference = new EdmCollectionTypeReference(primitiveCollectionType);
            EdmCollectionTypeReference complexCollectionTypeReference = new EdmCollectionTypeReference(complexCollectionType);

            this.model.AddElement(new EdmTerm("custom", "primitive", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, isNullable: false)));
            this.model.AddElement(new EdmTerm("custom", "complex", complexTypeReference));
            this.model.AddElement(new EdmTerm("custom", "primitiveCollection", primitiveCollectionTypeReference));
            this.model.AddElement(new EdmTerm("custom", "complexCollection", complexCollectionTypeReference));

            this.shouldIncludeAnnotation = (annotationName) => true;
        }
        public ODataAtomWriterEnumIntegrationTests()
        {
            this.userModel = new EdmModel();

            var enumType = new EdmEnumType("NS", "Color");
            var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1));
            enumType.AddMember(red);
            enumType.AddMember("Green", new EdmIntegerConstant(2));
            enumType.AddMember("Blue", new EdmIntegerConstant(3));

            // enum with flags
            var enumFlagsType = new EdmEnumType("NS", "ColorFlags", isFlags: true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));

            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            this.entityType.AddKeys(new EdmStructuralProperty(this.entityType, "FloatId", EdmCoreModel.Instance.GetDouble(false)));
            var enumTypeReference = new EdmEnumTypeReference(enumType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference));

            // add enum with flags
            var enumFlagsTypeReference = new EdmEnumTypeReference(enumFlagsType, false);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "ColorFlags", enumFlagsTypeReference));

            // enum in complex type
            EdmComplexType myComplexType = new EdmComplexType("NS", "MyComplexType");
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "MyColorFlags", enumFlagsTypeReference));
            myComplexType.AddProperty(new EdmStructuralProperty(myComplexType, "Height", EdmCoreModel.Instance.GetDouble(false)));
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyComplexType", new EdmComplexTypeReference(myComplexType, true)));

            // enum in collection type
            EdmCollectionType myCollectionType = new EdmCollectionType(enumFlagsTypeReference);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "MyCollectionType", new EdmCollectionTypeReference(myCollectionType)));

            this.userModel.AddElement(this.entityType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");
            this.userModel.AddElement(defaultContainer);

            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
        }
        public CustomersModelWithInheritance()
        {
            EdmModel model = new EdmModel();

            // Enum type simpleEnum
            EdmEnumType simpleEnum = new EdmEnumType("NS", "SimpleEnum");
            simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "First", new EdmIntegerConstant(0)));
            simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Second", new EdmIntegerConstant(1)));
            simpleEnum.AddMember(new EdmEnumMember(simpleEnum, "Third", new EdmIntegerConstant(2)));
            model.AddElement(simpleEnum);

            // complex type address
            EdmComplexType address = new EdmComplexType("NS", "Address");
            address.AddStructuralProperty("Street", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("State", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("ZipCode", EdmPrimitiveTypeKind.String);
            address.AddStructuralProperty("Country", EdmPrimitiveTypeKind.String);
            model.AddElement(address);

            // open complex type "Account"
            EdmComplexType account = new EdmComplexType("NS", "Account", null, false, true);
            account.AddStructuralProperty("Bank", EdmPrimitiveTypeKind.String);
            account.AddStructuralProperty("CardNum", EdmPrimitiveTypeKind.Int64);
            model.AddElement(account);

            EdmComplexType specialAccount = new EdmComplexType("NS", "SpecialAccount", account, false, true);
            specialAccount.AddStructuralProperty("SpecialCard", EdmPrimitiveTypeKind.String);
            model.AddElement(specialAccount);

            // entity type customer
            EdmEntityType customer = new EdmEntityType("NS", "Customer");
            customer.AddKeys(customer.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            IEdmProperty customerName = customer.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            customer.AddStructuralProperty("SimpleEnum", simpleEnum.ToEdmTypeReference(isNullable: false));
            customer.AddStructuralProperty("Address", new EdmComplexTypeReference(address, isNullable: true));
            customer.AddStructuralProperty("Account", new EdmComplexTypeReference(account, isNullable: true));
            IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive(
                EdmPrimitiveTypeKind.String,
                isNullable: true);
            var city = customer.AddStructuralProperty(
                "City",
                primitiveTypeReference,
                defaultValue: null,
                concurrencyMode: EdmConcurrencyMode.Fixed);
            model.AddElement(customer);

            // derived entity type special customer
            EdmEntityType specialCustomer = new EdmEntityType("NS", "SpecialCustomer", customer);
            specialCustomer.AddStructuralProperty("SpecialCustomerProperty", EdmPrimitiveTypeKind.Guid);
            specialCustomer.AddStructuralProperty("SpecialAddress", new EdmComplexTypeReference(address, isNullable: true));
            model.AddElement(specialCustomer);

            // entity type order (open entity type)
            EdmEntityType order = new EdmEntityType("NS", "Order", null, false, true);
            // EdmEntityType order = new EdmEntityType("NS", "Order");
            order.AddKeys(order.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            order.AddStructuralProperty("City", EdmPrimitiveTypeKind.String);
            order.AddStructuralProperty("Amount", EdmPrimitiveTypeKind.Int32);
            model.AddElement(order);

            // derived entity type special order
            EdmEntityType specialOrder = new EdmEntityType("NS", "SpecialOrder", order, false, true);
            specialOrder.AddStructuralProperty("SpecialOrderProperty", EdmPrimitiveTypeKind.Guid);
            model.AddElement(specialOrder);

            // test entity
            EdmEntityType testEntity = new EdmEntityType("System.Web.OData.Query.Expressions", "TestEntity");
            testEntity.AddStructuralProperty("SampleProperty", EdmPrimitiveTypeKind.Binary);
            model.AddElement(testEntity);

            // containment
            // my order
            EdmEntityType myOrder = new EdmEntityType("NS", "MyOrder");
            myOrder.AddKeys(myOrder.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            myOrder.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(myOrder);

            // order line
            EdmEntityType orderLine = new EdmEntityType("NS", "OrderLine");
            orderLine.AddKeys(orderLine.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Int32));
            orderLine.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            model.AddElement(orderLine);

            EdmNavigationProperty orderLinesNavProp = myOrder.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "OrderLines",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = orderLine,
                    ContainsTarget = true,
                });

           EdmNavigationProperty nonContainedOrderLinesNavProp = myOrder.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "NonContainedOrderLines",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = orderLine,
                    ContainsTarget = false,
                });

            EdmAction tag = new EdmAction("NS", "tag", returnType: null, isBound: true, entitySetPathExpression: null);
            tag.AddParameter("entity", new EdmEntityTypeReference(orderLine, false));
            model.AddElement(tag);

            // entity sets
            EdmEntityContainer container = new EdmEntityContainer("NS", "ModelWithInheritance");
            model.AddElement(container);
            EdmEntitySet customers = container.AddEntitySet("Customers", customer);
            EdmEntitySet orders = container.AddEntitySet("Orders", order);
            EdmEntitySet myOrders = container.AddEntitySet("MyOrders", myOrder);

            // singletons
            EdmSingleton vipCustomer = container.AddSingleton("VipCustomer", customer);
            EdmSingleton mary = container.AddSingleton("Mary", customer);
            EdmSingleton rootOrder = container.AddSingleton("RootOrder", order);

            // annotations
            model.SetOptimisticConcurrencyAnnotation(customers, new[] { city });

            // containment
            IEdmContainedEntitySet orderLines = (IEdmContainedEntitySet)myOrders.FindNavigationTarget(orderLinesNavProp);
            
            // no-containment
            IEdmNavigationSource nonContainedOrderLines = myOrders.FindNavigationTarget(nonContainedOrderLinesNavProp);

            // actions
            EdmAction upgrade = new EdmAction("NS", "upgrade", returnType: null, isBound: true, entitySetPathExpression: null);
            upgrade.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(upgrade);

            EdmAction specialUpgrade =
                new EdmAction("NS", "specialUpgrade", returnType: null, isBound: true, entitySetPathExpression: null);
            specialUpgrade.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
            model.AddElement(specialUpgrade);

            // actions bound to collection
            EdmAction upgradeAll = new EdmAction("NS", "UpgradeAll", returnType: null, isBound: true, entitySetPathExpression: null);
            upgradeAll.AddParameter("entityset",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false))));
            model.AddElement(upgradeAll);

            EdmAction upgradeSpecialAll = new EdmAction("NS", "UpgradeSpecialAll", returnType: null, isBound: true, entitySetPathExpression: null);
            upgradeSpecialAll.AddParameter("entityset",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(specialCustomer, false))));
            model.AddElement(upgradeSpecialAll);

            // functions
            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmTypeReference stringType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false);
            IEdmTypeReference intType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: false);

            EdmFunction IsUpgraded = new EdmFunction(
                "NS",
                "IsUpgraded",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            IsUpgraded.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(IsUpgraded);

            EdmFunction orderByCityAndAmount = new EdmFunction(
                "NS",
                "OrderByCityAndAmount",
                stringType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            orderByCityAndAmount.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            orderByCityAndAmount.AddParameter("city", stringType);
            orderByCityAndAmount.AddParameter("amount", intType);
            model.AddElement(orderByCityAndAmount);

            EdmFunction getOrders = new EdmFunction(
                "NS",
                "GetOrders",
                EdmCoreModel.GetCollection(order.ToEdmTypeReference(false)),
                isBound: true,
                entitySetPathExpression: null,
                isComposable: true);
            getOrders.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            getOrders.AddParameter("parameter", intType);
            model.AddElement(getOrders);

            EdmFunction IsSpecialUpgraded = new EdmFunction(
                "NS",
                "IsSpecialUpgraded",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            IsSpecialUpgraded.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
            model.AddElement(IsSpecialUpgraded);

            EdmFunction getSalary = new EdmFunction(
                "NS",
                "GetSalary",
                stringType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            getSalary.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(getSalary);

            getSalary = new EdmFunction(
                "NS",
                "GetSalary",
                stringType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            getSalary.AddParameter("entity", new EdmEntityTypeReference(specialCustomer, false));
            model.AddElement(getSalary);

            EdmFunction IsAnyUpgraded = new EdmFunction(
                "NS",
                "IsAnyUpgraded",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            EdmCollectionType edmCollectionType = new EdmCollectionType(new EdmEntityTypeReference(customer, false));
            IsAnyUpgraded.AddParameter("entityset", new EdmCollectionTypeReference(edmCollectionType));
            model.AddElement(IsAnyUpgraded);

            EdmFunction isCustomerUpgradedWithParam = new EdmFunction(
                "NS",
                "IsUpgradedWithParam",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            isCustomerUpgradedWithParam.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            isCustomerUpgradedWithParam.AddParameter("city", EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.String, isNullable: false));
            model.AddElement(isCustomerUpgradedWithParam);

            EdmFunction isCustomerLocal = new EdmFunction(
                "NS",
                "IsLocal",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            isCustomerLocal.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            model.AddElement(isCustomerLocal);

            EdmFunction entityFunction = new EdmFunction(
                "NS",
                "GetCustomer",
                returnType,
                isBound: true,
                entitySetPathExpression: null,
                isComposable: false);
            entityFunction.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            entityFunction.AddParameter("customer", new EdmEntityTypeReference(customer, false));
            model.AddElement(entityFunction);

            EdmFunction getOrder = new EdmFunction(
                "NS",
                "GetOrder",
                order.ToEdmTypeReference(false),
                isBound: true,
                entitySetPathExpression: null,
                isComposable: true); // Composable
            getOrder.AddParameter("entity", new EdmEntityTypeReference(customer, false));
            getOrder.AddParameter("orderId", intType);
            model.AddElement(getOrder);

            // functions bound to collection
            EdmFunction isAllUpgraded = new EdmFunction("NS", "IsAllUpgraded", returnType, isBound: true,
                entitySetPathExpression: null, isComposable: false);
            isAllUpgraded.AddParameter("entityset",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(customer, false))));
            isAllUpgraded.AddParameter("param", intType);
            model.AddElement(isAllUpgraded);

            EdmFunction isSpecialAllUpgraded = new EdmFunction("NS", "IsSpecialAllUpgraded", returnType, isBound: true,
                entitySetPathExpression: null, isComposable: false);
            isSpecialAllUpgraded.AddParameter("entityset",
                new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(specialCustomer, false))));
            isSpecialAllUpgraded.AddParameter("param", intType);
            model.AddElement(isSpecialAllUpgraded);

            // navigation properties
            EdmNavigationProperty ordersNavProp = customer.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "Orders",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = order
                });
            mary.AddNavigationTarget(ordersNavProp, orders);
            vipCustomer.AddNavigationTarget(ordersNavProp, orders);
            customers.AddNavigationTarget(ordersNavProp, orders);
            orders.AddNavigationTarget(
                 order.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
                 {
                     Name = "Customer",
                     TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                     Target = customer
                 }),
                customers);

            // navigation properties on derived types.
            EdmNavigationProperty specialOrdersNavProp = specialCustomer.AddUnidirectionalNavigation(
                new EdmNavigationPropertyInfo
                {
                    Name = "SpecialOrders",
                    TargetMultiplicity = EdmMultiplicity.Many,
                    Target = order
                });
            vipCustomer.AddNavigationTarget(specialOrdersNavProp, orders);
            customers.AddNavigationTarget(specialOrdersNavProp, orders);
            orders.AddNavigationTarget(
                 specialOrder.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
                 {
                     Name = "SpecialCustomer",
                     TargetMultiplicity = EdmMultiplicity.ZeroOrOne,
                     Target = customer
                 }),
                customers);
            model.SetAnnotationValue<BindableProcedureFinder>(model, new BindableProcedureFinder(model));

            // set properties
            Model = model;
            Container = container;
            Customer = customer;
            Order = order;
            Address = address;
            Account = account;
            SpecialCustomer = specialCustomer;
            SpecialOrder = specialOrder;
            Orders = orders;
            Customers = customers;
            VipCustomer = vipCustomer;
            Mary = mary;
            RootOrder = rootOrder;
            OrderLine = orderLine;
            OrderLines = orderLines; 
            NonContainedOrderLines = nonContainedOrderLines;
            UpgradeCustomer = upgrade;
            UpgradeSpecialCustomer = specialUpgrade;
            CustomerName = customerName;
            IsCustomerUpgraded = isCustomerUpgradedWithParam;
            IsSpecialCustomerUpgraded = IsSpecialUpgraded;
            Tag = tag;
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates a collection value type for the specified <paramref name="itemTypeReference"/>.
 /// </summary>
 /// <param name="itemTypeReference">The <see cref="IEdmPrimitiveTypeReference"/> for the item type.</param>
 /// <returns>The created <see cref="IEdmCollectionTypeReference"/>.</returns>
 public static IEdmCollectionTypeReference ToCollectionTypeReference(this IEdmPrimitiveTypeReference itemTypeReference)
 {
     IEdmCollectionType collectionType = new EdmCollectionType(itemTypeReference);
     return (IEdmCollectionTypeReference)ToTypeReference(collectionType);
 }
Ejemplo n.º 14
0
        public void NonPrimitiveAsXXXMethods()
        {
            IEdmPrimitiveType intDef = EdmCoreModel.Instance.GetPrimitiveType(EdmPrimitiveTypeKind.Int32);
            IEdmPrimitiveTypeReference intRef = new EdmPrimitiveTypeReference(intDef, false);

            IEdmEntityType entityDef = new EdmEntityType("MyNamespace", "MyEntity");
            IEdmEntityTypeReference entityRef = new EdmEntityTypeReference(entityDef, false);
            IEdmComplexType complexDef = new EdmComplexType("MyNamespace", "MyComplex");
            IEdmComplexTypeReference complexRef = new EdmComplexTypeReference(complexDef, false);
            IEdmCollectionType collectionDef = new EdmCollectionType(intRef);
            IEdmCollectionTypeReference collectionRef = new EdmCollectionTypeReference(collectionDef);

            IEdmCollectionTypeReference badCollectionRef = entityRef.AsCollection();
            IEdmEntityTypeReference badEntityRef = collectionRef.AsEntity();
            IEdmComplexTypeReference badComplexRef = entityRef.AsComplex();
            IEdmEntityReferenceTypeReference badEntityRefRef= entityRef.AsEntityReference();

            Assert.IsTrue(badCollectionRef.IsBad(), "Bad Collection is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badCollectionRef.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("[Collection([UnknownType Nullable=True]) Nullable=True]", badCollectionRef.ToString(), "Correct tostring");

            Assert.IsTrue(badComplexRef.IsBad(), "Bad Complex is Bad");
            Assert.IsTrue(badComplexRef.Definition.IsBad(), "Bad Complex definition is Bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badComplexRef.Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("TypeSemanticsCouldNotConvertTypeReference:[MyNamespace.MyEntity Nullable=False]", badComplexRef.ToString(), "Correct tostring");

            Assert.IsTrue(badEntityRef.IsBad(), "Bad Entity is bad");
            Assert.IsTrue(badEntityRef.Definition.IsBad(), "Bad Entity Definition is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badEntityRef.Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("TypeSemanticsCouldNotConvertTypeReference:[Collection(Edm.Int32) Nullable=False]", badEntityRef.ToString(), "Correct tostring");

            Assert.IsTrue(badEntityRefRef.IsBad(), "Bad Entity Reference is Bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, badEntityRefRef.Errors().First().ErrorCode, "Reference is bad from conversion");
            Assert.AreEqual("[EntityReference(.) Nullable=False]", badEntityRefRef.ToString(), "Correct tostring");

            Assert.IsFalse(entityRef.AsEntity().IsBad(), "Entity converted to Entity is good");
            Assert.IsFalse(complexRef.AsComplex().IsBad(), "Complex converted to complex is good");
            Assert.IsFalse(collectionRef.AsCollection().IsBad(), "Collection converted to collection is good");

            Assert.IsTrue(entityRef.AsStructured().IsEntity(), "Entity as structured is entity");
            Assert.IsFalse(entityRef.AsStructured().IsBad(), "Entity as structured is good");
            Assert.IsTrue(complexRef.AsStructured().IsComplex(), "Complex as structured is complex");
            Assert.IsFalse(complexRef.AsStructured().IsBad(), "Complex as structured is good");
            Assert.IsFalse(collectionRef.AsStructured().IsCollection(), "Collection as structured is not collection");
            Assert.IsTrue(collectionRef.AsStructured().IsBad(), "Collection as structured is bad");
            Assert.IsTrue(collectionRef.AsStructured().Definition.IsBad(), "Collection as structured definition is bad");
            Assert.AreEqual(EdmErrorCode.TypeSemanticsCouldNotConvertTypeReference, collectionRef.AsStructured().Definition.Errors().First().ErrorCode, "Reference is bad from conversion");
        }
Ejemplo n.º 15
0
        public void EqualityCollectionTypeTest()
        {
            var baselineCollectionTypeElement = new EdmEntityType("NS", "Baseline", new EdmEntityType("NS", "foo", null, true, false), true, false);
            var differentCollectionTypeElement = new EdmEntityType("NS", "Baseline", new EdmEntityType("NS", "bar", null, false, false), true, false);

            var baseline = new EdmCollectionType(new EdmEntityTypeReference(baselineCollectionTypeElement, true));
            var match = new EdmCollectionType(new EdmEntityTypeReference(baselineCollectionTypeElement, true));
            var differentCollectionNullibility = new EdmCollectionType(new EdmEntityTypeReference(baselineCollectionTypeElement, false));
            var differentCollectionType = new EdmCollectionType(new EdmEntityTypeReference(differentCollectionTypeElement, true));

            Assert.IsTrue(baseline.IsEquivalentTo(match), "Is the same.");
            Assert.IsFalse(baseline.IsEquivalentTo(differentCollectionNullibility), "Different nullibility.");
            Assert.IsFalse(baseline.IsEquivalentTo(differentCollectionType), "Different collection type element (different obj refs).");
            differentCollectionType = new EdmCollectionType(new EdmEntityTypeReference(baselineCollectionTypeElement, true));
            Assert.IsTrue(baseline.IsEquivalentTo(differentCollectionType), "Different collection types equal on element.");
        }
        public void ShortQualifiedNameForCollectionOfNonPrimitiveTypeShouldBeCollectionOfFullName()
        {
            const string stringOfNamespaceName = "TestModel";
            const string stringOfComplexTypeName = "MyComplexType";
            
            var edmComplexType = new EdmComplexType(stringOfNamespaceName, stringOfComplexTypeName);
            var edmCollectionType = new EdmCollectionType(new EdmComplexTypeReference(edmComplexType, true));

            var stringOfExpectedShortQulifiedName = String.Format("Collection({0}.{1})", stringOfNamespaceName, stringOfComplexTypeName);
            var stringOfObservedShortQulifiedName = edmCollectionType.ODataShortQualifiedName();
            stringOfObservedShortQulifiedName.Should().Be(stringOfExpectedShortQulifiedName);

            const string stringEntityTypeName = "MyEntityType";
            var edmEntityType = new EdmEntityType(stringOfNamespaceName, stringEntityTypeName);
            edmCollectionType = new EdmCollectionType(new EdmEntityTypeReference(edmEntityType, true));

            stringOfExpectedShortQulifiedName = String.Format("Collection({0}.{1})", stringOfNamespaceName, stringEntityTypeName);
            stringOfObservedShortQulifiedName = edmCollectionType.ODataShortQualifiedName();
            stringOfObservedShortQulifiedName.Should().Be(stringOfExpectedShortQulifiedName);
        }
        public void ShortQualifiedNameForCollectionPrimitiveTypeShouldBeCollectionOfName()
        {
            foreach (EdmPrimitiveTypeKind edmPrimitiveTypeKind in Enum.GetValues(typeof(EdmPrimitiveTypeKind)))
            {
                if (EdmPrimitiveTypeKind.None == edmPrimitiveTypeKind)
                    continue;
                var stringOfName = Enum.GetName(typeof(EdmPrimitiveTypeKind), edmPrimitiveTypeKind);
                stringOfName.ToUpper().Should().NotContain("EDM.");

                var stringOfExpectedShortQulifiedName = String.Format("Collection({0})", stringOfName);
                var iEdmPrimitiveType = EdmCoreModel.Instance.GetPrimitiveType(edmPrimitiveTypeKind);
                var edmCollectionType=new EdmCollectionType(new EdmPrimitiveTypeReference(iEdmPrimitiveType,true));
                var stringOfObservedShortQulifiedName = edmCollectionType.ODataShortQualifiedName();
                stringOfObservedShortQulifiedName.Should().Be(stringOfExpectedShortQulifiedName);
            }
        }
Ejemplo n.º 18
0
        public void FindMatchedOperations_CannotFind_BindableFunction_DerivedEntityCollection()
        {
            // Arrange
            var entityCollection = new EdmCollectionType(_entityType);

            // Act & Assert
            Assert.Empty(_model.FindMatchedOperations("NS.FunctionBoundToDerivedEntityCollection",  entityCollection));
        }
Ejemplo n.º 19
0
        public void FindMatchedOperations_DoesNotReturnNonBindableFunction_IfBindingParameterSpecified()
        {
            // Arrange
            var entityCollection = new EdmCollectionType(_entityType);

            // Act & Assert
            Assert.Empty(_model.FindMatchedOperations("NS.NonBindableAction", entityCollection));
            Assert.Empty(_model.FindMatchedOperations("NS.NonBindableAction", _entityType.Definition));
        }
Ejemplo n.º 20
0
        private bool TryCreateTypeNameSegment(ODataPathSegment previous, string identifier, string parenthesisExpression)
        {
            IEdmType targetEdmType;
            if (previous.TargetEdmType == null || (targetEdmType = UriEdmHelpers.FindTypeFromModel(this.configuration.Model, identifier, this.configuration.Resolver)) == null)
            {
                return false;
            }

            // if the new type segment prevents any results from possibly being returned, then short-circuit and throw a 404.
            IEdmType previousEdmType = previous.TargetEdmType;
            Debug.Assert(previousEdmType != null, "previous.TargetEdmType != null");

            if (previousEdmType.TypeKind == EdmTypeKind.Collection)
            {
                previousEdmType = ((IEdmCollectionType)previousEdmType).ElementType.Definition;
            }

            if (!targetEdmType.IsOrInheritsFrom(previousEdmType) && !previousEdmType.IsOrInheritsFrom(targetEdmType))
            {
                throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.RequestUriProcessor_InvalidTypeIdentifier_UnrelatedType(targetEdmType.ODataFullName(), previousEdmType.ODataFullName()));
            }

            // We want the type of the type segment to be a collection if the previous segment was a collection
            IEdmType actualTypeOfTheTypeSegment = targetEdmType;

            if (previous.EdmType.TypeKind == EdmTypeKind.Collection)
            {
                // creating a new collection type here because the type in the request is just the item type, there is no user-provided collection type.
                var actualEntityTypeOfTheTypeSegment = actualTypeOfTheTypeSegment as IEdmEntityType;
                if (actualEntityTypeOfTheTypeSegment != null)
                {
                    actualTypeOfTheTypeSegment = new EdmCollectionType(new EdmEntityTypeReference(actualEntityTypeOfTheTypeSegment, false));
                }
                else
                {
                    throw new ODataException(Strings.PathParser_TypeCastOnlyAllowedAfterEntityCollection(identifier));
                }
            }

            var typeNameSegment = (ODataPathSegment)new TypeSegment(actualTypeOfTheTypeSegment, previous.TargetEdmNavigationSource)
            {
                Identifier = identifier,
                TargetKind = previous.TargetKind,
                SingleResult = previous.SingleResult,
                TargetEdmType = targetEdmType
            };

            this.parsedSegments.Add(typeNameSegment);

            // Key expressions are allowed on Type segments
            this.TryBindKeyFromParentheses(parenthesisExpression);

            return true;
        }
Ejemplo n.º 21
0
        private static IEdmTypeReference GetEdmTypeReference(Dictionary<Type, IEdmType> availableTypes, IEdmTypeConfiguration configuration, bool nullable)
        {
            Contract.Assert(availableTypes != null);

            if (configuration == null)
            {
                return null;
            }

            EdmTypeKind kind = configuration.Kind;
            if (kind == EdmTypeKind.Collection)
            {
                CollectionTypeConfiguration collectionType = (CollectionTypeConfiguration)configuration;
                EdmCollectionType edmCollectionType =
                    new EdmCollectionType(GetEdmTypeReference(availableTypes, collectionType.ElementType, nullable));
                return new EdmCollectionTypeReference(edmCollectionType);
            }
            else
            {
                Type configurationClrType = TypeHelper.GetUnderlyingTypeOrSelf(configuration.ClrType);

                if (!configurationClrType.GetTypeInfo().IsEnum)
                {
                    configurationClrType = configuration.ClrType;
                }

                IEdmType type;

                if (availableTypes.TryGetValue(configurationClrType, out type))
                {
                    if (kind == EdmTypeKind.Complex)
                    {
                        return new EdmComplexTypeReference((IEdmComplexType)type, nullable);
                    }
                    else if (kind == EdmTypeKind.Entity)
                    {
                        return new EdmEntityTypeReference((IEdmEntityType)type, nullable);
                    }
                    else if (kind == EdmTypeKind.Enum)
                    {
                        return new EdmEnumTypeReference((IEdmEnumType)type, nullable);
                    }
                    else
                    {
                        throw Error.InvalidOperation(SRResources.UnsupportedEdmTypeKind, kind.ToString());
                    }
                }
                else if (configuration.Kind == EdmTypeKind.Primitive)
                {
                    PrimitiveTypeConfiguration primitiveTypeConfiguration = configuration as PrimitiveTypeConfiguration;
                    return new EdmPrimitiveTypeReference(primitiveTypeConfiguration.EdmPrimitiveType, nullable);
                }
                else
                {
                    throw Error.InvalidOperation(SRResources.NoMatchingIEdmTypeFound, configuration.FullName);
                }
            }
        }
Ejemplo n.º 22
0
 public void GetClrTypeNameShouldReturnICollectionStructureTemplateForCollectionOfEntityType()
 {
     EdmEntityType entityType = new EdmEntityType("Namespace", "elementName");
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(entityType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmTypeReference collectionTypeReference = new EdmTypeReferenceForTest(collectionType, false);
     ODataT4CodeGenerator.Utils.GetClrTypeName(collectionTypeReference, false, template, context, true, true, true)
         .Should().Be("global::System.Collections.Generic.ICollection<global::NamespacePrefix.elementName>");
 }
Ejemplo n.º 23
0
        public void GetClrTypeNameShouldReturnICollectionStructureTemplateForCollectionOfEnumType()
        {
            EdmEnumType gender = new EdmEnumType("Namespace", "Gender", EdmPrimitiveTypeKind.Byte, true);
            gender.AddMember("Male", new EdmIntegerConstant(1));
            gender.AddMember("Female", new EdmIntegerConstant(2));

            IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(gender, false);
            IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
            IEdmTypeReference collectionTypeReference = new EdmTypeReferenceForTest(collectionType, false);
            ODataT4CodeGenerator.Utils.GetClrTypeName(collectionTypeReference, false, template, context, true, true, true)
                .Should().Be("global::System.Collections.Generic.ICollection<global::NamespacePrefix.Gender>");
        }
Ejemplo n.º 24
0
 public void GetClrTypeNameShouldReturnICollectionStructureTemplateForCollectionOfPrimitiveType()
 {
     EdmPrimitiveType primitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.String);
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(primitiveType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmTypeReference collectionTypeReference = new EdmTypeReferenceForTest(collectionType, false);
     ODataT4CodeGenerator.Utils.GetClrTypeName(collectionTypeReference, false, template, context, true, true, true)
         .Should().Be("global::System.Collections.Generic.ICollection<string>");
 }
Ejemplo n.º 25
0
 public void GetClrTypeNameShouldReturnDataServiceCollectionStructureTemplate()
 {
     EdmEntityType entityType = new EdmEntityType("Namespace", "elementName");
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(entityType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmTypeReference collectionTypeReference = new EdmTypeReferenceForTest(collectionType, false);
     ODataT4CodeGenerator.Utils.GetClrTypeName(collectionTypeReference, true, template, context).Should().Be("global::Microsoft.OData.Client.DataServiceCollection<global::NamespacePrefix.elementName>");
 }
Ejemplo n.º 26
0
 public void GetClrTypeNameShouldReturnObservableCollectionStructureTemplate()
 {
     EdmComplexType complexType = new EdmComplexType("Namespace", "elementName");
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(complexType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmTypeReference collectionTypeReference = new EdmTypeReferenceForTest(collectionType, false);
     ODataT4CodeGenerator.Utils.GetClrTypeName(collectionTypeReference, true, template, context).Should().Be("global::System.Collections.ObjectModel.ObservableCollection<global::NamespacePrefix.elementName>");
 }
Ejemplo n.º 27
0
 public void GetPropertyInitializationValueShouldReturnConstructorWithNoParametersForElementsInEntityTypeButNotUseDataServiceCollection()
 {
     EdmEntityType entityType = new EdmEntityType("Namespace", "elementName");
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(entityType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType);
     EdmPropertyForTest property = new EdmPropertyForTest(new EdmStructruedTypeForTest(), "propertyName", collectionTypeReference);
     ODataT4CodeGenerator.Utils.GetPropertyInitializationValue(property, false, template, context).Should().Be("new global::System.Collections.ObjectModel.Collection<global::NamespacePrefix.elementName>()");
 }
Ejemplo n.º 28
0
 public void GetPropertyInitializationValueShouldReturnConstructorWithDataServiceCollectionConstructorParameters()
 {
     EdmEntityType entityType = new EdmEntityType("Namespace", "elementName");
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(entityType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType);
     EdmPropertyForTest property = new EdmPropertyForTest(new EdmStructruedTypeForTest(), "propertyName", collectionTypeReference);
     ODataT4CodeGenerator.Utils.GetPropertyInitializationValue(property, true, template, context).Should().Be("new global::Microsoft.OData.Client.DataServiceCollection<global::NamespacePrefix.elementName>(null, global::Microsoft.OData.Client.TrackingMode.None)");
 }
Ejemplo n.º 29
0
 public void GetPropertyInitializationValueShouldReturnConstructorWithNoParametersForElementsInPrimitiveType()
 {
     EdmPrimitiveType primitiveType = new EdmPrimitiveType(EdmPrimitiveTypeKind.String);
     IEdmTypeReference elementTypeReference = new EdmTypeReferenceForTest(primitiveType, false);
     IEdmCollectionType collectionType = new EdmCollectionType(elementTypeReference);
     IEdmCollectionTypeReference collectionTypeReference = new EdmCollectionTypeReference(collectionType);
     EdmPropertyForTest property = new EdmPropertyForTest(new EdmStructruedTypeForTest(), "propertyName", collectionTypeReference);
     ODataT4CodeGenerator.Utils.GetPropertyInitializationValue(property, false, template, context).Should().Be("new global::System.Collections.ObjectModel.Collection<string>()");
 }
Ejemplo n.º 30
0
        public void FindMatchedOpeartions_CanFind_BindableFunctions_EntityCollection(string segment, bool isDerivedType)
        {
            // Arrange
            IEdmTypeReference entityType = isDerivedType ? _derivedEntityType : _entityType;
            var entityCollection = new EdmCollectionType(entityType);

            // Act
            var results = _model.FindMatchedOperations(segment, entityCollection);

            // Assert
            Assert.Equal(new[] { "NS.FunctionBoundToEntityCollection" }, results.Select(f => f.FullName()));
        }