Example #1
0
        /// <summary>
        /// Initialises a new instance of the <see cref="OrderByProperty"/> class.
        /// </summary>
        /// <param name="rawValue">The raw value.</param>
        /// <param name="model">The model.</param>
        /// <exception cref="ArgumentNullException">Thrown if raw value or model are null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If supplied, the direction should be either 'asc' or 'desc'.</exception>
        internal OrderByProperty(string rawValue, EdmComplexType model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            this.RawValue = rawValue ?? throw new ArgumentNullException(nameof(rawValue));

            var space = rawValue.IndexOf(' ');

            if (space == -1)
            {
                this.Property = model.GetProperty(rawValue);
            }
            else
            {
                this.Property = model.GetProperty(rawValue.Substring(0, space));

                switch (rawValue.Substring(space + 1, rawValue.Length - (space + 1)))
                {
                case "asc":
                    this.Direction = OrderByDirection.Ascending;
                    break;

                case "desc":
                    this.Direction = OrderByDirection.Descending;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(rawValue), Messages.OrderByPropertyRawValueInvalid);
                }
            }
        }
        /// <summary>
        /// Initialises a new instance of the <see cref="SelectExpandQueryOption" /> class.
        /// </summary>
        /// <param name="rawValue">The raw request value.</param>
        /// <param name="model">The model.</param>
        internal SelectExpandQueryOption(string rawValue, EdmComplexType model)
            : base(rawValue)
        {
            if (rawValue == "$select=*")
            {
                this.Properties = model.Properties;
            }
            else if (rawValue == "$expand=*")
            {
                // TODO: Expand is actually for navigation properties, not complex types...
                this.Properties = model.Properties
                                  .Where(p => p.PropertyType is EdmComplexType)
                                  .ToList();
            }
            else
            {
                var equals = rawValue.IndexOf('=') + 1;

                var properties = rawValue.Substring(equals, rawValue.Length - equals)
                                 .Split(SplitCharacter.Comma)
                                 .Select(p => model.GetProperty(p))
                                 .ToList();

                this.Properties = properties;
            }
        }
            public WhenConstructed()
            {
                TestHelper.EnsureEDM();

                EdmComplexType model = EntityDataModel.Current.EntitySets["Customers"].EdmType;

                _operand = new PropertyAccessNode(PropertyPath.For(model.GetProperty("CompanyName")));
                _node    = new UnaryOperatorNode(_operand, _unaryOperatorKind);
            }
            public WhenConstructed()
            {
                TestHelper.EnsureEDM();

                EdmComplexType model = EntityDataModel.Current.EntitySets["Customers"].EdmType;

                _propertyPath = PropertyPath.For(model.GetProperty("CompanyName"));
                _node         = new PropertyAccessNode(_propertyPath);
            }
        public void GetProperty_ReturnsProperty()
        {
            TestHelper.EnsureEDM();

            EdmComplexType edmComplexType = EntityDataModel.Current.EntitySets["Customers"].EdmType;

            EdmProperty edmProperty = edmComplexType.GetProperty("CompanyName");

            Assert.NotNull(edmProperty);
            Assert.Equal("CompanyName", edmProperty.Name);
        }
        public void GetProperty_Throws_ODataException_If_PropertyNameNotFound()
        {
            TestHelper.EnsureEDM();

            EdmComplexType edmComplexType = EntityDataModel.Current.EntitySets["Customers"].EdmType;

            ODataException odataException = Assert.Throws <ODataException>(() => edmComplexType.GetProperty("Name"));

            Assert.Equal(ExceptionMessage.EdmTypeDoesNotContainProperty("Sample.Model.Customer", "Name"), odataException.Message);
            Assert.Equal(HttpStatusCode.BadRequest, odataException.StatusCode);
            Assert.Equal("Sample.Model.Customer", odataException.Target);
        }