private static ODataEntry CreateEntryWithKeyAsSegmentConvention(bool addAnnotation, bool? useKeyAsSegment)
        {
            var model = new EdmModel();
            var container = new EdmEntityContainer("Fake", "Container");
            model.AddElement(container);
            if (addAnnotation)
            {
                model.AddVocabularyAnnotation(new EdmAnnotation(container, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));                
            }
            
            EdmEntityType entityType = new EdmEntityType("Fake", "FakeType");
            entityType.AddKeys(entityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            model.AddElement(entityType);

            var entitySet = new EdmEntitySet(container, "FakeSet", entityType);
            container.AddElement(entitySet);

            var metadataContext = new ODataMetadataContext(
                true,
                ODataReaderBehavior.DefaultBehavior.OperationsBoundToEntityTypeMustBeContainerQualified,
                new EdmTypeReaderResolver(model, ODataReaderBehavior.DefaultBehavior),
                model,
                new Uri("http://temp.org/$metadata"),
                null /*requestUri*/);

            var thing = new ODataEntry {Properties = new[] {new ODataProperty {Name = "Id", Value = 1}}};
            thing.SetAnnotation(new ODataTypeAnnotation(entitySet, entityType));
            thing.MetadataBuilder = metadataContext.GetEntityMetadataBuilderForReader(new TestJsonLightReaderEntryState { Entry = thing, SelectedProperties = new SelectedPropertiesNode("*")}, useKeyAsSegment);
            return thing;
        }
        static InstanceAnnotationsReaderIntegrationTests()
        {
            EdmModel modelTmp = new EdmModel();
            EntityType = new EdmEntityType("TestNamespace", "TestEntityType");
            modelTmp.AddElement(EntityType);

            var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false));
            EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty });
            EntityType.AddProperty(keyProperty);
            var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
            var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many });

            var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer_sub");
            modelTmp.AddElement(defaultContainer);
            EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType);
            EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet);
            EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet);
            defaultContainer.AddElement(EntitySet);

            Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType);
            Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet);
            Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet);
            defaultContainer.AddElement(Singleton);

            ComplexType = new EdmComplexType("TestNamespace", "TestComplexType");
            ComplexType.AddProperty(new EdmStructuralProperty(ComplexType, "StringProperty", EdmCoreModel.Instance.GetString(false)));
            modelTmp.AddElement(ComplexType);

            Model = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", modelTmp);
        }
Пример #3
0
        /// <summary>
        /// Creates and adds an entity set to this entity container.
        /// </summary>
        /// <param name="name">Name of the entity set.</param>
        /// <param name="elementType">The entity type of the elements in this entity set.</param>
        /// <returns>Created entity set.</returns>
        public virtual EdmEntitySet AddEntitySet(string name, IEdmEntityType elementType)
        {
            EdmEntitySet entitySet = new EdmEntitySet(this, name, elementType);

            this.AddElement(entitySet);
            return(entitySet);
        }
        static ODataFeedAndEntryTypeContextTests()
        {
            Model = new EdmModel();
            EntitySetElementType = new EdmEntityType("ns", "Customer");
            ExpectedEntityType = new EdmEntityType("ns", "VipCustomer", EntitySetElementType);
            ActualEntityType = new EdmEntityType("ns", "DerivedVipCustomer", ExpectedEntityType);

            EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "DefaultContainer");
            Model.AddElement(defaultContainer);
            Model.AddVocabularyAnnotation(new EdmAnnotation(defaultContainer, UrlConventionsConstants.ConventionTerm, UrlConventionsConstants.KeyAsSegmentAnnotationValue));

            EntitySet = new EdmEntitySet(defaultContainer, "Customers", EntitySetElementType);
            Model.AddElement(EntitySetElementType);
            Model.AddElement(ExpectedEntityType);
            Model.AddElement(ActualEntityType);
            defaultContainer.AddElement(EntitySet);

            SerializationInfo = new ODataFeedAndEntrySerializationInfo { NavigationSourceName = "MyCustomers", NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer" };
            SerializationInfoWithEdmUnknowEntitySet = new ODataFeedAndEntrySerializationInfo() { NavigationSourceName = null, NavigationSourceEntityTypeName = "ns.MyCustomer", ExpectedTypeName = "ns.MyVipCustomer", NavigationSourceKind = EdmNavigationSourceKind.UnknownEntitySet };
            TypeContextWithoutModel = ODataFeedAndEntryTypeContext.Create(SerializationInfo, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            TypeContextWithModel = ODataFeedAndEntryTypeContext.Create(/*serializationInfo*/null, EntitySet, EntitySetElementType, ExpectedEntityType, Model, throwIfMissingTypeInfo: true);
            TypeContextWithEdmUnknowEntitySet = ODataFeedAndEntryTypeContext.Create(SerializationInfoWithEdmUnknowEntitySet, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            BaseTypeContextThatThrows = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: true);
            BaseTypeContextThatWillNotThrow = ODataFeedAndEntryTypeContext.Create(serializationInfo: null, navigationSource: null, navigationSourceEntityType: null, expectedEntityType: null, model: Model, throwIfMissingTypeInfo: false);
        }
Пример #5
0
        public void EdmSingletonBasicNavigationPropertyBindingTest()
        {
            var internalOrderProperty = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo(){Name = "InternalOrder", Target = this.orderType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne});
            var externalOrderProperty = customerType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo(){Name = "ExternalOrders", Target = this.orderType, TargetMultiplicity = EdmMultiplicity.Many});
            var customerProductProperty = customerType.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo() { Name = "Products", Target = this.productType, TargetMultiplicity = EdmMultiplicity.Many }, 
                new EdmNavigationPropertyInfo() { Name = "Buyer", Target = this.customerType, TargetMultiplicity = EdmMultiplicity.One });


            var orderSet = new EdmEntitySet(this.entityContainer, "Orders", this.orderType);
            var productSet = new EdmEntitySet(this.entityContainer, "Products", this.productType);

            var vipCustomer = new EdmSingleton(this.entityContainer, "VIP", this.customerType);

            vipCustomer.NavigationPropertyBindings.Should().HaveCount(0);

            vipCustomer.AddNavigationTarget(internalOrderProperty, orderSet);
            vipCustomer.AddNavigationTarget(externalOrderProperty, orderSet);
            vipCustomer.AddNavigationTarget(customerProductProperty, productSet);

            vipCustomer.NavigationPropertyBindings.Should().HaveCount(3)
                .And.Contain(m => m.NavigationProperty == internalOrderProperty && m.Target == orderSet)
                .And.Contain(m => m.NavigationProperty == externalOrderProperty && m.Target == orderSet)
                .And.Contain(m=>m.NavigationProperty ==  customerProductProperty && m.Target == productSet);

            vipCustomer.FindNavigationTarget(internalOrderProperty).Should().Be(orderSet);
            vipCustomer.FindNavigationTarget(externalOrderProperty).Should().Be(orderSet);
            vipCustomer.FindNavigationTarget(customerProductProperty).Should().Be(productSet);

            productSet.AddNavigationTarget(customerProductProperty.Partner, vipCustomer);
            productSet.FindNavigationTarget(customerProductProperty.Partner).Should().Be(vipCustomer);
        }
Пример #6
0
 public void TestEntityType()
 {
     var container = new EdmEntityContainer("NS", "C");
     var entityType = new EdmEntityType("NS", "People");
     var entitySet = new EdmEntitySet(container, "Peoples", entityType);
     Assert.AreEqual(entityType, entitySet.EntityType());
     var singleton = new EdmSingleton(container, "Boss", entityType);
     Assert.AreEqual(entityType, singleton.EntityType());
 }
        public void GetEntitySetLinkBuilder_ReturnsDefaultEntitySetBuilder_IfNotSet()
        {
            IEdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmEntityType entityType = new EdmEntityType("NS", "Entity");
            IEdmEntitySet entitySet = new EdmEntitySet(container, "EntitySet", entityType);

            Assert.NotNull(model.GetEntitySetLinkBuilder(entitySet));
        }
        public void Initialize()
        {
            this.model = new EdmModel();

            EdmComplexType personalInfo = new EdmComplexType(MyNameSpace, "PersonalInfo");
            personalInfo.AddStructuralProperty("Age", EdmPrimitiveTypeKind.Int16);
            personalInfo.AddStructuralProperty("Email", EdmPrimitiveTypeKind.String);
            personalInfo.AddStructuralProperty("Tel", EdmPrimitiveTypeKind.String);
            personalInfo.AddStructuralProperty("ID", EdmPrimitiveTypeKind.Guid);

            EdmComplexType derivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedPersonalInfo", personalInfo);
            derivedPersonalInfo.AddStructuralProperty("Hobby", EdmPrimitiveTypeKind.String);

            EdmComplexType derivedDerivedPersonalInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedPersonalInfo", derivedPersonalInfo);
            derivedDerivedPersonalInfo.AddStructuralProperty("Education", EdmPrimitiveTypeKind.String);

            EdmComplexType subjectInfo = new EdmComplexType(MyNameSpace, "Subject");
            subjectInfo.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            subjectInfo.AddStructuralProperty("Score", EdmPrimitiveTypeKind.Int16);

            EdmComplexType derivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedSubject", subjectInfo);
            derivedSubjectInfo.AddStructuralProperty("Teacher", EdmPrimitiveTypeKind.String);

            EdmComplexType derivedDerivedSubjectInfo = new EdmComplexType(MyNameSpace, "DerivedDerivedSubject", derivedSubjectInfo);
            derivedDerivedSubjectInfo.AddStructuralProperty("Classroom", EdmPrimitiveTypeKind.String);

            EdmCollectionTypeReference subjectsCollection = new EdmCollectionTypeReference(new EdmCollectionType(new EdmComplexTypeReference(subjectInfo, isNullable: true)));

            studentInfo = new EdmEntityType(MyNameSpace, "Student");
            studentInfo.AddStructuralProperty("Info", new EdmComplexTypeReference(personalInfo, isNullable: false));
            studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Subjects", subjectsCollection));

            // enum with flags
            var enumFlagsType = new EdmEnumType(MyNameSpace, "ColorFlags", isFlags: true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4));
            studentInfo.AddStructuralProperty("ClothesColors", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEnumTypeReference(enumFlagsType, true))));

            EdmCollectionTypeReference hobbiesCollection = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(isNullable: false)));
            studentInfo.AddProperty(new EdmStructuralProperty(studentInfo, "Hobbies", hobbiesCollection));

            model.AddElement(enumFlagsType);
            model.AddElement(studentInfo);
            model.AddElement(personalInfo);
            model.AddElement(derivedPersonalInfo);
            model.AddElement(derivedDerivedPersonalInfo);
            model.AddElement(subjectInfo);
            model.AddElement(derivedSubjectInfo);
            model.AddElement(derivedDerivedSubjectInfo);

            IEdmEntityContainer defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");
            model.AddElement(defaultContainer);

            this.studentSet = new EdmEntitySet(defaultContainer, "MySet", this.studentInfo);
        }
Пример #9
0
        public static IEdmModel CreateServiceEdmModel(string ns)
        {
            EdmModel model = new EdmModel();
            var defaultContainer = new EdmEntityContainer(ns, "PerfInMemoryContainer");
            model.AddElement(defaultContainer);

            var personType = new EdmEntityType(ns, "Person");
            var personIdProperty = new EdmStructuralProperty(personType, "PersonID", EdmCoreModel.Instance.GetInt32(false));
            personType.AddProperty(personIdProperty);
            personType.AddKeys(new IEdmStructuralProperty[] { personIdProperty });
            personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "MiddleName", EdmCoreModel.Instance.GetString(true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Age", EdmCoreModel.Instance.GetInt32(false)));
            model.AddElement(personType);

            var simplePersonSet = new EdmEntitySet(defaultContainer, "SimplePeopleSet", personType);
            defaultContainer.AddElement(simplePersonSet);

            var largetPersonSet = new EdmEntitySet(defaultContainer, "LargePeopleSet", personType);
            defaultContainer.AddElement(largetPersonSet);

            var addressType = new EdmComplexType(ns, "Address");
            addressType.AddProperty(new EdmStructuralProperty(addressType, "Street", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "PostalCode", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(addressType);

            var companyType = new EdmEntityType(ns, "Company");
            var companyId = new EdmStructuralProperty(companyType, "CompanyID", EdmCoreModel.Instance.GetInt32(false));
            companyType.AddProperty(companyId);
            companyType.AddKeys(companyId);
            companyType.AddProperty(new EdmStructuralProperty(companyType, "Name", EdmCoreModel.Instance.GetString(true)));
            companyType.AddProperty(new EdmStructuralProperty(companyType, "Address", new EdmComplexTypeReference(addressType, true)));
            companyType.AddProperty(new EdmStructuralProperty(companyType, "Revenue", EdmCoreModel.Instance.GetInt32(false)));

            model.AddElement(companyType);

            var companySet = new EdmEntitySet(defaultContainer, "CompanySet", companyType);
            defaultContainer.AddElement(companySet);

            var companyEmployeeNavigation = companyType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo()
            {
                Name = "Employees",
                Target = personType,
                TargetMultiplicity = EdmMultiplicity.Many
            });
            companySet.AddNavigationTarget(companyEmployeeNavigation, largetPersonSet);

            // ResetDataSource
            var resetDataSourceAction = new EdmAction(ns, "ResetDataSource", null, false, null);
            model.AddElement(resetDataSourceAction);
            defaultContainer.AddActionImport(resetDataSourceAction);

            return model;
        }
        public static IEdmModel CreateModel(string ns)
        {
            EdmModel model = new EdmModel();
            var defaultContainer = new EdmEntityContainer(ns, "DefaultContainer");
            model.AddElement(defaultContainer);

            var addressType = new EdmComplexType(ns, "Address");
            addressType.AddProperty(new EdmStructuralProperty(addressType, "Road", EdmCoreModel.Instance.GetString(false)));
            addressType.AddProperty(new EdmStructuralProperty(addressType, "City", EdmCoreModel.Instance.GetString(false)));
            model.AddElement(addressType);

            var personType = new EdmEntityType(ns, "Person");
            var personIdProperty = new EdmStructuralProperty(personType, "PersonId", EdmCoreModel.Instance.GetInt32(false));
            personType.AddProperty(personIdProperty);
            personType.AddKeys(new IEdmStructuralProperty[] { personIdProperty });
            personType.AddProperty(new EdmStructuralProperty(personType, "FirstName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "LastName", EdmCoreModel.Instance.GetString(false)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Address", new EdmComplexTypeReference(addressType, true)));
            personType.AddProperty(new EdmStructuralProperty(personType, "Descriptions", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)))));

            model.AddElement(personType);
            var peopleSet = new EdmEntitySet(defaultContainer, "People", personType);
            defaultContainer.AddElement(peopleSet);

            var numberComboType = new EdmComplexType(ns, "NumberCombo");
            numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Small", EdmCoreModel.Instance.GetInt32(false)));
            numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Middle", EdmCoreModel.Instance.GetInt64(false)));
            numberComboType.AddProperty(new EdmStructuralProperty(numberComboType, "Large", EdmCoreModel.Instance.GetDecimal(false)));
            model.AddElement(numberComboType);

            var productType = new EdmEntityType(ns, "Product");
            var productIdProperty = new EdmStructuralProperty(productType, "ProductId", EdmCoreModel.Instance.GetInt32(false));
            productType.AddProperty(productIdProperty);
            productType.AddKeys(new IEdmStructuralProperty[] { productIdProperty });
            productType.AddProperty(new EdmStructuralProperty(productType, "Quantity", EdmCoreModel.Instance.GetInt64(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "LifeTimeInSeconds", EdmCoreModel.Instance.GetDecimal(false)));
            productType.AddProperty(new EdmStructuralProperty(productType, "TheCombo", new EdmComplexTypeReference(numberComboType, true)));
            productType.AddProperty(new EdmStructuralProperty(productType, "LargeNumbers", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetDecimal(false)))));

            model.AddElement(productType);
            var productsSet = new EdmEntitySet(defaultContainer, "Products", productType);
            defaultContainer.AddElement(productsSet);

            var productsProperty = personType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name = "Products",
                Target = productType,
                TargetMultiplicity = EdmMultiplicity.Many
            });
            peopleSet.AddNavigationTarget(productsProperty, productsSet);

            IEnumerable<EdmError> errors;
            model.Validate(out errors);

            return model;
        }
 static ODataJsonLightReaderIntegrationTests()
 {
     EdmModel tmp = new EdmModel();
     EntityType = new EdmEntityType("Namespace", "EntityType");
     EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub");
     EntitySet = edmEntityContainer.AddEntitySet("EntitySet", EntityType);
     tmp.AddElement(edmEntityContainer);
     tmp.Fixup();
     Model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp);
 }
        static JsonFullMetadataLevelTests()
        {
            MetadataDocumentUri = new Uri("http://host/service.svc/$metadata", UriKind.Absolute);

            referencedModel = new EdmModel();
            EdmEntityContainer defaultContainer = new EdmEntityContainer("ns", "defaultContainer_sub");
            EntityType = new EdmEntityType("ns", "EntityType");
            EntitySet = new EdmEntitySet(defaultContainer, "Set", EntityType);
            referencedModel.AddElement(defaultContainer);
            Model = TestUtils.WrapReferencedModelsToMainModel("ns", "defaultContainer", referencedModel);
        }
        public void GetNavigationSourceLinkBuilder_ReturnsDefaultNavigationSourceBuilder_IfNotSet()
        {
            // Arrange
            IEdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmEntityType entityType = new EdmEntityType("NS", "Entity");
            IEdmNavigationSource navigationSource = new EdmEntitySet(container, "EntitySet", entityType);

            // Act & Assert
            Assert.NotNull(model.GetNavigationSourceLinkBuilder(navigationSource));
        }
        static ODataAtomWriterIntegrationTests()
        {
            Model = new EdmModel();
            EntityType = new EdmEntityType("Namespace", "EntityType");

            Model.AddElement(EntityType);
            var entityContainer = new EdmEntityContainer("Namespace", "Container");
            EntitySet = entityContainer.AddEntitySet("EntitySet", EntityType);
            Model.AddElement(entityContainer);
            Model.Fixup();
        }
 public void Initialize()
 {
     EdmModel tmp = new EdmModel();
     this.type = new EdmEntityType("Namespace", "Type");
     this.type.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo() { Target = this.type, TargetMultiplicity = EdmMultiplicity.Many, Name = "NavProp" });
     this.type.AddProperty(new EdmStructuralProperty(this.type, "PrimitiveProp", EdmCoreModel.Instance.GetInt32(false)));
     tmp.AddElement(this.type);
     EdmEntityContainer edmEntityContainer = new EdmEntityContainer("Namespace", "Container_sub");
     this.entitySet = edmEntityContainer.AddEntitySet("EntitySet", this.type);
     tmp.AddElement(edmEntityContainer);
     this.model = TestUtils.WrapReferencedModelsToMainModel("Namespace", "Container", tmp);
 }
        public void Init()
        {
            var entityContainer = new EdmEntityContainer("MyNamespace", "MyThing");

            var entityType = new EdmEntityType("MyNamespace", "EntityType");
            entityType.AddKeys(new EdmStructuralProperty(entityType, "Id", EdmCoreModel.Instance.GetInt32(false)));

            this.entitySet = this.entitySet = new EdmEntitySet(entityContainer, "EntitySet", entityType);
            this.structure = new EdmStructuredValueSimulator(entityType, new Dictionary<string, IEdmValue> { { "Id", EdmValueUtils.ConvertPrimitiveValue(1, null).Value } });

            this.metadataBuilder = new ConventionalODataEntityMetadataBuilder(new Uri("http://test/"), ((IEdmEntitySet)this.entitySet).Name, this.structure, DataServiceUrlConventions.Default);
        }
Пример #17
0
        public void EnsureActionImportIsAddedAndWithCorrectEntitySetExpression()
        {
            EdmEntityContainer container = new EdmEntityContainer("Default", "Container");
            EdmAction action = new EdmAction("DS", "TestAction", EdmCoreModel.Instance.GetBoolean(false));
            var edmEntitySet = new EdmEntitySet(container, "EntitySet", new EdmEntityType("DS", "TestEntity"));
            var entitySetExpression = new EdmEntitySetReferenceExpression(edmEntitySet);
            var actionImport = container.AddActionImport("OtherName", action, entitySetExpression);

            actionImport.Action.Should().Be(action);
            actionImport.Name.Should().Be("OtherName");
            actionImport.EntitySet.Should().Be(entitySetExpression);
            container.Elements.ToArray()[0].Should().Be(actionImport);
        }
Пример #18
0
        //// TODO: Add in-stream error tests

        /// <summary>
        /// Creates an empty model so that the JSON lite serializer won't complain.
        /// </summary>
        /// <param name="entitySet">An entity set in the generated model.</param>
        private EdmModel CreateErrorTestModel(out EdmEntitySet entitySet)
        {
            EdmModel model = new EdmModel();

            var customer = new EdmEntityType("TestModel", "Customer");
            model.AddElement(customer);

            var container = new EdmEntityContainer("TestModel", "DefaultContainer");
            model.AddElement(container);
            
            entitySet = container.AddEntitySet("Customers", customer);

            return model;
        }
        public AsyncBatchRoundtripJsonLightTests()
        {
            this.userModel = new EdmModel();

            this.customerType = new EdmEntityType("MyNS", "Customer");
            this.customerType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String);
            this.customerType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            this.userModel.AddElement(this.customerType);

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

            this.customers = this.defaultContainer.AddEntitySet("Customers", customerType);
        }
        public void GetNavigationSourceLinkBuilder_After_SetNavigationSourceLinkBuilder_OnEntitySet()
        {
            // Arrange
            IEdmModel model = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmEntityType entityType = new EdmEntityType("NS", "Entity");
            IEdmEntitySet entitySet = new EdmEntitySet(container, "EntitySet", entityType);
            NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation();

            // Act
            model.SetNavigationSourceLinkBuilder(entitySet, linkBuilder);
            var result = model.GetNavigationSourceLinkBuilder(entitySet);

            // Assert
            Assert.Same(linkBuilder, result);
        }
        public ODataAtomReaderEnumIntegrationTests()
        {
            this.userModel = 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));
            this.userModel.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));
            this.userModel.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)));
            this.userModel.AddElement(myComplexType);
            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.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
            defaultContainer.AddEntitySet(this.entitySet.Name, this.entityType);
            this.userModel.AddElement(defaultContainer);
        }
        static DeltaLinkWriterIntegrationTests()
        {
            Model = new EdmModel();
            EntityType = new EdmEntityType("TestNamespace", "TestEntityType");
            Model.AddElement(EntityType);

            var keyProperty = new EdmStructuralProperty(EntityType, "ID", EdmCoreModel.Instance.GetInt32(false));
            EntityType.AddKeys(new IEdmStructuralProperty[] { keyProperty });
            EntityType.AddProperty(keyProperty);
            var resourceNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
            var resourceSetNavigationProperty = EntityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "ResourceSetNavigationProperty", Target = EntityType, TargetMultiplicity = EdmMultiplicity.Many });

            var defaultContainer = new EdmEntityContainer("TestNamespace", "DefaultContainer");
            Model.AddElement(defaultContainer);
            EntitySet = new EdmEntitySet(defaultContainer, "TestEntitySet", EntityType);
            EntitySet.AddNavigationTarget(resourceNavigationProperty, EntitySet);
            EntitySet.AddNavigationTarget(resourceSetNavigationProperty, EntitySet);
            defaultContainer.AddElement(EntitySet);
        }
Пример #23
0
        public void Init()
        {
            this.clientEdmModel = new ClientEdmModel(ODataProtocolVersion.V4);
            this.entityDescriptor = new EntityDescriptor(this.clientEdmModel) { Entity = new Customer() };

            var serverType = new EdmEntityType("FQ.NS", "MyServerType");
            serverType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation", Target = serverType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
            this.serverTypeName = ((IEdmSchemaElement)serverType).FullName();
            var serverContainer = new EdmEntityContainer("FQ.NS", "MyContainer");
            this.serverEntitySet = serverContainer.AddEntitySet("MyEntitySet", serverType);

            var serverModel = new EdmModel();
            serverModel.AddElement(serverType);
            serverModel.AddElement(serverContainer);

            this.ctx = new DataServiceContext(new Uri("http://temp.org/"), ODataProtocolVersion.V4, this.clientEdmModel);
            this.ctx.Format.UseJson(serverModel);
            this.testSubject = new RequestInfo(ctx);
        }
        public EnumFilterFunctionalTests()
        {
            // set up the edm model etc
            this.userModel = new EdmModel();

            var enumType = new EdmEnumType("NS", "Color", EdmPrimitiveTypeKind.Int32, false);
            var red = new EdmEnumMember(enumType, "Red", new EdmIntegerConstant(1));
            enumType.AddMember(red);
            enumType.AddMember("Green", new EdmIntegerConstant(2));
            enumType.AddMember("Blue", new EdmIntegerConstant(3));
            enumType.AddMember("White", new EdmIntegerConstant(-10));

            // add to model
            this.userModel.AddElement(enumType);

            // add enum property
            this.entityType = new EdmEntityType("NS", "MyEntityType", isAbstract: false, isOpen: true, baseType: null);
            var enumTypeReference = new EdmEnumTypeReference(enumType, true);
            this.entityType.AddProperty(new EdmStructuralProperty(this.entityType, "Color", enumTypeReference));

            // enum with flags
            var enumFlagsType = new EdmEnumType("NS", "ColorFlags", EdmPrimitiveTypeKind.Int64, true);
            enumFlagsType.AddMember("Red", new EdmIntegerConstant(1L));
            enumFlagsType.AddMember("Green", new EdmIntegerConstant(2L));
            enumFlagsType.AddMember("Blue", new EdmIntegerConstant(4L));
            enumFlagsType.AddMember("GreenRed", new EdmIntegerConstant(3L));

            // add to model
            this.userModel.AddElement(enumFlagsType);

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

            this.userModel.AddElement(this.entityType);

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

            this.entitySet = new EdmEntitySet(defaultContainer, "MySet", this.entityType);
            defaultContainer.AddElement(this.entitySet);
        }
        static ODataEntityReferenceLinksTests()
        {
            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, "Customers", EntityType);
            defaultContainer.AddElement(EntitySet);

            EdmModel = TestUtils.WrapReferencedModelsToMainModel("TestNamespace", "DefaultContainer", tmpModel);
            MessageReaderSettingsReadAndValidateCustomInstanceAnnotations = new ODataMessageReaderSettings { ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*") };
       }
        public ExpandAndSelectPathExtractingTests()
        {
            this.baseType = new EdmEntityType("FQ.NS", "Base");
            this.baseType.AddKeys(this.baseType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32));
            var baseNavigation1 = this.baseType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation1", Target = this.baseType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });
            var baseNavigation2 = this.baseType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "Navigation2", Target = this.baseType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });

            this.derivedType = new EdmEntityType("FQ.NS", "Derived", this.baseType);
            this.derivedType.AddStructuralProperty("Derived", EdmPrimitiveTypeKind.Int32);
            var derivedNavigation = this.derivedType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo { Name = "DerivedNavigation", Target = this.derivedType, TargetMultiplicity = EdmMultiplicity.ZeroOrOne });

            var container = new EdmEntityContainer("FQ.NS", "Container");
            this.entitySet = container.AddEntitySet("Entities", this.baseType);
            this.entitySet.AddNavigationTarget(baseNavigation1, this.entitySet);
            this.entitySet.AddNavigationTarget(baseNavigation2, this.entitySet);
            this.entitySet.AddNavigationTarget(derivedNavigation, this.entitySet);

            this.model = new EdmModel();
            this.model.AddElement(this.baseType);
            this.model.AddElement(this.derivedType);
            this.model.AddElement(container);
        }
Пример #27
0
        public void VerifyAnnotationComputedConcurrency()
        {
            var model = new EdmModel();
            var entity = new EdmEntityType("NS1", "Product");
            var entityId = entity.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(false));
            entity.AddKeys(entityId);
            EdmStructuralProperty name1 = entity.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(false));
            EdmStructuralProperty timeVer = entity.AddStructuralProperty("UpdatedTime", EdmCoreModel.Instance.GetDate(false));
            model.AddElement(entity);

            SetComputedAnnotation(model, entityId);  // semantic meaning is V3's 'Identity' for Key profperty
            SetComputedAnnotation(model, timeVer);   // semantic meaning is V3's 'Computed' for non-key profperty

            var entityContainer = new EdmEntityContainer("NS1", "Container");
            model.AddElement(entityContainer);
            EdmEntitySet set1 = new EdmEntitySet(entityContainer, "Products", entity);
            model.SetOptimisticConcurrencyAnnotation(set1, new IEdmStructuralProperty[] { entityId, timeVer });
            entityContainer.AddElement(set1);

            string csdlStr = GetEdmx(model, EdmxTarget.OData);
            Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-16""?><edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx""><edmx:DataServices><Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm""><EntityType Name=""Product""><Key><PropertyRef Name=""Id"" /></Key><Property Name=""Id"" Type=""Edm.Int32"" Nullable=""false""><Annotation Term=""Org.OData.Core.V1.Computed"" Bool=""true"" /></Property><Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" /><Property Name=""UpdatedTime"" Type=""Edm.Date"" Nullable=""false""><Annotation Term=""Org.OData.Core.V1.Computed"" Bool=""true"" /></Property></EntityType><EntityContainer Name=""Container""><EntitySet Name=""Products"" EntityType=""NS1.Product""><Annotation Term=""Org.OData.Core.V1.OptimisticConcurrency""><Collection><PropertyPath>Id</PropertyPath><PropertyPath>UpdatedTime</PropertyPath></Collection></Annotation></EntitySet></EntityContainer></Schema></edmx:DataServices></edmx:Edmx>", csdlStr);
        }
        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 WriterStreamPropertiesTests()
        {
            Uri baseUri = new Uri("http://www.odata.org/", UriKind.Absolute);
            Uri relativeReadLinkUri = new Uri("readlink", UriKind.RelativeOrAbsolute);
            Uri relativeEditLinkUri = new Uri("editlink", UriKind.RelativeOrAbsolute);
            Uri absoluteReadLinkUri = new Uri(baseUri, relativeReadLinkUri.OriginalString);
            Uri absoluteEditLinkUri = new Uri(baseUri, relativeEditLinkUri.OriginalString);

            string contentType = "application/binary";
            string etag = "\"myetagvalue\"";
            string streamPropertyName = "stream1";

            var namedStreamProperties = new[]
            {
                // with only read link
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, ContentType = contentType}},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, ContentType = contentType}},
                // with only edit link
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = relativeEditLinkUri }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = relativeEditLinkUri, ContentType = contentType }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = relativeEditLinkUri, ContentType = contentType, ETag = etag }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = absoluteEditLinkUri }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = absoluteEditLinkUri, ContentType = contentType }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { EditLink = absoluteEditLinkUri, ContentType = contentType, ETag = etag }},
                // with both edit and read link
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, EditLink = relativeEditLinkUri }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType}},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = relativeReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType, ETag = etag }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, EditLink = relativeEditLinkUri }},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType}},
                new ODataProperty { Name = streamPropertyName, Value = new ODataStreamReferenceValue { ReadLink = absoluteReadLinkUri, EditLink = relativeEditLinkUri, ContentType = contentType, ETag = etag }},
            };

            var testCases = namedStreamProperties.Select(property =>
            {
                var propertyName = property.Name;
                var streamReferenceValue = (ODataStreamReferenceValue)property.Value;
                return new StreamPropertyTestCase
                {
                    NamedStreamProperty = property,
                    GetExpectedAtomPayload = (testConfiguration) =>
                        {
                            return
                                (streamReferenceValue.ReadLink == null
                                    ? string.Empty
                                    : (
                                        "<link rel=\"http://docs.oasis-open.org/odata/ns/mediaresource/" + property.Name + "\" " +
                                        (streamReferenceValue.ContentType == null ? string.Empty : "type=\"" + streamReferenceValue.ContentType + "\" ") +
                                        "title=\"" + property.Name + "\" " +
                                        "href=\"" + (((ODataStreamReferenceValue)property.Value).ReadLink.IsAbsoluteUri ? absoluteReadLinkUri.OriginalString : relativeReadLinkUri.OriginalString) + "\" " +
                                        "xmlns=\"" + TestAtomConstants.AtomNamespace + "\" />")) +

                                (streamReferenceValue.EditLink == null
                                    ? string.Empty
                                    : (
                                        "<link rel=\"http://docs.oasis-open.org/odata/ns/edit-media/" + property.Name + "\" " +
                                        (streamReferenceValue.ContentType == null ? string.Empty : "type=\"" + streamReferenceValue.ContentType + "\" ") +
                                        "title=\"" + property.Name + "\" " +
                                        "href=\"" + (((ODataStreamReferenceValue)property.Value).EditLink.IsAbsoluteUri ? absoluteEditLinkUri.OriginalString : relativeEditLinkUri.OriginalString) + "\" " +
                                        (streamReferenceValue.ETag == null ? string.Empty : "m:etag=\"" + streamReferenceValue.ETag.Replace("\"", "&quot;") + "\" xmlns:m=\"" + TestAtomConstants.ODataMetadataNamespace + "\" ") +
                                        "xmlns=\"" + TestAtomConstants.AtomNamespace + "\" />"));
                        },
                    GetExpectedJsonLightPayload = (testConfiguration) =>
                        {
                            return JsonLightWriterUtils.CombineProperties(
                                (streamReferenceValue.EditLink == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"" + absoluteEditLinkUri.OriginalString + "\"")),
                                (streamReferenceValue.ReadLink == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaReadLinkAnnotationName) + "\":\"" + absoluteReadLinkUri.OriginalString + "\"")),
                                (streamReferenceValue.ContentType == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaContentTypeAnnotationName) + "\":\"" + streamReferenceValue.ContentType + "\"")),
                                (streamReferenceValue.ETag == null ? string.Empty : ("\"" + JsonLightUtils.GetPropertyAnnotationName(propertyName, JsonLightConstants.ODataMediaETagAnnotationName) + "\":\"" + streamReferenceValue.ETag.Replace("\"", "\\\"") + "\"")));
                        },
                };
            });

            var testDescriptors = testCases.SelectMany(testCase =>
                {
                    EdmModel model = new EdmModel();
                    
                    EdmEntityType edmEntityType = new EdmEntityType("TestModel", "StreamPropertyEntityType");
                    EdmStructuralProperty edmStructuralProperty= edmEntityType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32, false);
                    edmEntityType.AddKeys(new IEdmStructuralProperty[]{edmStructuralProperty});
                    model.AddElement(edmEntityType);

                    EdmEntityContainer edmEntityContainer = new EdmEntityContainer("TestModel", "DefaultContainer");
                    model.AddElement(edmEntityContainer);

                    EdmEntitySet edmEntitySet = new EdmEntitySet(edmEntityContainer, "StreamPropertyEntitySet", edmEntityType);
                    edmEntityContainer.AddElement(edmEntitySet);

                    ODataEntry entry = new ODataEntry()
                    {
                        Id = ObjectModelUtils.DefaultEntryId,
                        ReadLink = ObjectModelUtils.DefaultEntryReadLink,
                        TypeName = edmEntityType.FullName()
                    };
                    
                    var streamReference = (ODataStreamReferenceValue)testCase.NamedStreamProperty.Value;
                    bool needBaseUri = (streamReference.ReadLink != null && !streamReference.ReadLink.IsAbsoluteUri) || (streamReference.EditLink != null && !streamReference.EditLink.IsAbsoluteUri);
                    entry.Properties = new ODataProperty[] { testCase.NamedStreamProperty };

                    var resultDescriptor = new PayloadWriterTestDescriptor<ODataItem>(
                        this.Settings,
                        entry,
                        (testConfiguration) =>
                        {
                            if (testConfiguration.Format == ODataFormat.Atom)
                            {
                                return new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                                {
                                    Xml = "<NamedStream>" + testCase.GetExpectedAtomPayload(testConfiguration) + "</NamedStream>",
                                    FragmentExtractor = result => result,
                                };
                            }
                            else if (testConfiguration.Format == ODataFormat.Json)
                            {
                                return new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                                {
                                    Json = string.Join(
                                        "$(NL)",
                                        "{",
                                        testCase.GetExpectedJsonLightPayload(testConfiguration),
                                        "}"),
                                    FragmentExtractor = result => result.RemoveAllAnnotations(true),
                                };
                            }
                            else
                            {
                                throw new NotSupportedException("Unsupported ODataFormat found: " + testConfiguration.Format.ToString());
                            }
                        })
                        {
                            Model = model,
                            PayloadEdmElementContainer = edmEntityContainer,
                            PayloadEdmElementType = edmEntityType,
                        };

                    var resultTestCases = new List<StreamPropertyTestDescriptor>();
                    if (needBaseUri)
                    {
                        resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = baseUri, TestDescriptor = resultDescriptor });
                    }
                    else
                    {
                        resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = null, TestDescriptor = resultDescriptor });
                        resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = baseUri, TestDescriptor = resultDescriptor });
                        resultTestCases.Add(new StreamPropertyTestDescriptor { BaseUri = new Uri("http://mybaseuri/", UriKind.Absolute), TestDescriptor = resultDescriptor });
                    }

                    return resultTestCases;
                });

            var testDescriptorBaseUriPairSet = testDescriptors.SelectMany(descriptor =>
                WriterPayloads.NamedStreamPayloads(descriptor.TestDescriptor).Select(namedStreamPayload =>
                     new Tuple<PayloadWriterTestDescriptor<ODataItem>, Uri>(namedStreamPayload, descriptor.BaseUri)));

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptorBaseUriPairSet,
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent,
                (testDescriptorBaseUriPair, testConfiguration) =>
                {
                    var testDescriptor = testDescriptorBaseUriPair.Item1;

                    if (testDescriptor.IsGeneratedPayload && testConfiguration.Format == ODataFormat.Json)
                    {
                        return;
                    }

                    ODataMessageWriterSettings settings = testConfiguration.MessageWriterSettings.Clone();
                    settings.PayloadBaseUri = testDescriptorBaseUriPair.Item2;
                    settings.SetServiceDocumentUri(ServiceDocumentUri);

                    WriterTestConfiguration config =
                        new WriterTestConfiguration(testConfiguration.Format, settings, testConfiguration.IsRequest, testConfiguration.Synchronous);

                    if (testConfiguration.IsRequest)
                    {
                        ODataEntry payloadEntry = (ODataEntry)testDescriptor.PayloadItems[0];
                        ODataProperty firstStreamProperty = payloadEntry.Properties.Where(p => p.Value is ODataStreamReferenceValue).FirstOrDefault();
                        this.Assert.IsNotNull(firstStreamProperty, "firstStreamProperty != null");

                        testDescriptor = new PayloadWriterTestDescriptor<ODataItem>(testDescriptor)
                        {
                            ExpectedResultCallback = tc => new WriterTestExpectedResults(this.Settings.ExpectedResultSettings)
                            {
                                ExpectedException2 = ODataExpectedExceptions.ODataException("WriterValidationUtils_StreamPropertyInRequest", firstStreamProperty.Name)
                            }
                        };
                    }

                    TestWriterUtils.WriteAndVerifyODataPayload(testDescriptor, config, this.Assert, this.Logger);
                });
        }
        public void GenerateFunctionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType()
        {
            // Arrange
            IEdmEntitySet specialCustomers = new EdmEntitySet(_model.Container, "SpecialCustomers", _model.SpecialCustomer);
            HttpRequestMessage request = GetODataRequest(_model.Model);
            var serializerContext = new ODataSerializerContext { Model = _model.Model, NavigationSource = specialCustomers, Url = request.GetUrlHelper() };
            var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 });

            // Act
            Uri link = entityContext.GenerateFunctionLink(_model.IsCustomerUpgraded);

            // Assert
            Assert.Equal("http://localhost/SpecialCustomers(42)/NS.Customer/IsUpgradedWithParam(entity=@entity,city=@city)",
                link.AbsoluteUri);
        }
        public void Constructor_TakingEdmTypeAndPath_SetsProperties()
        {
            // Arrange
            IEdmModel model = new EdmModel();
            IEdmEntityType entityType = new Mock<IEdmEntityType>().Object;
            IEdmEntityContainer entityContiner = new Mock<IEdmEntityContainer>().Object;
            EdmEntitySet entitySet = new EdmEntitySet(entityContiner, "entitySet", entityType);
            ODataPath path = new ODataPath(new EntitySetPathSegment(entitySet)); 

            // Act
            ODataQueryContext context = new ODataQueryContext(model, entityType, path);

            // Assert
            Assert.Same(model, context.Model);
            Assert.Same(entityType, context.ElementType);
            Assert.Same(entitySet, context.NavigationSource);
            Assert.Null(context.ElementClrType);
        }