public void Property_SegmentKind_IsEntitySet()
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            FunctionPathSegment segment = new FunctionPathSegment("function", parameters);

            Assert.Equal(ODataSegmentKinds.Function, segment.SegmentKind);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionPathSegmentTemplate"/> class.
        /// </summary>
        /// <param name="function">The function segment to be templatized</param>
        public FunctionPathSegmentTemplate(FunctionPathSegment function)
        {
            if (function == null)
            {
                throw Error.ArgumentNull("function");
            }

            ParameterMappings = KeyValuePathSegmentTemplate.BuildParameterMappings(function.Values, function.ToString());
        }
        public void GetEdmType_Returns_FunctionReturnType()
        {
            // Arrange
            IEdmEntityType returnType = new Mock<IEdmEntityType>().Object;
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmFunctionImport function = new EdmFunctionImport(
                container,
                "Function",
                new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)));
            FunctionPathSegment segment = new FunctionPathSegment(function, model: null, parameterValues: null);

            // Act
            var result = segment.GetEdmType(previousEdmType: null);

            // Assert
            Assert.Same(returnType, result);
        }
        public void TryMatch_ReturnsTrue_IfSameFunction()
        {
            // Arrange
            IEdmEntityType returnType = new Mock<IEdmEntityType>().Object;
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmFunctionImport function = new EdmFunctionImport(
                container,
                "Function",
                new EdmFunction("NS", "Function", new EdmEntityTypeReference(returnType, isNullable: false)));

            FunctionPathSegment template = new FunctionPathSegment(function, model: null, parameterValues: null);
            FunctionPathSegment segment = new FunctionPathSegment(function, model: null, parameterValues: null);

            // Act
            Dictionary<string, object> values = new Dictionary<string,object>();
            bool result = template.TryMatch(segment, values);

            // Assert
            Assert.True(result);
            Assert.Empty(values);
        }
        public void TryMatch_ReturnTrue_IfSameFunction()
        {
            // Arrange
            IEdmEntityType returnType = new Mock<IEdmEntityType>().Object;
            EdmEntityContainer container = new EdmEntityContainer("NS", "Container");
            EdmFunctionImport function = new EdmFunctionImport(
                container,
                "Function",
                new EdmFunction(
                    "NS",
                    "Function",
                    new EdmEntityTypeReference(returnType, isNullable: false)));

            Dictionary<string, string> parameterValues = new Dictionary<string, string>()
            {
                { "Parameter1", "1" },
                { "Parameter2", "2" }
            };

            Dictionary<string, string> parameterMappings = new Dictionary<string, string>()
            {
                { "Parameter1", "{param1}" },
                { "Parameter2", "{param2}" }
            };

            FunctionPathSegment segment = new FunctionPathSegment(function, model: null, parameterValues: parameterValues);
            FunctionPathSegmentTemplate template = new FunctionPathSegmentTemplate(
                new FunctionPathSegment(function, model: null, parameterValues: parameterMappings));


            // Act
            Dictionary<string, object> values = new Dictionary<string,object>();
            bool result = template.TryMatch(segment, values);

            // Assert
            Assert.True(result);
            Assert.Equal(2, values.Count);
            Assert.Equal("1", values["param1"]);
            Assert.Equal("2", values["param2"]);
        }