public void CanConfigureAllLinksViaIdLink()
        {
            // Arrange
            ODataModelBuilder builder = GetCommonModel();
            var expectedEditLink = "http://server/service/Products(15)";

            var products = builder.EntitySet<EntitySetLinkConfigurationTest_Product>("Products");
            products.HasIdLink(c =>
                string.Format(
                    "http://server/service/Products({0})",
                    c.GetPropertyValue("ID")
                ),
                followsConventions: false);

            var actor = builder.EntitySets.Single();
            var model = builder.GetEdmModel();
            var productType = model.SchemaElements.OfType<IEdmEntityType>().Single();
            var productsSet = model.SchemaElements.OfType<IEdmEntityContainer>().Single().EntitySets().Single();
            var productInstance = new EntitySetLinkConfigurationTest_Product { ID = 15 };
            var serializerContext = new ODataSerializerContext { Model = model, EntitySet = productsSet };
            var entityContext = new EntityInstanceContext(serializerContext, productType.AsReference(), productInstance);
            var entitySetLinkBuilderAnnotation = new EntitySetLinkBuilderAnnotation(actor);

            // Act
            var selfLinks = entitySetLinkBuilderAnnotation.BuildEntitySelfLinks(entityContext, ODataMetadataLevel.Default);

            // Assert
            Assert.NotNull(selfLinks.EditLink);
            Assert.Equal(expectedEditLink, selfLinks.EditLink.ToString());
            Assert.NotNull(selfLinks.ReadLink);
            Assert.Equal(expectedEditLink, selfLinks.ReadLink.ToString());
            Assert.NotNull(selfLinks.IdLink);
            Assert.Equal(expectedEditLink, selfLinks.IdLink);
        }
        public void CanConfigureAllLinksViaEditLink()
        {
            // Arrange
            ODataModelBuilder builder = GetCommonModel();
            var expectedEditLink = "http://server/service/Products(15)";

            var products = builder.EntitySet<EntitySetLinkConfigurationTest_Product>("Products");
            products.HasEditLink(c => new Uri(
                string.Format(
                    "http://server/service/Products({0})",
                    c.EntityInstance.ID
                )
            ));

            var actor = builder.EntitySets.Single();
            var model = builder.GetEdmModel();
            var productType = model.SchemaElements.OfType<IEdmEntityType>().Single();
            var productsSet = model.SchemaElements.OfType<IEdmEntityContainer>().Single().EntitySets().Single();
            var productInstance = new EntitySetLinkConfigurationTest_Product { ID = 15 };
            var entityContext = new EntityInstanceContext { EdmModel = model, EntitySet = productsSet, EntityType = productType, EntityInstance = productInstance, UrlHelper = new UrlHelper(new HttpRequestMessage()) };
            var entitySetLinkBuilderAnnotation = new EntitySetLinkBuilderAnnotation(actor);

            // Act
            var editLinkUri = entitySetLinkBuilderAnnotation.BuildEditLink(entityContext);
            var readLinkUri = entitySetLinkBuilderAnnotation.BuildReadLink(entityContext);
            var idLink = entitySetLinkBuilderAnnotation.BuildIdLink(entityContext);

            // Assert
            Assert.NotNull(editLinkUri);
            Assert.Equal(expectedEditLink, editLinkUri.ToString());
            Assert.NotNull(readLinkUri);
            Assert.Equal(expectedEditLink, readLinkUri.ToString());
            Assert.NotNull(idLink);
            Assert.Equal(expectedEditLink, idLink);
        }
        public void CanConfigureLinksIndependently()
        {
            // Arrange
            ODataModelBuilder builder = GetCommonModel();
            var expectedEditLink      = "http://server1/service/Products(15)";
            var expectedReadLink      = "http://server2/service/Products/15";
            var expectedIdLink        = "http://server3/service/Products(15)";

            var products = builder.EntitySet <EntitySetLinkConfigurationTest_Product>("Products");

            products.HasEditLink(c => new Uri(
                                     string.Format(
                                         "http://server1/service/Products({0})",
                                         c.GetPropertyValue("ID")
                                         )
                                     ),
                                 followsConventions: false);
            products.HasReadLink(c => new Uri(
                                     string.Format(
                                         "http://server2/service/Products/15",
                                         c.GetPropertyValue("ID")
                                         )
                                     ),
                                 followsConventions: false);
            products.HasIdLink(c =>
                               new Uri(string.Format(
                                           "http://server3/service/Products({0})",
                                           c.GetPropertyValue("ID"))
                                       ),
                               followsConventions: false
                               );

            var actor           = builder.EntitySets.Single();
            var model           = builder.GetEdmModel();
            var productType     = model.SchemaElements.OfType <IEdmEntityType>().Single();
            var productsSet     = model.SchemaElements.OfType <IEdmEntityContainer>().Single().EntitySets().Single();
            var productInstance = new EntitySetLinkConfigurationTest_Product {
                ID = 15
            };
            var serializerContext = new ODataSerializerContext {
                Model = model, NavigationSource = productsSet
            };
            var entityContext = new ResourceContext(serializerContext, productType.AsReference(), productInstance);

            // Act
            var editLink = actor.GetEditLink().Factory(entityContext);
            var readLink = actor.GetReadLink().Factory(entityContext);
            var idLink   = actor.GetIdLink().Factory(entityContext);

            // Assert
            Assert.NotNull(editLink);
            Assert.Equal(expectedEditLink, editLink.ToString());
            Assert.NotNull(readLink);
            Assert.Equal(expectedReadLink, readLink.ToString());
            Assert.NotNull(idLink);
            Assert.Equal(expectedIdLink, idLink.ToString());
        }
        public void CanConfigureLinksIndependently()
        {
            // Arrange
            ODataModelBuilder builder = GetCommonModel();
            var expectedEditLink      = "http://server1/service/Products(15)";
            var expectedReadLink      = "http://server2/service/Products/15";
            var expectedIdLink        = "http://server3/service/Products(15)";

            var products = builder.EntitySet <EntitySetLinkConfigurationTest_Product>("Products");

            products.HasEditLink(c => new Uri(
                                     string.Format(
                                         "http://server1/service/Products({0})",
                                         c.EntityInstance.ID
                                         )
                                     ));
            products.HasReadLink(c => new Uri(
                                     string.Format(
                                         "http://server2/service/Products/15",
                                         c.EntityInstance.ID
                                         )
                                     ));
            products.HasIdLink(c =>
                               string.Format(
                                   "http://server3/service/Products({0})",
                                   c.EntityInstance.ID
                                   )
                               );

            var actor           = builder.EntitySets.Single();
            var model           = builder.GetEdmModel();
            var productType     = model.SchemaElements.OfType <IEdmEntityType>().Single();
            var productsSet     = model.SchemaElements.OfType <IEdmEntityContainer>().Single().EntitySets().Single();
            var productInstance = new EntitySetLinkConfigurationTest_Product {
                ID = 15
            };
            var entityContext = new EntityInstanceContext {
                EdmModel = model, EntitySet = productsSet, EntityType = productType, EntityInstance = productInstance, UrlHelper = new UrlHelper(new HttpRequestMessage())
            };

            // Act
            var editLink = actor.GetEditLink()(entityContext);
            var readLink = actor.GetReadLink()(entityContext);
            var idLink   = actor.GetIdLink()(entityContext);

            // Assert
            Assert.NotNull(editLink);
            Assert.Equal(expectedEditLink, editLink.ToString());
            Assert.NotNull(readLink);
            Assert.Equal(expectedReadLink, readLink.ToString());
            Assert.NotNull(idLink);
            Assert.Equal(expectedIdLink, idLink);
        }
        public void CanConfigureLinksIndependently()
        {
            // Arrange
            ODataModelBuilder builder = GetCommonModel();
            var expectedEditLink = "http://server1/service/Products(15)";
            var expectedReadLink = "http://server2/service/Products/15";
            var expectedIdLink = "http://server3/service/Products(15)";

            var products = builder.EntitySet<EntitySetLinkConfigurationTest_Product>("Products");
            products.HasEditLink(c => new Uri(
                string.Format(
                    "http://server1/service/Products({0})",
                    c.GetPropertyValue("ID")
                )
            ),
            followsConventions: false);
            products.HasReadLink(c => new Uri(
                string.Format(
                    "http://server2/service/Products/15",
                    c.GetPropertyValue("ID")
                )
            ),
            followsConventions: false);
            products.HasIdLink(c =>
                string.Format(
                    "http://server3/service/Products({0})",
                    c.GetPropertyValue("ID")
                ),
            followsConventions: false
            );

            var actor = builder.EntitySets.Single();
            var model = builder.GetEdmModel();
            var productType = model.SchemaElements.OfType<IEdmEntityType>().Single();
            var productsSet = model.SchemaElements.OfType<IEdmEntityContainer>().Single().EntitySets().Single();
            var productInstance = new EntitySetLinkConfigurationTest_Product { ID = 15 };
            var serializerContext = new ODataSerializerContext { Model = model, EntitySet = productsSet };
            var entityContext = new EntityInstanceContext(serializerContext, productType.AsReference(), productInstance);

            // Act
            var editLink = actor.GetEditLink().Factory(entityContext);
            var readLink = actor.GetReadLink().Factory(entityContext);
            var idLink = actor.GetIdLink().Factory(entityContext);

            // Assert
            Assert.NotNull(editLink);
            Assert.Equal(expectedEditLink, editLink.ToString());
            Assert.NotNull(readLink);
            Assert.Equal(expectedReadLink, readLink.ToString());
            Assert.NotNull(idLink);
            Assert.Equal(expectedIdLink, idLink);
        }
Beispiel #6
0
        public void CanConfigureAllLinksViaIdLink()
        {
            // Arrange
            ODataModelBuilder builder = GetCommonModel();
            var expectedEditLink      = "http://server/service/Products(15)";

            var products = builder.EntitySet <EntitySetLinkConfigurationTest_Product>("Products");

            products.HasIdLink(c =>
                               new Uri(string.Format(
                                           "http://server/service/Products({0})",
                                           c.GetPropertyValue("ID"))
                                       ),
                               followsConventions: false);

            var actor           = builder.EntitySets.Single();
            var model           = builder.GetEdmModel();
            var productType     = model.SchemaElements.OfType <IEdmEntityType>().Single();
            var productsSet     = model.SchemaElements.OfType <IEdmEntityContainer>().Single().EntitySets().Single();
            var productInstance = new EntitySetLinkConfigurationTest_Product {
                ID = 15
            };
            var serializerContext = new ODataSerializerContext {
                Model = model, NavigationSource = productsSet
            };
            var entityContext         = new EntityInstanceContext(serializerContext, productType.AsReference(), productInstance);
            var linkBuilderAnnotation = new NavigationSourceLinkBuilderAnnotation(actor);

            // Act
            var selfLinks = linkBuilderAnnotation.BuildEntitySelfLinks(entityContext, ODataMetadataLevel.Default);

            // Assert
            Assert.NotNull(selfLinks.EditLink);
            Assert.Equal(expectedEditLink, selfLinks.EditLink.ToString());
            Assert.NotNull(selfLinks.ReadLink);
            Assert.Equal(expectedEditLink, selfLinks.ReadLink.ToString());
            Assert.NotNull(selfLinks.IdLink);
            Assert.Equal(expectedEditLink, selfLinks.IdLink.ToString());
        }