Ejemplo n.º 1
0
        public void HasFeedActionLink_ThrowsException_OnNonBindableActions()
        {
            // Arrange
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("NoBindableAction");

            // Act & Assert
            ExceptionAssert.Throws <InvalidOperationException>(
                () => action.HasFeedActionLink(ctx => new Uri("http://any"), followsConventions: false),
                "To register an action link factory, actions must be bindable to the collection of entity. " +
                "Action 'NoBindableAction' does not meet this requirement.");
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }