public void Apply_FollowsConventions()
        {
            // Arrange
            ODataModelBuilder            builder  = new ODataModelBuilder();
            FunctionConfiguration        function = new FunctionConfiguration(builder, "IgnoreAction");
            Mock <IEdmTypeConfiguration> mockBindingParameterType = new Mock <IEdmTypeConfiguration>();

            mockBindingParameterType.Setup(o => o.Kind).Returns(EdmTypeKind.Entity);
            mockBindingParameterType.Setup(o => o.ClrType).Returns(typeof(int));
            function.SetBindingParameter("IgnoreParameter", mockBindingParameterType.Object);
            FunctionLinkGenerationConvention convention = new FunctionLinkGenerationConvention();

            // Act
            convention.Apply(function, builder);

            // Assert
            Assert.True(function.FollowsConventions);
        }
        public void Apply_Doesnot_Override_UserConfiguration()
        {
            // Arrange
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create();
            var customers = builder.EntitySet <Customer>("Customers");
            var function  = customers.EntityType.Function("MyFunction").Returns <int>();

            function.HasFunctionLink(ctx => new Uri("http://localhost/FunctionTestWorks"), followsConventions: false);
            FunctionLinkGenerationConvention convention = new FunctionLinkGenerationConvention();

            convention.Apply(function, builder);

            // Act
            IEdmModel model        = builder.GetEdmModel();
            var       edmCustomers = model.EntityContainer.FindEntitySet("Customers");
            var       edmType      = model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Customer");
            var       edmFunction  = model.SchemaElements.OfType <IEdmFunction>().Single(f => f.Name == "MyFunction");

            Assert.NotNull(edmFunction);

            string routeName     = "OData";
            var    configuration = RoutingConfigurationFactory.CreateWithRootContainer(routeName);

            configuration.MapODataServiceRoute(routeName, null, model);

            var request = RequestFactory.Create(HttpMethod.Get, "http://localhost:123", configuration, routeName);

            OperationLinkBuilder fuinctionLinkBuilder = model.GetOperationLinkBuilder(edmFunction);

            var serializerContext = ODataSerializerContextFactory.Create(model, edmCustomers, request);
            var entityContext     = new ResourceContext(serializerContext, edmType.AsReference(), new Customer {
                Id = 109
            });

            // Assert
            Uri link = fuinctionLinkBuilder.BuildLink(entityContext);

            Assert.Equal("http://localhost/FunctionTestWorks", link.AbsoluteUri);
        }
        public void Apply_WorksFor_FunctionBoundToCollectionOfEntity()
        {
            // Arrange
            ODataConventionModelBuilder builder = ODataConventionModelBuilderFactory.Create();
            var function = builder.EntityType <Customer>().Collection.Function("MyFunction").Returns <int>();

            function.Parameter <string>("param");

            // Act
            Assert.Null(function.GetFunctionLink());     // Guard
            Assert.Null(function.GetFeedFunctionLink()); // Guard

            FunctionLinkGenerationConvention convention = new FunctionLinkGenerationConvention();

            convention.Apply(function, builder);

            // Assert
            var functionLink = function.GetFeedFunctionLink();

            Assert.NotNull(functionLink);
            Assert.IsType <Func <ResourceSetContext, Uri> >(functionLink);

            Assert.Null(function.GetFunctionLink());
        }