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, 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); }
public void Singleton_CanOnlyConfigureIdLinkViaIdLinkFactory() { // Arrange ODataModelBuilder builder = GetSingletonModel(); const string ExpectedEditLink = "http://server/service/Exchange"; var product = builder.Singleton <SingletonProduct>("Exchange"); product.HasIdLink(c => new Uri("http://server/service/Exchange"), followsConventions: false); var exchange = builder.Singletons.Single(); var model = builder.GetEdmModel(); var productType = model.SchemaElements.OfType <IEdmEntityType>().Single(); var singleton = model.SchemaElements.OfType <IEdmEntityContainer>().Single().FindSingleton("Exchange"); var singletonInstance = new SingletonProduct { ID = 15 }; var serializerContext = new ODataSerializerContext { Model = model, NavigationSource = singleton }; var entityContext = new ResourceContext(serializerContext, productType.AsReference(), singletonInstance); var linkBuilderAnnotation = new NavigationSourceLinkBuilderAnnotation(exchange); // Act var selfLinks = linkBuilderAnnotation.BuildEntitySelfLinks(entityContext, ODataMetadataLevel.FullMetadata); // Assert Assert.NotNull(selfLinks.IdLink); Assert.Equal(ExpectedEditLink, selfLinks.IdLink.ToString()); Assert.Null(selfLinks.ReadLink); Assert.Null(selfLinks.EditLink); }
public void Singleton_CanOnlyConfigureIdLinkViaIdLinkFactory() { // Arrange ODataModelBuilder builder = GetSingletonModel(); const string ExpectedEditLink = "http://server/service/Exchange"; var product = builder.Singleton<SingletonProduct>("Exchange"); product.HasIdLink(c => new Uri("http://server/service/Exchange"), followsConventions: false); var exchange = builder.Singletons.Single(); var model = builder.GetEdmModel(); var productType = model.SchemaElements.OfType<IEdmEntityType>().Single(); var singleton = model.SchemaElements.OfType<IEdmEntityContainer>().Single().FindSingleton("Exchange"); var singletonInstance = new SingletonProduct { ID = 15 }; var serializerContext = new ODataSerializerContext { Model = model, NavigationSource = singleton }; var entityContext = new EntityInstanceContext(serializerContext, productType.AsReference(), singletonInstance); var linkBuilderAnnotation = new NavigationSourceLinkBuilderAnnotation(exchange); // Act var selfLinks = linkBuilderAnnotation.BuildEntitySelfLinks(entityContext, ODataMetadataLevel.FullMetadata); // Assert Assert.NotNull(selfLinks.IdLink); Assert.Equal(ExpectedEditLink, selfLinks.IdLink.ToString()); Assert.Null(selfLinks.ReadLink); Assert.Null(selfLinks.EditLink); }
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()); }