public void CreateODataOperations_CreateOperations(bool followConventions)
        {
            // Arrange
            // Arrange
            string expectedTarget          = "aa://Target";
            ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
            var builder = new ODataConventionModelBuilder();

            builder.EntitySet <FeedCustomer>("Customers");
            var function = builder.EntityType <FeedCustomer>().Collection.Function("MyFunction").Returns <int>();

            function.HasFeedFunctionLink(a => new Uri(expectedTarget), followConventions);
            IEdmModel model = builder.GetEdmModel();

            IEdmEntitySet customers              = model.EntityContainer.FindEntitySet("Customers");
            IEdmFunction  edmFunction            = model.SchemaElements.OfType <IEdmFunction>().First(f => f.Name == "MyFunction");
            string        expectedMetadataPrefix = "http://Metadata";

            UrlHelper          url         = CreateMetadataLinkFactory(expectedMetadataPrefix);
            HttpRequestMessage request     = new HttpRequestMessage();
            FeedContext        feedContext = new FeedContext
            {
                EntitySetBase = customers,
                Request       = request,
                Url           = url
            };

            ODataSerializerContext serializerContext = new ODataSerializerContext
            {
                NavigationSource = customers,
                Request          = request,
                Model            = model,
                MetadataLevel    = ODataMetadataLevel.FullMetadata,
                Url = url
            };

            // Act
            ODataOperation actualOperation = serializer.CreateODataOperation(edmFunction, feedContext, serializerContext);

            // Assert
            Assert.NotNull(actualOperation);
            string         expectedMetadata = expectedMetadataPrefix + "#Default.MyFunction";
            ODataOperation expectedFunction = new ODataFunction
            {
                Metadata = new Uri(expectedMetadata),
                Target   = new Uri(expectedTarget),
                Title    = "MyFunction"
            };

            AssertEqual(expectedFunction, actualOperation);
        }
        public void CreateODataOperation_OmitsOperations_WhenNonFullMetadata(ODataMetadataLevel metadataLevel)
        {
            // Arrange
            ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmFunction      function   = new EdmFunction("NS", "Function", returnType, isBound: true, entitySetPathExpression: null, isComposable: false);

            FeedContext            feedContext       = new FeedContext();
            ODataSerializerContext serializerContext = new ODataSerializerContext
            {
                MetadataLevel = metadataLevel
            };
            // Act

            ODataOperation operation = serializer.CreateODataOperation(function, feedContext, serializerContext);

            // Assert
            Assert.Null(operation);
        }
        public void CreateODataOperations_CreateOperations(bool followConventions)
        {
            // Arrange
            // Arrange
            string expectedTarget = "aa://Target";
            ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<FeedCustomer>("Customers");
            var function = builder.EntityType<FeedCustomer>().Collection.Function("MyFunction").Returns<int>();
            function.HasFeedFunctionLink(a => new Uri(expectedTarget), followConventions);
            IEdmModel model = builder.GetEdmModel();

            IEdmEntitySet customers = model.EntityContainer.FindEntitySet("Customers");
            IEdmFunction edmFunction = model.SchemaElements.OfType<IEdmFunction>().First(f => f.Name == "MyFunction");
            string expectedMetadataPrefix = "http://Metadata";

            UrlHelper url = CreateMetadataLinkFactory(expectedMetadataPrefix);
            HttpRequestMessage request = new HttpRequestMessage();
            FeedContext feedContext = new FeedContext
            {
                EntitySetBase = customers,
                Request = request,
                Url = url
            };

            ODataSerializerContext serializerContext = new ODataSerializerContext
            {
                NavigationSource = customers,
                Request = request,
                Model = model,
                MetadataLevel = ODataMetadataLevel.FullMetadata,
                Url = url
            };

            // Act
            ODataOperation actualOperation = serializer.CreateODataOperation(edmFunction, feedContext, serializerContext);

            // Assert
            Assert.NotNull(actualOperation);
            string expectedMetadata = expectedMetadataPrefix + "#Default.MyFunction";
            ODataOperation expectedFunction = new ODataFunction
            {
                Metadata = new Uri(expectedMetadata),
                Target = new Uri(expectedTarget),
                Title = "MyFunction"
            };

            AssertEqual(expectedFunction, actualOperation);
        }
        public void CreateODataOperation_OmitsOperations_WhenNonFullMetadata(ODataMetadataLevel metadataLevel)
        {
            // Arrange
            ODataFeedSerializer serializer = new ODataFeedSerializer(new DefaultODataSerializerProvider());

            IEdmTypeReference returnType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false);
            IEdmFunction function = new EdmFunction("NS", "Function", returnType, isBound: true, entitySetPathExpression: null, isComposable: false);

            FeedContext feedContext = new FeedContext();
            ODataSerializerContext serializerContext = new ODataSerializerContext
            {
                MetadataLevel = metadataLevel
            };
            // Act

            ODataOperation operation = serializer.CreateODataOperation(function, feedContext, serializerContext);

            // Assert
            Assert.Null(operation);
        }