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 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 static void SetNavigationSourceLinkBuilder(this IEdmModel model, IEdmNavigationSource navigationSource, NavigationSourceLinkBuilderAnnotation navigationSourceLinkBuilder) { if (model == null) { throw Error.ArgumentNull("model"); } model.SetAnnotationValue(navigationSource, navigationSourceLinkBuilder); }
public void BuildIdLink_Throws_IfIdLinkBuilderIsNull(ODataMetadataLevel metadataLevel) { // Arrange NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act & Assert Assert.Throws<InvalidOperationException>( () => linkBuilder.BuildIdLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel), "No IdLink factory was found. Try calling HasIdLink on the NavigationSourceConfiguration for 'Customers'."); }
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 void Ctor_FollowingConventions_GeneratesSelfLinkWithCast_IfDerivedTypeHasNavigationProperty() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = model.Customers, Url = request.GetUrlHelper() }; ResourceContext instanceContext = new ResourceContext(serializerContext, model.SpecialCustomer.AsReference(), new { ID = 42 }); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(model.Customers, model.Model); var result = linkBuilder.BuildIdLink(instanceContext, ODataMetadataLevel.FullMetadata); // Assert Assert.Equal("http://localhost/Customers(42)/NS.SpecialCustomer", result.ToString()); }
public void CanConfigureReadLinkToNotFollowConventions() { // Arrange Uri idLink = new Uri("http://id_link"); Uri readLink = new Uri("http://read_link"); _entitySet.HasIdLink(new SelfLinkBuilder <Uri>((ctxt) => idLink, followsConventions: true)); _entitySet.HasReadLink(new SelfLinkBuilder <Uri>((ctxt) => readLink, followsConventions: false)); // Act var selfLinks = new NavigationSourceLinkBuilderAnnotation(_entitySet).BuildEntitySelfLinks(new ResourceContext(), ODataMetadataLevel.MinimalMetadata); // Assert Assert.Null(selfLinks.IdLink); Assert.Null(selfLinks.EditLink); Assert.Equal(readLink, selfLinks.ReadLink); }
public void BuildNavigationLink_ReturnsNull(bool followsConventions, ODataMetadataLevel metadataLevel) { // Arrange var navigationProperty = _entitySet.EntityType.AddNavigationProperty(typeof(Customer).GetProperty("Orders"), EdmMultiplicity.Many); IEdmModel model = _modelBuilder.GetEdmModel(); IEdmNavigationProperty edmNavProperty = model.GetEdmTypeReference(typeof(Customer)).AsEntity().DeclaredNavigationProperties().Single(p => p.Name == "Orders"); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); linkBuilder.AddNavigationPropertyLinkBuilder(edmNavProperty, new NavigationLinkBuilder((context, property) => new Uri("http://navigationlink"), followsConventions)); // Act Uri generatedNavigationLink = linkBuilder.BuildNavigationLink(new ResourceContext(), edmNavProperty, (ODataMetadataLevel)metadataLevel); // Assert Assert.Null(generatedNavigationLink); }
public void Ctor_FollowingConventions_GeneratesNavigationLinkWithCast_ForDerivedNavigationProperty() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = model.Customers, Url = request.GetUrlHelper() }; EntityInstanceContext instanceContext = new EntityInstanceContext(serializerContext, model.SpecialCustomer.AsReference(), new { ID = 42 }); IEdmNavigationProperty ordersProperty = model.SpecialCustomer.NavigationProperties().First(p => p.Name == "SpecialOrders"); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(model.Customers, model.Model); Uri result = linkBuilder.BuildNavigationLink(instanceContext, ordersProperty, ODataMetadataLevel.Default); // Assert Assert.Equal("http://localhost/Customers(42)/NS.SpecialCustomer/SpecialOrders", result.AbsoluteUri); }
public void Ctor_FollowingConventions_GeneratesSelfLinkWithoutCast_IfDerivedTypesHaveNoNavigationProperty() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmEntitySet specialCustomers = new EdmEntitySet(model.Container, "SpecialCustomers", model.SpecialCustomer); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = specialCustomers, Url = request.GetUrlHelper() }; EntityInstanceContext instanceContext = new EntityInstanceContext(serializerContext, model.Customer.AsReference(), new { ID = 42 }); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(specialCustomers, model.Model); var result = linkBuilder.BuildIdLink(instanceContext, ODataMetadataLevel.Default); // Assert Assert.Equal("http://localhost/SpecialCustomers(42)", result.ToString()); }
public static NavigationSourceLinkBuilderAnnotation GetNavigationSourceLinkBuilder(this IEdmModel model, IEdmNavigationSource navigationSource) { if (model == null) { throw Error.ArgumentNull("model"); } NavigationSourceLinkBuilderAnnotation annotation = model .GetAnnotationValue<NavigationSourceLinkBuilderAnnotation>(navigationSource); if (annotation == null) { // construct and set a navigation source link builder that follows OData URL conventions. annotation = new NavigationSourceLinkBuilderAnnotation(navigationSource, model); model.SetNavigationSourceLinkBuilder(navigationSource, annotation); } return annotation; }
public void BuildIdLink(bool followsConventions, ODataMetadataLevel metadataLevel, bool linkEmitted) { // Arrange _entitySet.HasIdLink(new SelfLinkBuilder <Uri>((context) => new Uri("http://selflink"), followsConventions)); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act Uri generatedIdLink = linkBuilder.BuildIdLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel); // Assert if (linkEmitted) { Assert.Equal(new Uri("http://selflink"), generatedIdLink); } else { Assert.Null(generatedIdLink); } }
public void BuildReadLink_WhenReadLinkIsNotSameAsEditLink(bool followsConventions, ODataMetadataLevel metadataLevel, bool linkEmitted) { // Arrange _entitySet.HasReadLink(new SelfLinkBuilder <Uri>((context) => new Uri("http://readlink/"), followsConventions)); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act Uri generatedReadLink = linkBuilder.BuildReadLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel, new Uri("http://editLink")); // Assert if (linkEmitted) { Assert.Equal("http://readlink/", generatedReadLink.AbsoluteUri); } else { Assert.Null(generatedReadLink); } }
public void BuildIdLink(bool followsConventions, ODataMetadataLevel metadataLevel, bool linkEmitted) { // Arrange _entitySet.HasIdLink(new SelfLinkBuilder<Uri>((context) => new Uri("http://selflink"), followsConventions)); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act Uri generatedIdLink = linkBuilder.BuildIdLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel); // Assert if (linkEmitted) { Assert.Equal(new Uri("http://selflink"), generatedIdLink); } else { Assert.Null(generatedIdLink); } }
public void Ctor_FollowingConventions_GeneratesNavigationLinkWithoutCast_ForNavigationPropertyOnBaseType() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = model.Customers, Url = request.GetUrlHelper() }; EntityInstanceContext instanceContext = new EntityInstanceContext(serializerContext, model.Customer.AsReference(), new { ID = 42 }); IEdmNavigationProperty ordersProperty = model.Customer.NavigationProperties().First(p => p.Name == "Orders"); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(model.Customers, model.Model); linkBuilder.AddNavigationPropertyLinkBuilder(ordersProperty, new NavigationLinkBuilder((context, property) => context.GenerateNavigationPropertyLink(property, includeCast: false), false)); Uri result = linkBuilder.BuildNavigationLink(instanceContext, ordersProperty, ODataMetadataLevel.MinimalMetadata); // Assert Assert.Equal("http://localhost/Customers(42)/Orders", result.AbsoluteUri); }
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()); }
public void CanConfigureReadLinkToNotFollowConventions() { // Arrange Uri idLink = new Uri("http://id_link"); Uri readLink = new Uri("http://read_link"); _entitySet.HasIdLink(new SelfLinkBuilder<Uri>((ctxt) => idLink, followsConventions: true)); _entitySet.HasReadLink(new SelfLinkBuilder<Uri>((ctxt) => readLink, followsConventions: false)); // Act var selfLinks = new NavigationSourceLinkBuilderAnnotation(_entitySet).BuildEntitySelfLinks(new EntityInstanceContext(), ODataMetadataLevel.MinimalMetadata); // Assert Assert.Null(selfLinks.IdLink); Assert.Null(selfLinks.EditLink); Assert.Equal(readLink, selfLinks.ReadLink); }
public void CreateODataFeed_SetsNextPageLink_WhenWritingTruncatedCollection_ForExpandedProperties() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmCollectionTypeReference customersType = new EdmCollectionTypeReference(new EdmCollectionType(model.Customer.AsReference())); ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider()); SelectExpandClause selectExpandClause = new SelectExpandClause(new SelectItem[0], allSelected: true); IEdmNavigationProperty ordersProperty = model.Customer.NavigationProperties().First(); EntityInstanceContext entity = new EntityInstanceContext { SerializerContext = new ODataSerializerContext { NavigationSource = model.Customers, Model = model.Model } }; ODataSerializerContext nestedContext = new ODataSerializerContext(entity, selectExpandClause, ordersProperty); TruncatedCollection<Order> orders = new TruncatedCollection<Order>(new[] { new Order(), new Order() }, pageSize: 1); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(); linkBuilder.AddNavigationPropertyLinkBuilder(ordersProperty, new NavigationLinkBuilder((entityContext, navigationProperty) => new Uri("http://navigation-link/"), false)); model.Model.SetNavigationSourceLinkBuilder(model.Customers, linkBuilder); model.Model.SetNavigationSourceLinkBuilder(model.Orders, new NavigationSourceLinkBuilderAnnotation()); // Act ODataFeed feed = serializer.CreateODataFeed(orders, _customersType, nestedContext); // Assert Assert.Equal("http://navigation-link/?$skip=1", feed.NextPageLink.AbsoluteUri); }
public void BuildEditLink_WhenEditLinkIsSameAsIdLink_And_IsNotSet(bool followsConventions, ODataMetadataLevel metadataLevel, bool linkEmitted) { // Arrange _entitySet.HasIdLink(new SelfLinkBuilder<string>((context) => "http://selflink/", followsConventions)); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act Uri generatedEditLink = linkBuilder.BuildEditLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel, "http://selflink"); // Assert if (linkEmitted) { Assert.Equal("http://selflink/", generatedEditLink.AbsoluteUri); } else { Assert.Null(generatedEditLink); } }
private static void AddNavigationBindings(NavigationSourceConfiguration configuration, EdmNavigationSource navigationSource, NavigationSourceLinkBuilderAnnotation linkBuilder, ODataModelBuilder builder, Dictionary<Type, IEdmType> edmTypeMap, Dictionary<string, EdmNavigationSource> edmNavigationSourceMap) { foreach (EntityTypeConfiguration entityType in builder.ThisAndBaseAndDerivedTypes(configuration.EntityType)) { foreach (NavigationPropertyConfiguration navigationProperty in entityType.NavigationProperties) { NavigationPropertyBindingConfiguration binding = configuration.FindBinding(navigationProperty); bool isContained = navigationProperty.ContainsTarget; if (binding != null || isContained) { EdmEntityType edmEntityType = edmTypeMap[entityType.ClrType] as EdmEntityType; IEdmNavigationProperty edmNavigationProperty = edmEntityType.NavigationProperties() .Single(np => np.Name == navigationProperty.Name); if (!isContained) { navigationSource.AddNavigationTarget( edmNavigationProperty, edmNavigationSourceMap[binding.TargetNavigationSource.Name]); } NavigationLinkBuilder linkBuilderFunc = configuration.GetNavigationPropertyLink(navigationProperty); if (linkBuilderFunc != null) { linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc); } } } } }
public void BuildEditLink_WhenEditLinkIsSameAsIdLink_And_IsNotSet(bool followsConventions, ODataMetadataLevel metadataLevel) { // Arrange _entitySet.HasIdLink(new SelfLinkBuilder<Uri>((context) => new Uri("http://selflink/"), followsConventions)); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act Uri generatedEditLink = linkBuilder.BuildEditLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel, new Uri("http://selflink")); // Assert Assert.Null(generatedEditLink); }
public void BuildIdLink_DoesNotThrow_IfJsonAndIdLinkBuilderIsNull(object metadataLevel) { NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); Assert.DoesNotThrow( () => linkBuilder.BuildIdLink(new EntityInstanceContext(), (ODataMetadataLevel)metadataLevel)); }
public void Ctor_FollowingConventions_GeneratesNavigationLinkWithCast_ForDerivedNavigationProperty() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = model.Customers, Url = request.GetUrlHelper() }; EntityInstanceContext instanceContext = new EntityInstanceContext(serializerContext, model.SpecialCustomer.AsReference(), new { ID = 42 }); IEdmNavigationProperty ordersProperty = model.SpecialCustomer.NavigationProperties().First(p => p.Name == "SpecialOrders"); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(model.Customers, model.Model); Uri result = linkBuilder.BuildNavigationLink(instanceContext, ordersProperty, ODataMetadataLevel.FullMetadata); // Assert Assert.Equal("http://localhost/Customers(42)/NS.SpecialCustomer/SpecialOrders", result.AbsoluteUri); }
public void Ctor_FollowingConventions_GeneratesFeedSelfLinkFollowingConventions() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpRequestMessage request = GetODataRequest(model.Model); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(model.Customers, model.Model); Uri result = linkBuilder.BuildFeedSelfLink(new FeedContext { EntitySet = model.Customers, Url = request.GetUrlHelper() }); // Assert Assert.Equal("http://localhost/Customers", result.AbsoluteUri); }
public void BuildReadLink_WhenReadLinkIsNotSameAsEditLink(bool followsConventions, ODataMetadataLevel metadataLevel, bool linkEmitted) { // Arrange _entitySet.HasReadLink(new SelfLinkBuilder<Uri>((context) => new Uri("http://readlink/"), followsConventions)); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); // Act Uri generatedReadLink = linkBuilder.BuildReadLink(new EntityInstanceContext(), metadataLevel, new Uri("http://editLink")); // Assert if (linkEmitted) { Assert.Equal("http://readlink/", generatedReadLink.AbsoluteUri); } else { Assert.Null(generatedReadLink); } }
public void BuildNavigationLink_ReturnsNull(bool followsConventions, ODataMetadataLevel metadataLevel) { // Arrange var navigationProperty = _entitySet.EntityType.AddNavigationProperty(typeof(Customer).GetProperty("Orders"), EdmMultiplicity.Many); IEdmModel model = _modelBuilder.GetEdmModel(); IEdmNavigationProperty edmNavProperty = model.GetEdmTypeReference(typeof(Customer)).AsEntity().DeclaredNavigationProperties().Single(p => p.Name == "Orders"); NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(_entitySet); linkBuilder.AddNavigationPropertyLinkBuilder(edmNavProperty, new NavigationLinkBuilder((context, property) => new Uri("http://navigationlink"), followsConventions)); // Act Uri generatedNavigationLink = linkBuilder.BuildNavigationLink(new EntityInstanceContext(), edmNavProperty, (ODataMetadataLevel)metadataLevel); // Assert Assert.Null(generatedNavigationLink); }
public void Ctor_FollowingConventions_GeneratesSelfLinkWithoutCast_IfDerivedTypesHaveNoNavigationProperty() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); IEdmEntitySet specialCustomers = new EdmEntitySet(model.Container, "SpecialCustomers", model.SpecialCustomer); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = specialCustomers, Url = request.GetUrlHelper() }; EntityInstanceContext instanceContext = new EntityInstanceContext(serializerContext, model.Customer.AsReference(), new { ID = 42 }); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(specialCustomers, model.Model); var result = linkBuilder.BuildIdLink(instanceContext, ODataMetadataLevel.FullMetadata); // Assert Assert.Equal("http://localhost/SpecialCustomers(42)", result.ToString()); }
public void Ctor_FollowingConventions_GeneratesSelfLinkWithCast_IfDerivedTypeHasNavigationProperty() { // Arrange CustomersModelWithInheritance model = new CustomersModelWithInheritance(); HttpRequestMessage request = GetODataRequest(model.Model); ODataSerializerContext serializerContext = new ODataSerializerContext { Model = model.Model, NavigationSource = model.Customers, Url = request.GetUrlHelper() }; EntityInstanceContext instanceContext = new EntityInstanceContext(serializerContext, model.Customer.AsReference(), new { ID = 42 }); // Act NavigationSourceLinkBuilderAnnotation linkBuilder = new NavigationSourceLinkBuilderAnnotation(model.Customers, model.Model); string result = linkBuilder.BuildIdLink(instanceContext, ODataMetadataLevel.Default); // Assert Assert.Equal("http://localhost/Customers(42)/NS.Customer", result); }