public void WhenFeedActionLinksNotManuallyConfigured_ConventionBasedBuilderUsesConventions() { // Arrange Uri expectedUri = new Uri("http://server/Movies/Default.Watch"); ODataModelBuilder builder = ODataConventionModelBuilderFactory.Create(); EntityTypeConfiguration <Movie> movie = builder.EntitySet <Movie>("Movies").EntityType; ActionConfiguration watch = movie.Collection.Action("Watch"); // action bound to collection IEdmModel model = builder.GetEdmModel(); var configuration = RoutingConfigurationFactory.Create(); string routeName = "Route"; configuration.MapODataServiceRoute(routeName, null, model); var request = RequestFactory.Create(HttpMethod.Get, "http://server/Movies", configuration, routeName); // Act IEdmEntityContainer container = model.SchemaElements.OfType <IEdmEntityContainer>().SingleOrDefault(); IEdmAction watchAction = Assert.Single(model.SchemaElements.OfType <IEdmAction>()); // Guard IEdmEntitySet entitySet = container.EntitySets().SingleOrDefault(); ResourceSetContext context = ResourceSetContextFactory.Create(entitySet, request); OperationLinkBuilder actionLinkBuilder = model.GetAnnotationValue <OperationLinkBuilder>(watchAction); //Assert Assert.Equal(expectedUri, watch.GetFeedActionLink()(context)); Assert.NotNull(actionLinkBuilder); Assert.Equal(expectedUri, actionLinkBuilder.BuildLink(context)); }
public void CanManuallyConfigureFeedActionLinkFactory() { // Arrange Uri expectedUri = new Uri("http://localhost/service/Customers/Reward"); ODataModelBuilder builder = new ODataModelBuilder(); EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType; customer.HasKey(c => c.CustomerId); customer.Property(c => c.Name); ActionConfiguration reward = customer.Collection.Action("Reward"); reward.HasFeedActionLink(ctx => expectedUri, followsConventions: false); IEdmModel model = builder.GetEdmModel(); // Act IEdmAction rewardAction = Assert.Single(model.SchemaElements.OfType <IEdmAction>()); // Guard OperationLinkBuilder actionLinkBuilder = model.GetAnnotationValue <OperationLinkBuilder>(rewardAction); ResourceSetContext context = new ResourceSetContext(); //Assert Assert.Equal(expectedUri, reward.GetFeedActionLink()(context)); Assert.NotNull(actionLinkBuilder); Assert.Equal(expectedUri, actionLinkBuilder.BuildLink(context)); }
public void Apply(ProcedureConfiguration configuration, ODataModelBuilder model) { ActionConfiguration action = configuration as ActionConfiguration; if (action == null || !action.IsBindable) { return; } // You only need to create links for bindable actions that bind to a single entity. if (action.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity && action.GetActionLink() == null) { if (action.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Entity && action.GetActionLink() == null) { string bindingParameterType = action.BindingParameter.TypeConfiguration.FullName; action.HasActionLink( entityContext => entityContext.GenerateActionLink(bindingParameterType, action.FullyQualifiedName), followsConventions: true); } } else if (action.BindingParameter.TypeConfiguration.Kind == EdmTypeKind.Collection && action.GetFeedActionLink() == null) { if (((CollectionTypeConfiguration)action.BindingParameter.TypeConfiguration).ElementType.Kind == EdmTypeKind.Entity) { string bindingParameterType = action.BindingParameter.TypeConfiguration.FullName; action.HasFeedActionLink( feedContext => feedContext.GenerateActionLink(bindingParameterType, action.FullyQualifiedName), followsConventions: true); } } }