Пример #1
0
        /// <summary>
        /// For a given payload element determines its test configuration limits.
        /// </summary>
        /// <param name="payloadElement">The payload element to check.</param>
        /// <param name="validators">The collection of validators to use.</param>
        /// <returns>The test configuration limits computed.</returns>
        public static TestConfigurationLimits GetTestConfigurationLimits(ODataPayloadElement payloadElement, Validators validators)
        {
            TestConfigurationLimits testConfigLimits = new TestConfigurationLimits();

            new Visitor(validators, testConfigLimits).Visit(payloadElement);
            return(testConfigLimits);
        }
Пример #2
0
            /// <summary>
            /// Applies validators to the specified element.
            /// </summary>
            /// <param name="element">The payload element to apply the validators to.</param>
            /// <param name="testConfigLimits">The test configuration limits to modify.</param>
            public void Apply(ODataPayloadElement element, TestConfigurationLimits testConfigLimits)
            {
                List <ConfigurationValidator> validators;

                if (this.map.TryGetValue(element.ElementType, out validators))
                {
                    foreach (var validator in validators)
                    {
                        validator(element, testConfigLimits);
                    }
                }
            }
Пример #3
0
        /// <summary>
        /// Validator for spatial values.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void SpatialValueValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            PrimitiveValue primitiveValue = payloadElement as PrimitiveValue;

            ExceptionUtilities.Assert(primitiveValue != null, "This validator only works on primitive values.");

            if (primitiveValue.ClrValue is ISpatial)
            {
                // Spatial values require V3.
                testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
            }
            else if (primitiveValue.ClrValue == null)
            {
                EntityModelTypeAnnotation typeAnnotation = primitiveValue.GetAnnotation <EntityModelTypeAnnotation>();
                if (typeAnnotation != null && typeAnnotation.EdmModelType.Definition.IsSpatial())
                {
                    testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
                }
            }
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="validators">The validators collection to use.</param>
 /// <param name="testConfigLimits">The test configuration limits to modify.</param>
 public Visitor(Validators validators, TestConfigurationLimits testConfigLimits)
 {
     this.validators = validators;
     this.testConfigLimits = testConfigLimits;
 }
 /// <summary>
 /// For a given payload element determines its test configuration limits.
 /// </summary>
 /// <param name="payloadElement">The payload element to check.</param>
 /// <param name="validators">The collection of validators to use.</param>
 /// <returns>The test configuration limits computed.</returns>
 public static TestConfigurationLimits GetTestConfigurationLimits(ODataPayloadElement payloadElement, Validators validators)
 {
     TestConfigurationLimits testConfigLimits = new TestConfigurationLimits();
     new Visitor(validators, testConfigLimits).Visit(payloadElement);
     return testConfigLimits;
 }
        /// <summary>
        /// Validator for actions and functions.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void ActionAndFunctionValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            EntityInstance entityInstance = payloadElement as EntityInstance;
            ExceptionUtilities.Assert(entityInstance != null, "This validator only works on entity instances.");

            if (entityInstance.ServiceOperationDescriptors.Any())
            {
                // Actions and Functions require V3 response payloads.
                testConfigLimits.DisallowRequest();
                testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
            }
        }
        /// <summary>
        /// Validator for spatial values.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void SpatialValueValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            PrimitiveValue primitiveValue = payloadElement as PrimitiveValue;
            ExceptionUtilities.Assert(primitiveValue != null, "This validator only works on primitive values.");

            if (primitiveValue.ClrValue is ISpatial)
            {
                // Spatial values require V3.
                testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
            }
            else if (primitiveValue.ClrValue == null)
            {
                EntityModelTypeAnnotation typeAnnotation = primitiveValue.GetAnnotation<EntityModelTypeAnnotation>();
                if (typeAnnotation != null && typeAnnotation.EdmModelType.Definition.IsSpatial())
                {
                    testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
                }
            }
        }
        /// <summary>
        /// Validator for stream properties in requests.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void AssociationLinkValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            NavigationPropertyInstance navigationProperty = payloadElement as NavigationPropertyInstance;
            ExceptionUtilities.Assert(navigationProperty != null, "This validator only works on navigation properties.");

            if (navigationProperty.AssociationLink != null)
            {
                // Association links are not allowed in requests.
                testConfigLimits.DisallowRequest();

                // Association links can only be read if MPV >= V3, they are recognized even in <V3 payloads
                // but we don't have a way to specify this here, so just mark them as >=V3 as well.
                testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
            }
        }
        /// <summary>
        /// Validator for stream properties in requests.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void StreamPropertyValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            ExceptionUtilities.Assert(payloadElement is NamedStreamInstance, "This validator only works on stream properties.");

            // Stream properties are not allowed in requests.
            testConfigLimits.DisallowRequest();

            // Stream properties are only allowed in >=V3 requests.
            testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
        }
        /// <summary>
        /// Validator for collections of primitive and complex types.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void NonEntityCollectionValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            ExceptionUtilities.Assert(payloadElement is PrimitiveMultiValue || payloadElement is ComplexMultiValue, "This validator only works on collection values.");

            // Collection values require V3.
            testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
        }
 /// <summary>
 /// Applies validators to the specified element.
 /// </summary>
 /// <param name="element">The payload element to apply the validators to.</param>
 /// <param name="testConfigLimits">The test configuration limits to modify.</param>
 public void Apply(ODataPayloadElement element, TestConfigurationLimits testConfigLimits)
 {
     List<ConfigurationValidator> validators;
     if (this.map.TryGetValue(element.ElementType, out validators))
     {
         foreach (var validator in validators)
         {
             validator(element, testConfigLimits);
         }
     }
 }
Пример #12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="validators">The validators collection to use.</param>
 /// <param name="testConfigLimits">The test configuration limits to modify.</param>
 public Visitor(Validators validators, TestConfigurationLimits testConfigLimits)
 {
     this.validators       = validators;
     this.testConfigLimits = testConfigLimits;
 }
Пример #13
0
        /// <summary>
        /// Validator for actions and functions.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void ActionAndFunctionValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            EntityInstance entityInstance = payloadElement as EntityInstance;

            ExceptionUtilities.Assert(entityInstance != null, "This validator only works on entity instances.");

            if (entityInstance.ServiceOperationDescriptors.Any())
            {
                // Actions and Functions require V3 response payloads.
                testConfigLimits.DisallowRequest();
                testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
            }
        }
Пример #14
0
        /// <summary>
        /// Validator for stream properties in requests.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void AssociationLinkValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            NavigationPropertyInstance navigationProperty = payloadElement as NavigationPropertyInstance;

            ExceptionUtilities.Assert(navigationProperty != null, "This validator only works on navigation properties.");

            if (navigationProperty.AssociationLink != null)
            {
                // Association links are not allowed in requests.
                testConfigLimits.DisallowRequest();

                // Association links can only be read if MPV >= V3, they are recognized even in <V3 payloads
                // but we don't have a way to specify this here, so just mark them as >=V3 as well.
                testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
            }
        }
Пример #15
0
        /// <summary>
        /// Validator for stream properties in requests.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void StreamPropertyValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            ExceptionUtilities.Assert(payloadElement is NamedStreamInstance, "This validator only works on stream properties.");

            // Stream properties are not allowed in requests.
            testConfigLimits.DisallowRequest();

            // Stream properties are only allowed in >=V3 requests.
            testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
        }
Пример #16
0
        /// <summary>
        /// Validator for collections of primitive and complex types.
        /// </summary>
        /// <param name="payloadElement">The payload element to validate.</param>
        /// <param name="testConfigLimits">The test configuration limits to modify.</param>
        public static void NonEntityCollectionValidator(ODataPayloadElement payloadElement, TestConfigurationLimits testConfigLimits)
        {
            ExceptionUtilities.Assert(payloadElement is PrimitiveMultiValue || payloadElement is ComplexMultiValue, "This validator only works on collection values.");

            // Collection values require V3.
            testConfigLimits.RaiseMinPayloadVersion(ODataVersion.V4);
        }