public void TryMatch_DifferentType()
        {
            // Arrange
            DynamicPropertyPathSegment leftSegment = new DynamicPropertyPathSegment("property");
            KeyValuePathSegment rightSegment = new KeyValuePathSegment("value");

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

            // Assert
            Assert.False(result);
        }
Exemple #2
0
        public void TryMatch_DifferentType()
        {
            // Arrange
            DynamicPropertyPathSegment leftSegment  = new DynamicPropertyPathSegment("property");
            KeyValuePathSegment        rightSegment = new KeyValuePathSegment("value");

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

            // Assert
            Assert.False(result);
        }
        public void TryMatch()
        {
            // Arrange
            DynamicPropertyPathSegment leftSegment = new DynamicPropertyPathSegment("property");
            DynamicPropertyPathSegment rightSegment = new DynamicPropertyPathSegment("property");

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

            // Assert
            Assert.True(result);
        }
Exemple #4
0
        public void TryMatch()
        {
            // Arrange
            DynamicPropertyPathSegment leftSegment  = new DynamicPropertyPathSegment("property");
            DynamicPropertyPathSegment rightSegment = new DynamicPropertyPathSegment("property");

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

            // Assert
            Assert.True(result);
        }
Exemple #5
0
        public void TryMatch_ConditionalWhenPropertyName(bool isSamePropertyName, string propertName)
        {
            // Arrange
            DynamicPropertyPathSegmentTemplate template = new DynamicPropertyPathSegmentTemplate(new DynamicPropertyPathSegment("matchingproperty"));
            DynamicPropertyPathSegment         segment  = new DynamicPropertyPathSegment(propertName);

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

            // Assert
            Assert.Equal(isSamePropertyName, result);
            Assert.False(values.ContainsKey("matchingproperty"));
        }
Exemple #6
0
        public void Translate_PathTemplateSegment_To_DynamicPropertyPathSegment_Works()
        {
            // Arrange
            PathTemplateSegment segment = new PathTemplateSegment("{pName:dynamicproperty}");

            // Act
            IEnumerable <ODataPathSegment> segments = _translator.Translate(segment);

            // Assert
            ODataPathSegment           pathSegment    = Assert.Single(segments);
            DynamicPropertyPathSegment dynamicSegment = Assert.IsType <DynamicPropertyPathSegment>(pathSegment);

            Assert.Equal("{pName}", dynamicSegment.PropertyName);
        }
Exemple #7
0
        public void Translate_OpenPropertySegment_To_DynamicPropertyPathSegment_Works()
        {
            // Arrange
            OpenPropertySegment segment = new OpenPropertySegment("Dynamic");

            // Act
            IEnumerable <ODataPathSegment> segments = _translator.Translate(segment);

            // Assert
            ODataPathSegment           pathSegment = Assert.Single(segments);
            DynamicPropertyPathSegment dynamicPropertyPathSegment = Assert.IsType <DynamicPropertyPathSegment>(pathSegment);

            Assert.Equal("Dynamic", dynamicPropertyPathSegment.PropertyName);
        }
        public void TryMatch_ConditionalWhenPropertyName(bool isSamePropertyName, string propertName)
        {
            // Arrange
            DynamicPropertyPathSegmentTemplate template = new DynamicPropertyPathSegmentTemplate(new DynamicPropertyPathSegment("matchingproperty"));
            DynamicPropertyPathSegment segment = new DynamicPropertyPathSegment(propertName);

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

            // Assert
            Assert.Equal(isSamePropertyName, result);
            Assert.False(values.ContainsKey("matchingproperty"));

        }
        public void TryMatch_AlwaysTrueWhenParameterName()
        {
            // Arrange
            DynamicPropertyPathSegmentTemplate template = new DynamicPropertyPathSegmentTemplate(new DynamicPropertyPathSegment("{parameter}"));
            DynamicPropertyPathSegment segment = new DynamicPropertyPathSegment("property");

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

            // Assert
            Assert.True(result);
            Assert.True(values.ContainsKey("parameter"));
            Assert.Equal("property", values["parameter"]);
        }
Exemple #10
0
        public void TryMatch_AlwaysTrueWhenParameterName()
        {
            // Arrange
            DynamicPropertyPathSegmentTemplate template = new DynamicPropertyPathSegmentTemplate(new DynamicPropertyPathSegment("{parameter}"));
            DynamicPropertyPathSegment         segment  = new DynamicPropertyPathSegment("property");

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

            // Assert
            Assert.True(result);
            Assert.True(values.ContainsKey("parameter"));
            Assert.Equal("property", values["parameter"]);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicPropertyPathSegmentTemplate"/> class.
        /// </summary>
        /// <param name="dynamicPropertyPathSegment">The path template segment to be parsed as a template.</param>
        public DynamicPropertyPathSegmentTemplate(DynamicPropertyPathSegment dynamicPropertyPathSegment)
        {
            if (dynamicPropertyPathSegment == null)
            {
                throw Error.ArgumentNull("dynamicPropertyPathSegment");
            }

            PropertyName = dynamicPropertyPathSegment.PropertyName;
            TreatPropertyNameAsParameterName = false;

            if (IsRouteParameter(PropertyName))
            {
                PropertyName = PropertyName.Substring(1, PropertyName.Length - 2);
                TreatPropertyNameAsParameterName = true;

                if (String.IsNullOrEmpty(PropertyName))
                {
                    throw new ODataException(
                        Error.Format(SRResources.EmptyParameterAlias, PropertyName, dynamicPropertyPathSegment));
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DynamicPropertyPathSegmentTemplate"/> class.
        /// </summary>
        /// <param name="dynamicPropertyPathSegment">The path template segment to be parsed as a template.</param>
        public DynamicPropertyPathSegmentTemplate(DynamicPropertyPathSegment dynamicPropertyPathSegment)
        {
            if (dynamicPropertyPathSegment == null)
            {
                throw Error.ArgumentNull("dynamicPropertyPathSegment");
            }

            PropertyName = dynamicPropertyPathSegment.PropertyName;
            TreatPropertyNameAsParameterName = false;

            if (IsRouteParameter(PropertyName))
            {
                PropertyName = PropertyName.Substring(1, PropertyName.Length - 2);
                TreatPropertyNameAsParameterName = true;

                if (String.IsNullOrEmpty(PropertyName))
                {
                    throw new ODataException(
                              Error.Format(SRResources.EmptyParameterAlias, PropertyName, dynamicPropertyPathSegment));
                }
            }
        }