Esempio n. 1
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.UnboundFunction)
            {
                UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)pathSegment;
                if (_functionName == functionSegment.FunctionName)
                {
                    var enumNames = functionSegment.Function.Function.Parameters.Where(p => p.Type.IsEnum()).Select(p => p.Name);
                    if (KeyValuePathSegmentTemplate.TryMatch(ParameterMappings, functionSegment.Values, values,
                                                             enumNames))
                    {
                        foreach (KeyValuePair <string, string> nameAndValue in functionSegment.Values)
                        {
                            string name  = nameAndValue.Key;
                            object value = functionSegment.GetParameterValue(name);

                            ProcedureRoutingConventionHelpers.AddFunctionParameters(functionSegment.Function.Function, name,
                                                                                    value, values, values, ParameterMappings);
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BoundFunctionPathSegmentTemplate"/> class.
        /// </summary>
        /// <param name="function">The function segment to be templatized</param>
        public BoundFunctionPathSegmentTemplate(BoundFunctionPathSegment function)
        {
            if (function == null)
            {
                throw Error.ArgumentNull("function");
            }

            FunctionName      = function.FunctionName;
            ParameterMappings = KeyValuePathSegmentTemplate.BuildParameterMappings(function.Values, function.ToString());
        }
Esempio n. 3
0
        public void Ctor_InitializesPropertyMappings_Properly()
        {
            // Arrange && Act
            KeyValuePathSegmentTemplate template = new KeyValuePathSegmentTemplate(
                new KeyValuePathSegment("Key1={ID1},Key2={ID2}"));

            // Assert
            Assert.NotNull(template.ParameterMappings);
            Assert.Equal(2, template.ParameterMappings.Count);
            Assert.Equal("ID1", template.ParameterMappings["Key1"]);
            Assert.Equal("ID2", template.ParameterMappings["Key2"]);
        }
        public void Ctor_InitializesPropertyMappings_Properly()
        {
            // Arrange && Act
            KeyValuePathSegmentTemplate template = new KeyValuePathSegmentTemplate(
                new KeyValuePathSegment("Key1={ID1},Key2={ID2}"));

            // Assert
            Assert.NotNull(template.ParameterMappings);
            Assert.Equal(2, template.ParameterMappings.Count);
            Assert.Equal("ID1", template.ParameterMappings["Key1"]);
            Assert.Equal("ID2", template.ParameterMappings["Key2"]);
        }
Esempio n. 5
0
        public void TryMatch_SingleKey_ReturnsTrueOnMatch()
        {
            KeyValuePathSegmentTemplate template = new KeyValuePathSegmentTemplate(new KeyValuePathSegment("{ID}"));
            KeyValuePathSegment         segment  = new KeyValuePathSegment("123");

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

            // Assert
            Assert.True(result);
            Assert.Equal("123", values["ID"]);
        }
Esempio n. 6
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.Function)
            {
                BoundFunctionPathSegment functionSegment = (BoundFunctionPathSegment)pathSegment;
                if (FunctionName == functionSegment.FunctionName)
                {
                    return(KeyValuePathSegmentTemplate.TryMatch(ParameterMappings, functionSegment.Values, values));
                }
            }

            return(false);
        }
        public void TryMatch_SingleKey_ReturnsTrueOnMatch()
        {
            KeyValuePathSegmentTemplate template = new KeyValuePathSegmentTemplate(new KeyValuePathSegment("{ID}"));
            KeyValuePathSegment segment = new KeyValuePathSegment("123");

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

            // Assert
            Assert.True(result);
            Assert.Equal("123", values["ID"]);
        }
Esempio n. 8
0
        public void TryMatch_MultiKey_ReturnsTrueOnMatch()
        {
            KeyValuePathSegmentTemplate template = new KeyValuePathSegmentTemplate(new KeyValuePathSegment("FirstName={key1},LastName={key2}"));
            KeyValuePathSegment         segment  = new KeyValuePathSegment("FirstName=abc,LastName=xyz");

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

            // Assert
            Assert.True(result);
            Assert.Equal("abc", values["key1"]);
            Assert.Equal("xyz", values["key2"]);
        }
        public void TryMatch_MultiKey_ReturnsTrueOnMatch()
        {
            KeyValuePathSegmentTemplate template = new KeyValuePathSegmentTemplate(new KeyValuePathSegment("FirstName={key1},LastName={key2}"));
            KeyValuePathSegment segment = new KeyValuePathSegment("FirstName=abc,LastName=xyz");

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

            // Assert
            Assert.True(result);
            Assert.Equal("abc", values["key1"]);
            Assert.Equal("xyz", values["key2"]);
        }
Esempio n. 10
0
        /// <inheritdoc />
        public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values)
        {
            if (pathSegment.SegmentKind == ODataSegmentKinds.UnboundFunction)
            {
                UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)pathSegment;
                if (_functionName == functionSegment.FunctionName)
                {
                    var enumNames = functionSegment.Function.Function.Parameters.Where(p => p.Type.IsEnum()).Select(p => p.Name);
                    return(KeyValuePathSegmentTemplate.TryMatch(ParameterMappings, functionSegment.Values, values, enumNames));
                }
            }

            return(false);
        }