public void Validate_ThrowsIfTryingToValidateALimitedProperty(string query, string edmTypeName, string message)
        {
            // Arrange
            IEdmModel               model    = GetEdmModel();
            IEdmEntityType          edmType  = model.SchemaElements.OfType <IEdmEntityType>().Single(t => t.Name == edmTypeName);
            ODataQueryContext       context  = new ODataQueryContext(model, edmType);
            OrderByQueryOption      option   = new OrderByQueryOption(query, context);
            ODataValidationSettings settings = new ODataValidationSettings();

            // Act & Assert
            OrderByQueryValidator validator = new OrderByQueryValidator();

            Assert.Throws <ODataException>(() => validator.Validate(option, settings), message);
        }
        public void Validate_DoesntThrowIfTheLeafOfThePathIsWithinTheAllowedProperties()
        {
            // Arrange
            IEdmModel               model    = GetEdmModel();
            IEdmEntityType          edmType  = model.SchemaElements.OfType <IEdmEntityType>().Single(t => t.Name == "LimitedEntity");
            ODataQueryContext       context  = new ODataQueryContext(model, edmType);
            OrderByQueryOption      option   = new OrderByQueryOption("ComplexProperty/Value", context);
            ODataValidationSettings settings = new ODataValidationSettings();

            settings.AllowedOrderByProperties.Add("Value");

            // Act & Assert
            OrderByQueryValidator validator = new OrderByQueryValidator();

            Assert.DoesNotThrow(() => validator.Validate(option, settings));
        }
        public void Validate_ThrowsIfTheLeafOfThePathIsntWithinTheAllowedProperties()
        {
            // Arrange
            IEdmModel               model    = GetEdmModel();
            IEdmEntityType          edmType  = model.SchemaElements.OfType <IEdmEntityType>().Single(t => t.Name == "LimitedEntity");
            ODataQueryContext       context  = new ODataQueryContext(model, edmType);
            OrderByQueryOption      option   = new OrderByQueryOption("ComplexProperty/Value", context);
            ODataValidationSettings settings = new ODataValidationSettings();

            settings.AllowedOrderByProperties.Add("NotSortableProperty");

            // Act & Assert
            OrderByQueryValidator validator = new OrderByQueryValidator();

            Assert.Throws <ODataException>(() =>
                                           validator.Validate(option, settings),
                                           "Order by 'Value' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on EnableQueryAttribute or QueryValidationSettings.");
        }
        public void Validate_ThrowsIfTheLeafOfThePathIsntWithinTheAllowedProperties()
        {
            // Arrange
            IEdmModel model = GetEdmModel();
            IEdmEntityType edmType = model.SchemaElements.OfType<IEdmEntityType>().Single(t => t.Name == "LimitedEntity");
            ODataQueryContext context = new ODataQueryContext(model, edmType);
            OrderByQueryOption option = new OrderByQueryOption("ComplexProperty/Value", context);
            ODataValidationSettings settings = new ODataValidationSettings();
            settings.AllowedOrderByProperties.Add("UnsortableProperty");

            // Act & Assert
            OrderByQueryValidator validator = new OrderByQueryValidator();
            Assert.Throws<ODataException>(() =>
                validator.Validate(option, settings),
                "Order by 'Value' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on EnableQueryAttribute or QueryValidationSettings.");
        }
        public void Validate_DoesntThrowIfTheLeafOfThePathIsWithinTheAllowedProperties()
        {
            // Arrange
            IEdmModel model = GetEdmModel();
            IEdmEntityType edmType = model.SchemaElements.OfType<IEdmEntityType>().Single(t => t.Name == "LimitedEntity");
            ODataQueryContext context = new ODataQueryContext(model, edmType);
            OrderByQueryOption option = new OrderByQueryOption("ComplexProperty/Value", context);
            ODataValidationSettings settings = new ODataValidationSettings();
            settings.AllowedOrderByProperties.Add("Value");

            // Act & Assert
            OrderByQueryValidator validator = new OrderByQueryValidator();
            Assert.DoesNotThrow(() => validator.Validate(option, settings));
        }
        public void Validate_ThrowsIfTryingToValidateALimitedProperty(string query, string edmTypeName, string message)
        {
            // Arrange
            IEdmModel model = GetEdmModel();
            IEdmEntityType edmType = model.SchemaElements.OfType<IEdmEntityType>().Single(t => t.Name == edmTypeName);
            ODataQueryContext context = new ODataQueryContext(model, edmType);
            OrderByQueryOption option = new OrderByQueryOption(query, context);
            ODataValidationSettings settings = new ODataValidationSettings();

            // Act & Assert
            OrderByQueryValidator validator = new OrderByQueryValidator();
            Assert.Throws<ODataException>(() => validator.Validate(option, settings), message);
        }