Пример #1
0
        public void EqualityIsCorrect()
        {
            OpenPropertySegment openPropertySegment1 = new OpenPropertySegment("superbeans");
            OpenPropertySegment openPropertySegment2 = new OpenPropertySegment("superbeans");

            openPropertySegment1.Equals(openPropertySegment2).Should().BeTrue();
        }
Пример #2
0
 /// <summary>
 /// Translate an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Translate</param>
 /// <returns>Translated WebApi path segment.</returns>
 public override IEnumerable <ODataPathSegment> Translate(OpenPropertySegment segment)
 {
     throw new ODataException(Error.Format(
                                  SRResources.TargetKindNotImplemented,
                                  typeof(Semantic.ODataPathSegment).Name,
                                  typeof(OpenPropertySegment).Name));
 }
Пример #3
0
        /// <summary>
        /// Translate OpenPropertySegment to linq expression.
        /// </summary>
        /// <param name="segment">The OpenPropertySegment</param>
        /// <returns>The linq expression</returns>
        public override Expression Translate(OpenPropertySegment segment)
        {
            if (!(this.LastProcessedSegment is KeySegment ||
                  this.LastProcessedSegment is SingletonSegment ||
                  this.LastProcessedSegment is NavigationPropertySegment ||
                  this.LastProcessedSegment is PropertySegment ||
                  this.LastProcessedSegment is TypeSegment))
            {
                throw new InvalidOperationException("Unsupported URI segment before PropertySegment");
            }

            // get OpenProperties
            var propertyAccessExpression = Expression.Property(this.ResultExpression, "OpenProperties");
            // key
            var key = Expression.Constant(segment.PropertyName, typeof(string));
            // OpenProperties.ContainsKey(segment.PropertyName)
            MethodInfo containsKeyMethod  = typeof(Dictionary <string, object>).GetMethod("ContainsKey", new[] { typeof(string) });
            var        containsExpression = Expression.Call(propertyAccessExpression, containsKeyMethod, key);
            //OpenProperties[segment.PropertyName]
            var queryOpenPropertyExpression = Expression.Property(propertyAccessExpression, "Item", key);

            this.ResultExpression     = Expression.Condition(containsExpression, queryOpenPropertyExpression, Expression.Constant(null));
            this.LastProcessedSegment = segment;
            return(this.ResultExpression);
        }
Пример #4
0
        public static AndConstraint <OpenPropertySegment> ShouldBeOpenPropertySegment(this ODataPathSegment segment, string openPropertyName)
        {
            segment.Should().BeOfType <OpenPropertySegment>();
            OpenPropertySegment openPropertySegment = segment.As <OpenPropertySegment>();

            openPropertySegment.PropertyName.Should().Be(openPropertyName);
            return(new AndConstraint <OpenPropertySegment>(openPropertySegment));
        }
 public void InequalityIsCorrect()
 {
     OpenPropertySegment openPropertySegment1 = new OpenPropertySegment("superbeans");
     OpenPropertySegment openPropertySegment2 = new OpenPropertySegment("incredibeans");
     BatchSegment segment = BatchSegment.Instance;
     openPropertySegment1.Equals(openPropertySegment2).Should().BeFalse();
     openPropertySegment2.Equals(segment).Should().BeFalse();
 }
Пример #6
0
        public void InequalityIsCorrect()
        {
            OpenPropertySegment openPropertySegment1 = new OpenPropertySegment("superbeans");
            OpenPropertySegment openPropertySegment2 = new OpenPropertySegment("incredibeans");
            BatchSegment        segment = BatchSegment.Instance;

            openPropertySegment1.Equals(openPropertySegment2).Should().BeFalse();
            openPropertySegment2.Equals(segment).Should().BeFalse();
        }
Пример #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);
        }
Пример #8
0
        public override void Handle(OpenPropertySegment segment)
        {
            this.ThrowIfResolved();

            this.NavigationSource = null;
            this.Property         = new EdmOpenStructuralProperty(segment.PropertyName);
            this.Type             = segment.EdmType;
            this.ElementType      = this.GetElementType(this.Type);

            this.PushParentSegment();
            this.childSegments.Add(segment);

            this.canonicalSegments.Add(segment);
        }
 /// <summary>
 /// Handle an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Handle</param>
 public override void Handle(OpenPropertySegment segment)
 {
     CommonHandler(segment);
 }
Пример #10
0
        public override void Handle(OpenPropertySegment segment)
        {
            this.ThrowIfResolved();

            this.NavigationSource = null;
            this.Property = new EdmOpenStructuralProperty(segment.PropertyName);
            this.Type = segment.EdmType;
            this.ElementType = this.GetElementType(this.Type);

            this.PushParentSegment();
            this.childSegments.Add(segment);

            this.canonicalSegments.Add(segment);
        }
Пример #11
0
 /// <summary>
 /// Handle an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Handle</param>
 public virtual void Handle(OpenPropertySegment segment)
 {
     throw new NotImplementedException();
 }
 public void IdentifierIsPropertyName()
 {
     OpenPropertySegment openPropertySegment = new OpenPropertySegment("stuff");
     openPropertySegment.Identifier.Should().Be("stuff");
 }
 /// <summary>
 /// Translate an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Translate</param>
 /// <returns>Defined by the implementer.</returns>
 public override string Translate(OpenPropertySegment segment)
 {
     Debug.Assert(segment != null, "segment != null");
     return("/" + segment.PropertyName);
 }
Пример #14
0
        private void BuildSelections(
            SelectExpandClause selectExpandClause,
            HashSet <IEdmStructuralProperty> allStructuralProperties,
            HashSet <IEdmNavigationProperty> allNavigationProperties,
            HashSet <IEdmAction> allActions,
            HashSet <IEdmFunction> allFunctions)
        {
            foreach (SelectItem selectItem in selectExpandClause.SelectedItems)
            {
                if (selectItem is ExpandedNavigationSelectItem)
                {
                    continue;
                }

                PathSelectItem pathSelectItem = selectItem as PathSelectItem;

                if (pathSelectItem != null)
                {
                    ValidatePathIsSupported(pathSelectItem.SelectedPath);
                    ODataPathSegment segment = pathSelectItem.SelectedPath.LastSegment;

                    NavigationPropertySegment navigationPropertySegment = segment as NavigationPropertySegment;
                    if (navigationPropertySegment != null)
                    {
                        IEdmNavigationProperty navigationProperty = navigationPropertySegment.NavigationProperty;
                        if (allNavigationProperties.Contains(navigationProperty))
                        {
                            SelectedNavigationProperties.Add(navigationProperty);
                        }
                        continue;
                    }

                    PropertySegment structuralPropertySegment = segment as PropertySegment;
                    if (structuralPropertySegment != null)
                    {
                        IEdmStructuralProperty structuralProperty = structuralPropertySegment.Property;
                        if (allStructuralProperties.Contains(structuralProperty))
                        {
                            SelectedStructuralProperties.Add(structuralProperty);
                        }
                        continue;
                    }

                    OperationSegment operationSegment = segment as OperationSegment;
                    if (operationSegment != null)
                    {
                        AddOperations(allActions, allFunctions, operationSegment);
                        continue;
                    }

                    OpenPropertySegment openPropertySegment = segment as OpenPropertySegment;
                    if (openPropertySegment != null)
                    {
                        SelectedDynamicProperties.Add(openPropertySegment.PropertyName);
                        continue;
                    }
                    throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, segment.GetType().Name));
                }

                WildcardSelectItem wildCardSelectItem = selectItem as WildcardSelectItem;
                if (wildCardSelectItem != null)
                {
                    SelectedStructuralProperties = allStructuralProperties;
                    SelectedNavigationProperties = allNavigationProperties;
                    continue;
                }

                NamespaceQualifiedWildcardSelectItem wildCardActionSelection = selectItem as NamespaceQualifiedWildcardSelectItem;
                if (wildCardActionSelection != null)
                {
                    SelectedActions   = allActions;
                    SelectedFunctions = allFunctions;
                    continue;
                }

                throw new ODataException(Error.Format(SRResources.SelectionTypeNotSupported, selectItem.GetType().Name));
            }
        }
Пример #15
0
        /// <summary>
        /// Creates a new segment for an open property.
        /// </summary>
        /// <param name="previous">previous segment info.</param>
        /// <param name="identifier">name of the segment.</param>
        /// <param name="parenthesisExpression">whether this segment has a query portion or not.</param>
        private void CreateOpenPropertySegment(ODataPathSegment previous, string identifier, string parenthesisExpression)
        {
            ODataPathSegment segment = new OpenPropertySegment(identifier);

            // Handle an open type property. If the current leaf isn't an 
            // object (which implies it's already an open type), then
            // it should be marked as an open type.
            if (previous.TargetEdmType != null && !previous.TargetEdmType.IsOpenType())
            {
                throw ExceptionUtil.CreateResourceNotFoundError(segment.Identifier);
            }

            // Open navigation properties are not supported on OpenTypes.
            if (parenthesisExpression != null)
            {
                throw ExceptionUtil.CreateBadRequestError(ODataErrorStrings.OpenNavigationPropertiesNotSupportedOnOpenTypes(segment.Identifier));
            }

            this.parsedSegments.Add(segment);
        }
Пример #16
0
 /// <summary>
 /// Translate an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Translate</param>
 /// <returns>Translated WebApi path segment.</returns>
 public override IEnumerable <ODataPathSegment> Translate(OpenPropertySegment segment)
 {
     yield return(new DynamicPropertyPathSegment(segment.PropertyName));
 }
Пример #17
0
 /// <summary>
 /// Handle an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Handle</param>
 public virtual void Handle(OpenPropertySegment segment)
 {
     throw new NotImplementedException();
 }
 public void EqualityIsCorrect()
 {
     OpenPropertySegment openPropertySegment1 = new OpenPropertySegment("superbeans");
     OpenPropertySegment openPropertySegment2 = new OpenPropertySegment("superbeans");
     openPropertySegment1.Equals(openPropertySegment2).Should().BeTrue();
 }
 public void PropertyNameSetCorrectly()
 {
     OpenPropertySegment openPropertySegment = new OpenPropertySegment("beans");
     openPropertySegment.PropertyName.Should().Be("beans");
 }
 public void SingleResultIsTrue()
 {
     OpenPropertySegment openPropertySegment = new OpenPropertySegment("itblowsmymindhowmuchstuffthereisinhere");
     openPropertySegment.SingleResult.Should().BeTrue();
 }
 public void TargetKindIsOpenProperty()
 {
     OpenPropertySegment openPropertySegment = new OpenPropertySegment("anincredibleamountofstuff");
     openPropertySegment.TargetKind.Should().Be(RequestTargetKind.OpenProperty);
 }
 public void TargetEdmTypeIsNull()
 {
     OpenPropertySegment openPropertySegment = new OpenPropertySegment("evenmoreawesomestuff");
     openPropertySegment.TargetEdmType.Should().BeNull();
 }
Пример #23
0
 public override string Translate(OpenPropertySegment segment)
 {
     return(string.Format("(OpenProperty: {0})", segment.PropertyName));
 }
 /// <summary>
 /// Translate an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Translate</param>
 /// <returns>UserDefinedValue</returns>
 /// <exception cref="System.ArgumentNullException">Throws if the input segment is null.</exception>
 public override bool Translate(OpenPropertySegment segment)
 {
     ExceptionUtils.CheckArgumentNotNull(segment, "segment");
     return(false);
 }
Пример #25
0
 /// <summary>
 /// Translate OpenPropertySegment to linq expression.
 /// </summary>
 /// <param name="segment">The OpenPropertySegment</param>
 /// <returns>The linq expression</returns>
 public override Expression Translate(OpenPropertySegment segment)
 {
     throw new NotImplementedException("OpenPropertySegment translation is not supported");
 }
 /// <summary>
 /// Translate an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Translate</param>
 /// <returns>Defined by the implementer.</returns>
 public override string Translate(OpenPropertySegment segment)
 {
     throw new NotImplementedException();
 }
Пример #27
0
        public void TargetKindIsOpenProperty()
        {
            OpenPropertySegment openPropertySegment = new OpenPropertySegment("anincredibleamountofstuff");

            openPropertySegment.TargetKind.Should().Be(RequestTargetKind.OpenProperty);
        }
Пример #28
0
        public void SingleResultIsTrue()
        {
            OpenPropertySegment openPropertySegment = new OpenPropertySegment("itblowsmymindhowmuchstuffthereisinhere");

            openPropertySegment.SingleResult.Should().BeTrue();
        }
Пример #29
0
        public void PropertyNameSetCorrectly()
        {
            OpenPropertySegment openPropertySegment = new OpenPropertySegment("beans");

            openPropertySegment.PropertyName.Should().Be("beans");
        }
Пример #30
0
        public void IdentifierIsPropertyName()
        {
            OpenPropertySegment openPropertySegment = new OpenPropertySegment("stuff");

            openPropertySegment.Identifier.Should().Be("stuff");
        }
        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);
        }
Пример #32
0
 /// <summary>
 /// Translate an OpenPropertySegment
 /// </summary>
 /// <param name="segment">the segment to Translate</param>
 /// <returns>Defined by the implementer.</returns>
 public virtual T Translate(OpenPropertySegment segment)
 {
     throw new NotImplementedException();
 }
Пример #33
0
        public void TargetEdmTypeIsNull()
        {
            OpenPropertySegment openPropertySegment = new OpenPropertySegment("evenmoreawesomestuff");

            openPropertySegment.TargetEdmType.Should().BeNull();
        }