Esempio n. 1
0
        public void CanWriteEdmSingletonWithEdmEntityTypeButValidationFailed()
        {
            string expected =
                "<?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=\"NS\" xmlns=\"http://docs.oasis-open.org/odata/ns/edm\">" +
                "<EntityContainer Name=\"Default\">" +
                "<Singleton Name=\"VIP\" Type=\"Edm.EntityType\" />" +
                "</EntityContainer>" +
                "</Schema>" +
                "</edmx:DataServices>" +
                "</edmx:Edmx>";

            EdmModel           model     = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer("NS", "Default");
            EdmSingleton       singleton = new EdmSingleton(container, "VIP", EdmCoreModel.Instance.GetEntityType());

            container.AddElement(singleton);
            model.AddElement(container);
            IEnumerable <EdmError> errors;

            Assert.False(model.Validate(out errors));
            Assert.Equal(2, errors.Count());

            string csdlStr = GetCsdl(model, CsdlTarget.OData);

            Assert.Equal(expected, csdlStr);
        }
        public ODataJsonBatchAtomicityGroupTests()
        {
            this.edmModel = new EdmModel();

            this.userType = new EdmEntityType("NS", "User");
            this.userType.AddStructuralProperty("UserPrincipalName", EdmPrimitiveTypeKind.String);
            this.userType.AddStructuralProperty("Surname", EdmPrimitiveTypeKind.String);
            this.userType.AddStructuralProperty("GivenName", EdmPrimitiveTypeKind.String);
            this.userType.AddStructuralProperty("BirthDate", EdmPrimitiveTypeKind.DateTimeOffset);
            this.edmModel.AddElement(this.userType);

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

            this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.userType);
            this.defaultContainer.AddElement(this.singleton);

            textualSampleString = "azAZ09~!@#$%^&*()_+{}|:\"';?/.,\\etc\r\n\b\t\f";

            // Generate array of bytes representing all byte values.
            int binaryBytesLength = 256;

            this.binarySampleBytes = new byte[binaryBytesLength];

            for (int i = 0; i < binaryBytesLength; i++)
            {
                this.binarySampleBytes[i] = (byte)(i & 0xff);
            }

            this.readerSettingsV401    = new ODataMessageReaderSettings();
            readerSettingsV401.Version = ODataVersion.V401;

            this.writerSettingsV401    = new ODataMessageWriterSettings();
            writerSettingsV401.Version = ODataVersion.V401;
        }
        static InstanceAnnotationWriterIntegrationTests()
        {
            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
            });

            ComplexType = new EdmComplexType("TestNamespace", "Address");
            Model.AddElement(ComplexType);

            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);
            Singleton = new EdmSingleton(defaultContainer, "TestSingleton", EntityType);
            Singleton.AddNavigationTarget(resourceNavigationProperty, EntitySet);
            Singleton.AddNavigationTarget(resourceSetNavigationProperty, EntitySet);
            defaultContainer.AddElement(Singleton);
        }
Esempio n. 4
0
        private static EdmModel BuildEdmModel()
        {
            EdmModel model = new EdmModel();

            EdmEntityContainer defaultContainer = new EdmEntityContainer(DefaultNamespace, "DefaultContainer");

            model.AddElement(defaultContainer);

            //Define entity type
            var companyType = new EdmEntityType(DefaultNamespace, "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, "Revenue",
                                                              EdmCoreModel.Instance.GetInt32(true)));
            model.AddElement(companyType);

            //Define singleton
            EdmSingleton company = new EdmSingleton(defaultContainer, "Company", companyType);

            defaultContainer.AddElement(company);

            return(model);
        }
        public void EdmSingletonAnnotationTests()
        {
            EdmModel model = new EdmModel();

            EdmStructuralProperty customerProperty = new EdmStructuralProperty(customerType, "Name", EdmCoreModel.Instance.GetString(false));

            customerType.AddProperty(customerProperty);
            model.AddElement(this.customerType);

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

            EdmTerm term       = new EdmTerm(myNamespace, "SingletonAnnotation", EdmPrimitiveTypeKind.String);
            var     annotation = new EdmVocabularyAnnotation(vipCustomer, term, new EdmStringConstant("Singleton Annotation"));

            model.AddVocabularyAnnotation(annotation);

            var singletonAnnotation = vipCustomer.VocabularyAnnotations(model).Single();

            Assert.Equal(vipCustomer, singletonAnnotation.Target);
            Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name);

            singletonAnnotation = model.FindDeclaredVocabularyAnnotations(vipCustomer).Single();
            Assert.Equal(vipCustomer, singletonAnnotation.Target);
            Assert.Equal("SingletonAnnotation", singletonAnnotation.Term.Name);

            EdmTerm propertyTerm       = new EdmTerm(myNamespace, "SingletonPropertyAnnotation", EdmPrimitiveTypeKind.String);
            var     propertyAnnotation = new EdmVocabularyAnnotation(customerProperty, propertyTerm, new EdmStringConstant("Singleton Property Annotation"));

            model.AddVocabularyAnnotation(propertyAnnotation);

            var singletonPropertyAnnotation = customerProperty.VocabularyAnnotations(model).Single();

            Assert.Equal(customerProperty, singletonPropertyAnnotation.Target);
            Assert.Equal("SingletonPropertyAnnotation", singletonPropertyAnnotation.Term.Name);
        }
Esempio n. 6
0
        public void BuildSelectExpandNode_Works_IfOnlyNavigationPropertyDefinedOnType()
        {
            // Assert
            EdmModel      model  = new EdmModel();
            EdmEntityType entity = new EdmEntityType("NS", "Entity");

            entity.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo
            {
                Name               = "Nav",
                Target             = entity,
                TargetMultiplicity = EdmMultiplicity.One
            });
            model.AddElement(entity);
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmSingleton       singleton = container.AddSingleton("Single", entity);

            container.AddElement(singleton);
            model.AddElement(container);

            // Act
            SelectExpandClause selectExpandClause = new ODataQueryOptionParser(model, entity, singleton,
                                                                               new Dictionary <string, string>
            {
                { "$select", "Nav" }
            }).ParseSelectAndExpand();

            SelectExpandNode selectExpandNode = new SelectExpandNode(selectExpandClause, entity, model);

            // Assert
            Assert.Null(selectExpandNode.SelectedStructuralProperties);
            Assert.Null(selectExpandNode.SelectedComplexTypeProperties);

            Assert.NotNull(selectExpandNode.SelectedNavigationProperties);
            Assert.Single(selectExpandNode.SelectedNavigationProperties);
        }
        public void EdmSingletonBasicAttributeTest()
        {
            EdmSingleton singleton = new EdmSingleton(this.entityContainer, "VIP", customerType);

            Assert.Same(this.entityContainer, singleton.Container);
            Assert.Equal(EdmContainerElementKind.Singleton, singleton.ContainerElementKind);
            Assert.Same(customerType, singleton.EntityType());
        }
Esempio n. 8
0
        public void EdmSingletonBasicAttributeTest()
        {
            EdmSingleton singleton = new EdmSingleton(this.entityContainer, "VIP", customerType);

            singleton.Container.Should().Be(this.entityContainer);
            singleton.ContainerElementKind.Should().Be(EdmContainerElementKind.Singleton);
            singleton.EntityType().Should().Be(customerType);
        }
Esempio n. 9
0
        private void InitializeEdmModel()
        {
            this.edmModel = new EdmModel();

            EdmEntityContainer defaultContainer = new EdmEntityContainer("TestModel", "DefaultContainer");

            this.edmModel.AddElement(defaultContainer);

            EdmComplexType addressType = new EdmComplexType("TestModel", "Address");

            addressType.AddStructuralProperty("Street", EdmCoreModel.Instance.GetString(/*isNullable*/ false));
            addressType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetString(/*isNullable*/ false));

            this.cityType = new EdmEntityType("TestModel", "City");
            EdmStructuralProperty cityIdProperty = cityType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false));

            cityType.AddKeys(cityIdProperty);
            cityType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/ false));
            cityType.AddStructuralProperty("Size", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false));
            cityType.AddStructuralProperty("Restaurants", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetString(/*isNullable*/ false)));
            cityType.AddStructuralProperty("Address", new EdmComplexTypeReference(addressType, true));
            this.edmModel.AddElement(cityType);

            this.capitolCityType = new EdmEntityType("TestModel", "CapitolCity", cityType);
            capitolCityType.AddStructuralProperty("CapitolType", EdmCoreModel.Instance.GetString(/*isNullable*/ false));
            this.edmModel.AddElement(capitolCityType);

            EdmEntityType         districtType       = new EdmEntityType("TestModel", "District");
            EdmStructuralProperty districtIdProperty = districtType.AddStructuralProperty("Id", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false));

            districtType.AddKeys(districtIdProperty);
            districtType.AddStructuralProperty("Name", EdmCoreModel.Instance.GetString(/*isNullable*/ false));
            districtType.AddStructuralProperty("Zip", EdmCoreModel.Instance.GetInt32(/*isNullable*/ false));
            this.edmModel.AddElement(districtType);

            cityType.AddBidirectionalNavigation(
                new EdmNavigationPropertyInfo {
                Name = "Districts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many
            },
                new EdmNavigationPropertyInfo {
                Name = "City", Target = cityType, TargetMultiplicity = EdmMultiplicity.One
            });

            cityType.NavigationProperties().Single(np => np.Name == "Districts");
            capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo {
                Name = "CapitolDistrict", Target = districtType, TargetMultiplicity = EdmMultiplicity.One
            });
            capitolCityType.AddUnidirectionalNavigation(new EdmNavigationPropertyInfo {
                Name = "OutlyingDistricts", Target = districtType, TargetMultiplicity = EdmMultiplicity.Many
            });

            this.citySet = defaultContainer.AddEntitySet("Cities", cityType);
            defaultContainer.AddEntitySet("Districts", districtType);

            this.singletonCity = defaultContainer.AddSingleton("SingletonCity", cityType);
        }
        public void KindPropertyReturnsSingleton()
        {
            // Arrange
            EdmEntityContainer           container = new EdmEntityContainer("NS", "Default");
            EdmSingleton                 me        = new EdmSingleton(container, "Me", _simpleKeyEntityType);
            ODataNavigationSourceSegment nsSegment = new ODataNavigationSourceSegment(me);
            ODataPath path = new ODataPath(nsSegment);

            // Act & Assert
            Assert.Equal(ODataPathKind.Singleton, path.Kind);
        }
        public void TryTranslateSingletonSegmentTemplate_ThrowsArgumentNull_Context()
        {
            // Arrange
            EdmEntityType            entityType       = new EdmEntityType("NS", "entity");
            IEdmEntityContainer      container        = new EdmEntityContainer("NS", "default");
            IEdmSingleton            singleton        = new EdmSingleton(container, "singleton", entityType);
            SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton);

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => singletonSegment.TryTranslate(null), "context");
        }
Esempio n. 12
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 CtorSingletonSegmentTemplate_SetsProperties()
        {
            // Arrange & Act
            EdmEntityType            entityType       = new EdmEntityType("NS", "entity");
            IEdmEntityContainer      container        = new EdmEntityContainer("NS", "default");
            IEdmSingleton            singleton        = new EdmSingleton(container, "singleton", entityType);
            SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton);

            // Assert
            Assert.NotNull(singletonSegment.Segment);
            Assert.Same(singleton, singletonSegment.Singleton);
        }
Esempio n. 14
0
        /// <summary>Adds a singleton to the metadata definition.</summary>
        /// <param name="name">The name of the singleton to add.</param>
        /// <param name="entityType">The type of entity in the singleton.</param>
        /// <returns>The newly created singleton.</returns>
        public IEdmSingleton AddSingleton(string name, IEdmEntityType entityType)
        {
            if (entityType.TypeKind != EdmTypeKind.Entity)
            {
                throw new ArgumentException("The type specified as the base type of a singleton is not an entity type.");
            }

            EdmSingleton singleton = new EdmSingleton(this, name, entityType);

            this.SetAnnotationValue <IEdmSingleton>(entityType, singleton);
            this.singletons.Add(name, singleton);
            return(singleton);
        }
Esempio n. 15
0
        public void GetEdmType_Returns_SingletonEntityType()
        {
            // Arrange
            Mock <IEdmEntityContainer> edmContainer = new Mock <IEdmEntityContainer>();
            Mock <IEdmEntityType>      entityType   = new Mock <IEdmEntityType>();
            IEdmSingleton edmSingleton = new EdmSingleton(edmContainer.Object, "singleton", entityType.Object);

            // Act
            SingletonPathSegment segment = new SingletonPathSegment(edmSingleton);

            // Assert
            Assert.Same(entityType.Object, segment.GetEdmType(previousEdmType: null));
        }
        public void GetTemplatesSingletonSegmentTemplate_ReturnsTemplates()
        {
            // Assert
            EdmEntityType            entityType       = new EdmEntityType("NS", "entity");
            IEdmEntityContainer      container        = new EdmEntityContainer("NS", "default");
            IEdmSingleton            singleton        = new EdmSingleton(container, "singleton", entityType);
            SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton);

            // Act & Assert
            IEnumerable <string> templates = singletonSegment.GetTemplates();
            string template = Assert.Single(templates);

            Assert.Equal("/singleton", template);
        }
        private void StreamTestSetting()
        {
            referencedModel = new EdmModel();

            this.webType = new EdmEntityType("NS", "Web");
            this.webType.AddStructuralProperty("Logo", EdmPrimitiveTypeKind.Stream);
            referencedModel.AddElement(this.webType);

            this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub");
            referencedModel.AddElement(defaultContainer);
            this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", referencedModel);
            this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType);
            this.defaultContainer.AddElement(this.singleton);
        }
        private void MediaEntrySetSetting()
        {
            referencedModel = new EdmModel();

            this.webType = new EdmEntityType("NS", "Web", null, /*isAbstract*/ false, /*isOpen*/ false, /*hasStream*/ true);
            referencedModel.AddElement(this.webType);

            this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub");
            referencedModel.AddElement(defaultContainer);

            this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", referencedModel);
            this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType);
            this.defaultContainer.AddElement(this.singleton);
        }
        public void GenerateFunctionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType_ForSingleton()
        {
            // Arrange
            IEdmSingleton me                = new EdmSingleton(_model.Container, "Me", _model.SpecialCustomer);
            var           request           = RequestFactory.CreateFromModel(_model.Model);
            var           serializerContext = ODataSerializerContextFactory.Create(_model.Model, me, request);
            var           entityContext     = new ResourceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 });

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

            // Assert
            Assert.Equal("http://localhost/Me/NS.Customer/NS.IsUpgradedWithParam(city=@city)", link.AbsoluteUri);
        }
Esempio n. 20
0
        public void GenerateSelfLink_WorksToGenerateExpectedSelfLink_ForSingleton(bool includeCast, string expectedIdLink)
        {
            // Arrange
            IEdmSingleton mary              = new EdmSingleton(_model.EntityContainer, "Mary", _customer);
            var           request           = RequestFactory.Create(_model);
            var           serializerContext = ODataSerializerContextFactory.Create(_model, mary, request);
            var           entityContext     = new ResourceContext(serializerContext, _specialCustomer.AsReference(), new { ID = 42 });

            // Act
            var idLink = entityContext.GenerateSelfLink(includeCast);

            // Assert
            Assert.Equal(expectedIdLink, idLink.ToString());
        }
Esempio n. 21
0
        public void CommonSingletonSegmentTemplateProperties_ReturnsAsExpected()
        {
            // Assert
            EdmEntityType            entityType       = new EdmEntityType("NS", "entity");
            IEdmEntityContainer      container        = new EdmEntityContainer("NS", "default");
            IEdmSingleton            singleton        = new EdmSingleton(container, "singleton", entityType);
            SingletonSegmentTemplate singletonSegment = new SingletonSegmentTemplate(singleton);

            // Act & Assert
            Assert.Equal("singleton", singletonSegment.Literal);
            Assert.Equal(ODataSegmentKind.Singleton, singletonSegment.Kind);
            Assert.True(singletonSegment.IsSingle);
            Assert.Same(entityType, singletonSegment.EdmType);
            Assert.Same(singleton, singletonSegment.NavigationSource);
        }
Esempio n. 22
0
        static AsyncRoundtripJsonLightTests()
        {
            userModel = new EdmModel();

            testType = new EdmEntityType("NS", "Test");
            testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
            testType.AddStructuralProperty("Dummy", EdmPrimitiveTypeKind.String);
            userModel.AddElement(testType);

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

            singleton = new EdmSingleton(defaultContainer, "MySingleton", testType);
            defaultContainer.AddElement(singleton);
        }
Esempio n. 23
0
        public MultipartMixedBatchDependsOnIdsTests()
        {
            this.userModel = new EdmModel();

            this.webType = new EdmEntityType("NS", "Web");
            this.webType.AddStructuralProperty("WebId", EdmPrimitiveTypeKind.Int32);
            this.webType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            this.userModel.AddElement(this.webType);

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

            this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType);
            this.defaultContainer.AddElement(this.singleton);
        }
        private void InitializeEdmModel()
        {
            this.userModel = new EdmModel();

            testType = new EdmEntityType("NS", "Test");
            testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
            this.userModel.AddElement(testType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");

            this.userModel.AddElement(defaultContainer);

            this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.testType);
            defaultContainer.AddElement(this.singleton);
        }
Esempio n. 25
0
        public void GenerateNavigationLink_WorksToGenerateExpectedNavigationLink_ForSingleton(bool includeCast, string expectedNavigationLink)
        {
            // Arrange
            IEdmSingleton          mary              = new EdmSingleton(_model.EntityContainer, "Mary", _customer);
            var                    request           = RequestFactory.Create(_model);
            var                    serializerContext = ODataSerializerContextFactory.Create(_model, mary, request);
            var                    entityContext     = new ResourceContext(serializerContext, _specialCustomer.AsReference(), new { ID = 42 });
            IEdmNavigationProperty ordersProperty    = _customer.NavigationProperties().Single();

            // Act
            Uri uri = entityContext.GenerateNavigationPropertyLink(ordersProperty, includeCast);

            // Assert
            Assert.Equal(expectedNavigationLink, uri.AbsoluteUri);
        }
        static ODataAsynchronousReaderTests()
        {
            userModel = new EdmModel();

            testType = new EdmEntityType("NS", "Test");
            testType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
            userModel.AddElement(testType);

            var defaultContainer = new EdmEntityContainer("NS", "DefaultContainer");

            userModel.AddElement(defaultContainer);

            singleton = new EdmSingleton(defaultContainer, "MySingleton", testType);
            defaultContainer.AddElement(singleton);
        }
Esempio n. 27
0
        public void GetNavigationSourceLinkBuilder_After_SetNavigationSourceLinkBuilder_OnSingleton()
        {
            // Arrange
            IEdmModel          model      = new EdmModel();
            EdmEntityContainer container  = new EdmEntityContainer("NS", "Container");
            EdmEntityType      entityType = new EdmEntityType("NS", "Entity");
            IEdmSingleton      singleton  = new EdmSingleton(container, "Singleton", entityType);
            NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation();

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

            // Assert
            Assert.Same(linkBuilder, result);
        }
        public ODataJsonLightSingletonWriterTests()
        {
            referencedModel = new EdmModel();

            this.webType = new EdmEntityType("NS", "Web");
            this.webType.AddStructuralProperty("WebId", EdmPrimitiveTypeKind.Int32);
            this.webType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
            referencedModel.AddElement(this.webType);

            this.defaultContainer = new EdmEntityContainer("NS", "DefaultContainer_sub");
            referencedModel.AddElement(defaultContainer);

            this.userModel = TestUtils.WrapReferencedModelsToMainModel("NS", "DefaultContainer", referencedModel);
            this.singleton = new EdmSingleton(defaultContainer, "MySingleton", this.webType);
            this.defaultContainer.AddElement(this.singleton);
        }
        public void GenerateActionLink_GeneratesLinkWithDownCast_IfElementTypeDerivesFromBindingParameterType_ForSingleton()
        {
            // Arrange
            IEdmSingleton      me      = new EdmSingleton(_model.Container, "Me", _model.SpecialCustomer);
            HttpRequestMessage request = GetODataRequest(_model.Model);
            var serializerContext      = new ODataSerializerContext {
                Model = _model.Model, NavigationSource = me, Url = request.GetUrlHelper()
            };
            var entityContext = new EntityInstanceContext(serializerContext, _model.SpecialCustomer.AsReference(), new { ID = 42 });

            // Act
            Uri link = entityContext.GenerateActionLink(_model.UpgradeCustomer);

            // Assert
            Assert.Equal("http://localhost/Me/NS.Customer/upgrade", link.AbsoluteUri);
        }
Esempio n. 30
0
        public void ODataPathSegmentHandler_Handles_SingletonSegment()
        {
            // Arrange
            ODataPathSegmentHandler handler = new ODataPathSegmentHandler();

            EdmEntityContainer entityContainer = new EdmEntityContainer("NS", "Default");
            EdmEntityType      customer        = new EdmEntityType("NS", "Customer");
            EdmSingleton       me      = entityContainer.AddSingleton("me", customer);
            SingletonSegment   segment = new SingletonSegment(me);

            // Act
            handler.Handle(segment);

            // Assert
            Assert.Equal("me", handler.PathLiteral);
            Assert.Same(me, handler.NavigationSource);
        }