Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
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 = new OrderByQueryValidator();

            Assert.DoesNotThrow(() => validator.Validate(option, settings));
        }
Ejemplo n.º 3
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 = 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.");
        }
Ejemplo n.º 4
0
 public OrderByQueryValidatorTest()
 {
     _validator = new OrderByQueryValidator();
     _context   = ValidationTestHelper.CreateCustomerContext();
 }
        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);
        }
 public OrderByQueryValidatorTest()
 {
     _validator = new OrderByQueryValidator();
     _context = ValidationTestHelper.CreateCustomerContext();
 }
Ejemplo n.º 9
0
 public OrderByQueryValidatorTest()
 {
     _context   = ValidationTestHelper.CreateCustomerContext();
     _validator = new OrderByQueryValidator(_context.DefaultQuerySettings);
 }