/// <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 <paramref name="rawValue"/> or <paramref name="model"/> are null.</exception>
        /// <exception cref="ODataException">Thrown if there is an error parsing the <paramref name="rawValue"/>.</exception>
        internal OrderByProperty(string rawValue, EdmComplexType model)
        {
            RawValue = rawValue ?? throw new ArgumentNullException(nameof(rawValue));

            if (model is null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (rawValue.IndexOf(' ') == -1)
            {
                PropertyPath = PropertyPath.For(rawValue, model);
            }
            else
            {
                PropertyPath = PropertyPath.For(rawValue.SubstringBefore(' '), model);

                if (rawValue.EndsWith(" asc", StringComparison.Ordinal))
                {
                    Direction = OrderByDirection.Ascending;
                }
                else if (rawValue.EndsWith(" desc", StringComparison.Ordinal))
                {
                    Direction = OrderByDirection.Descending;
                }
                else
                {
                    throw ODataException.BadRequest(ExceptionMessage.InvalidOrderByDirection(rawValue.SubstringAfter(' '), PropertyPath.Property.Name), "$orderby");
                }
            }
        }
Beispiel #2
0
            public void AnArgumentOutOfRangeExceptionShouldBeThrown()
            {
                TestHelper.EnsureEDM();

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

                ODataException odataException = Assert.Throws <ODataException>(() => new OrderByProperty("CompanyName wibble", model));

                Assert.Equal(ExceptionMessage.InvalidOrderByDirection("wibble", "CompanyName"), odataException.Message);
                Assert.Equal(HttpStatusCode.BadRequest, odataException.StatusCode);
                Assert.Equal("$orderby", odataException.Target);
            }