Ejemplo n.º 1
0
        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 = OrderByQueryValidator.GetOrderByQueryValidator(context);

            Assert.DoesNotThrow(() => validator.Validate(option, settings));
        }
Ejemplo n.º 2
0
        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 = OrderByQueryValidator.GetOrderByQueryValidator(context);

            Assert.Throws <ODataException>(() =>
                                           validator.Validate(option, settings),
                                           "Order by 'Value' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on EnableQueryAttribute or QueryValidationSettings.");
        }