Example #1
0
            public PayloadReaderTestDescriptor ToTestDescriptor(PayloadReaderTestDescriptor.Settings settings, IEdmModel model, bool withMetadataAnnotation = false)
            {
                IEdmEntityContainer container       = model.FindEntityContainer("DefaultContainer");
                IEdmEntitySet       citiesEntitySet = container.FindEntitySet("Cities");
                IEdmType            cityType        = model.FindType("TestModel.CityType");

                EntityInstance entity = PayloadBuilder.Entity("TestModel.CityType")
                                        .ExpectedEntityType(cityType, citiesEntitySet)
                                        .JsonRepresentation(
                    "{" +
                    (withMetadataAnnotation ? ("\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://http://odata.org/test/$metadata#DefaultContainer.Cities/$entity\",") : string.Empty) +
                    "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.CityType\"," +
                    this.Json +
                    ",\"Id\":1" +
                    "}");

                foreach (PropertyInstance property in this.ExpectedEntity.Properties)
                {
                    entity.Add(property.DeepCopy());
                }

                entity.Add(PayloadBuilder.PrimitiveProperty("Id", 1));

                return(new NavigationLinkTestCaseDescriptor(settings)
                {
                    DebugDescription = this.DebugDescription,
                    PayloadElement = entity,
                    PayloadEdmModel = model,
                    ExpectedException = this.ExpectedException,
                    ExpectedIsCollectionValues = this.ExpectedIsCollectionValues,
                });
            }
            public PayloadReaderTestDescriptor ToTestDescriptor(PayloadReaderTestDescriptor.Settings settings, IEdmModel model, bool throwOnUndeclaredPropertyForNonOpenType)
            {
                var cityType = model.FindDeclaredType("TestModel.CityType").ToTypeReference();
                var cities = model.EntityContainer.FindEntitySet("Cities");
                EntityInstance entity = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                    .ExpectedEntityType(cityType, cities)
                    .JsonRepresentation(
                        "{" +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities()/$entity\"," +
                            "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.CityType\"," +
                            "\"Id\":1," +
                            this.Json +
                        "}");
                foreach (PropertyInstance property in this.ExpectedEntity.Properties)
                {
                    entity.Add(property.DeepCopy());
                }

                ExpectedException expectedException = this.ExpectedException;
                if (throwOnUndeclaredPropertyForNonOpenType)
                {
                    expectedException = ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "UndeclaredProperty", "TestModel.CityType");
                }

                return new PayloadReaderTestDescriptor(settings)
                {
                    DebugDescription = this.DebugDescription,
                    PayloadElement = entity,
                    PayloadEdmModel = model,
                    ExpectedException = expectedException
                };
            }
 internal PayloadReaderTestDescriptor ToEdmPayloadReaderTestDescriptor(PayloadReaderTestDescriptor.Settings payloadTestDescriptorSettings, PayloadReaderTestExpectedResult.PayloadReaderTestExpectedResultSettings payloadExpectedResultSettings)
 {
     return(new PayloadReaderTestDescriptor(payloadTestDescriptorSettings)
     {
         PayloadElement = this.Json,
         PayloadEdmModel = this.EdmModel,
         SkipTestConfiguration = this.SkipTestConfiguration,
         ExpectedResultCallback = (testConfig) =>
                                  new PayloadReaderTestExpectedResult(payloadExpectedResultSettings)
         {
             ExpectedException = this.ExpectedExceptionFunc == null ? null : this.ExpectedExceptionFunc(this, testConfig),
         }
     });
 }
Example #4
0
        public static IEnumerable <PayloadReaderTestDescriptor> CreateStreamPropertyMetadataTestDescriptors(PayloadReaderTestDescriptor.Settings settings)
        {
            // Get the standard stream property payloads
            IEnumerable <PayloadReaderTestDescriptor> streamPropertyTestDescriptors = PayloadReaderTestDescriptorGenerator.CreateStreamReferenceValueTestDescriptors(settings, withMetadata: true);

            // Add some reader specific payloads
            EdmModel model = new EdmModel().Fixup();

            streamPropertyTestDescriptors = streamPropertyTestDescriptors.Concat(new PayloadReaderTestDescriptor[]
            {
                // Just read link - valid for readers
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", readLink: "http://odata.org/mr"),
                    PayloadEdmModel = model,
                },
                // Just content type
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", contentType: "mime/type"),
                    PayloadEdmModel = model,
                    // Doesn't work for ATOM as ATOM needs the self link to put the content type on
                    SkipTestConfiguration = tc => false
                },
                // Read link and content type
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", readLink: "http://odata.org/mr", contentType: "mime/type"),
                    PayloadEdmModel = model,
                },
                // Just edit link - valid for readers
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", editLink: "http://odata.org/mr"),
                    PayloadEdmModel = model,
                },
                // Just etag
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", etag: "etag"),
                    PayloadEdmModel = model,
                    // Doesn't work for ATOM as ATOM needs the edit link to put the etag on
                    SkipTestConfiguration = tc => false
                },
                // Just edit link and etag - valid for readers
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", editLink: "http://odata.org/mr", etag: "etag"),
                    PayloadEdmModel = model,
                },
                // All properties
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement  = PayloadBuilder.StreamProperty("StreamProperty", readLink: "http://odata.org/mrread", contentType: "mime/type", editLink: "http://odata.org/mr", etag: "etag"),
                    PayloadEdmModel = model,
                },

                // TODO: Add more tests around values for the stream properties. Readers won't validate anything, so empty values are acceptable
            });

            return(streamPropertyTestDescriptors);
        }
Example #5
0
        private static IEnumerable <PayloadReaderTestDescriptor> CreateUndeclaredPropertyBehaviorKindStreamPropertyTestDescriptors(bool throwOnUndeclaredPropertyForNonOpenType, PayloadReaderTestDescriptor.Settings settings)
        {
            IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                // Undeclared stream property with read-link only.
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("UndeclaredProperty", "http://odata.org/readlink"),
                    PayloadEdmModel   = model,
                    ExpectedException = throwOnUndeclaredPropertyForNonOpenType
                                            ? ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "UndeclaredProperty", "TestModel.CityType")
                                            : null
                },
                // Undeclared stream property with edit-link only.
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("UndeclaredProperty", null, "http://odata.org/editlink"),
                    PayloadEdmModel   = model,
                    ExpectedException = throwOnUndeclaredPropertyForNonOpenType
                                            ? ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "UndeclaredProperty", "TestModel.CityType")
                                            : null
                },
                // Undeclared stream property with all properties.
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).StreamProperty("UndeclaredProperty", "http://odata.org/readlink", "http://odata.org/editlink", "stream/content", "stream:etag"),
                    PayloadEdmModel   = model,
                    ExpectedException = throwOnUndeclaredPropertyForNonOpenType
                                            ? ODataExpectedExceptions.ODataException("ValidationUtils_PropertyDoesNotExistOnType", "UndeclaredProperty", "TestModel.CityType")
                                            : null
                },
            };

            return(testDescriptors);
        }
Example #6
0
 internal BatchReaderMixedEncodingTestDescriptor(PayloadReaderTestDescriptor.Settings settings)
     : base(settings)
 {
 }
 /// <summary>
 /// Constructor for NavigationLinkTestCaseDescriptor.
 /// </summary>
 /// <param name="settings">The settings.</param>
 public NavigationLinkTestCaseDescriptor(PayloadReaderTestDescriptor.Settings settings)
     : base(settings)
 {
 }
Example #8
0
        /// <summary>
        /// Creates invalid error representations in JSON (e.g., extra properties where they are not allowed,
        /// invalid property value types, etc.) - no duplicate properties.
        /// </summary>
        /// <param name="settings">The test descriptor settings to use for the generated <see cref="PayloadReaderTestDescriptor"/>.</param>
        /// <param name="isJsonLight">true if the payloads should be in Json lite format; false if they should be in verbose Json.</param>
        /// <returns>An enumerable of <see cref="PayloadReaderTestDescriptor"/> representing the invalid error payloads.</returns>
        public static IEnumerable <PayloadReaderTestDescriptor> CreateInvalidErrorDescriptors(PayloadReaderTestDescriptor.Settings settings, bool isJsonLight)
        {
            string errorPropertyName = JsonLightConstants.ODataErrorPropertyName;

            return(new PayloadReaderTestDescriptor[]
            {
                #region Extra properties at the top-level
                // extra properties in top-level object
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error("foo").Message("msg1")
                                     .JsonRepresentation("{ \"foo\": \"bar\" }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty", "foo"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error("foo").Message("msg1")
                                     .JsonRepresentation("{ \"foo\": \"bar\", \"" + errorPropertyName + "\": { } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty", "foo"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error("foo").Message("msg1")
                                     .JsonRepresentation("{ \"" + errorPropertyName + "\": { }, \"foo\": \"bar\" }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonErrorDeserializer_TopLevelErrorWithInvalidProperty", "foo"),
                },

                // extra properties in top-level error object
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"foo\": \"bar\" } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightErrorDeserializer_TopLevelErrorValueWithInvalidProperty", "foo"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error("foo").Message("msg1")
                                     .JsonRepresentation("{ \"" + errorPropertyName + "\": { \"message\": \"msg1\", \"foo\": \"bar\" } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightErrorDeserializer_TopLevelErrorValueWithInvalidProperty", "foo"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error("foo").Message("msg1")
                                     .JsonRepresentation("{ \"" + errorPropertyName + "\": { \"foo\": \"bar\", \"message\": \"msg1\" , \"foo2\": \"bar2\" } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightErrorDeserializer_TopLevelErrorValueWithInvalidProperty", "foo"),
                },
                #endregion Extra properties at the top-level

                #region Invalid property values
                // invalid property values for top-level error property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": null }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": 42 }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": [ ] }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray"),
                },

                // invalid property values for message property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"message\": [ ] }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"message\": 42 }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_CannotReadPropertyValueAsString", "42", "message"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"message\": {} }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },

                // invalid property values for innererror value property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": 42 }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": [ ] }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray"),
                },

                // invalid property values for message property on innererror value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"message\": { } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"message\": [ ] } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },

                // invalid property values for stacktrace property on innererror value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"stacktrace\": { } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"stacktrace\": [ ] } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },

                // invalid property values for type name property on innererror value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"type\": { } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"type\": [ ] } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },

                // invalid property values for internal exception property on innererror value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": 42 }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": [ ] } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray"),
                },

                // invalid property values for message property on internal exception property value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": { \"message\": { } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": { \"message\": [ ] } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },

                // invalid property values for stacktrace property on internal exception property value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": { \"stacktrace\": { } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": { \"stacktrace\": [ ] } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },

                // invalid property values for type name property on internal exception property value
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": { \"type\": { } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().JsonRepresentation("{ \"" + errorPropertyName + "\": { \"innererror\": { \"internalexception\": { \"type\": [ ] } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },
                #endregion Invalid property values
            });
        }
Example #9
0
        public void TopLevelInvalidErrorTestWithDuplicateDataProperties()
        {
            PayloadReaderTestDescriptor.Settings      settings        = this.Settings;
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                #region Duplicate properties
                // duplicate 'error' property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"message\": \"Error message\" }, \"error\": { \"message\": \"Error message\" } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonReaderUtils_MultipleErrorPropertiesWithSameName", "error"),
                },

                // duplicate 'code' property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"code\": \"Error code\", \"code\": \"Error code\" } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "code"),
                },

                // duplicate 'message' property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"message\": \"Error message\", \"message\": \"Error message\" } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "message"),
                },

                // duplicate 'innererror' property
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"code\": \"Error code\", \"innererror\": { }, \"innererror\": { } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "innererror"),
                },

                // duplicate 'message' property (on the inner error)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"code\": \"Error code\", \"innererror\": { \"message\": \"Inner msg\", \"message\": \"Inner msg\" } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "message"),
                },

                // duplicate 'type' property (on the inner error)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"code\": \"Error code\", \"innererror\": { \"type\": \"Some typename\", \"type\": \"Some typename\" } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "type"),
                },

                // duplicate 'stacktrace' property (on the inner error)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"code\": \"Error code\", \"innererror\": { \"stacktrace\": \"stack trace\", \"stacktrace\": \"stack trace\" } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "stacktrace"),
                },

                // duplicate 'internalexception' property (on the inner error)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement    = PayloadBuilder.Error().JsonRepresentation("{ \"error\": { \"code\": \"Error code\", \"innererror\": { \"internalexception\": { }, \"internalexception\": { } } } }"),
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesChecker_DuplicatePropertyNamesNotAllowed", "internalexception"),
                },
                #endregion Duplicate properties
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest),
                // Disable WCF DS Server behavior since in that case duplicate properties are eliminated and the code will not see them.
                TestReaderUtils.ODataBehaviorKinds.Where(behavior => behavior != TestODataBehaviorKind.WcfDataServicesServer),
                (testDescriptor, testConfiguration, behavior) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration.CloneAndApplyBehavior(behavior));
            });
        }
        /// <summary>
        /// Creates invalid error representations in ATOM (e.g., extra properties where they are not allowed,
        /// invalid property value types, etc.)
        /// </summary>
        /// <param name="settings">The test descriptor settings to use for the generated <see cref="PayloadReaderTestDescriptor"/>.</param>
        /// <returns>An enumerable of <see cref="PayloadReaderTestDescriptor"/> representing the invalid error payloads.</returns>
        private static IEnumerable <PayloadReaderTestDescriptor> CreateInvalidErrorDescriptors(PayloadReaderTestDescriptor.Settings settings)
        {
            return(new PayloadReaderTestDescriptor[]
            {
                #region Duplicate error elements
                // duplicate 'm:code' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().Code("ErrorCode").XmlRepresentation("<m:error><m:code>ErrorCode</m:code><m:code>ErrorCode2</m:code></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleErrorElementsWithSameName", "code")
                },
                // duplicate 'm:message' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().Message("ErrorMessage").XmlRepresentation("<m:error><m:message>ErrorMessage</m:message><m:message>ErrorMessage2</m:message></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleErrorElementsWithSameName", "message")
                },
                // duplicate 'm:innererror' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(new ODataInternalExceptionPayload()).XmlRepresentation("<m:error><m:innererror></m:innererror><m:innererror></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleErrorElementsWithSameName", "innererror")
                },
                // duplicate (inner) 'm:message' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(new ODataInternalExceptionPayload().Message("InnerMessage")).XmlRepresentation("<m:error><m:innererror><m:message>InnerMessage</m:message><m:message>InnerMessage2</m:message></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName", "message")
                },
                // duplicate (inner) 'm:type' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(new ODataInternalExceptionPayload().TypeName("TypeName")).XmlRepresentation("<m:error><m:innererror><m:type>TypeName</m:type><m:type>TypeName2</m:type></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName", "type")
                },
                // duplicate (inner) 'm:stacktrace' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(new ODataInternalExceptionPayload().StackTrace("StackTrace")).XmlRepresentation("<m:error><m:innererror><m:stacktrace>StackTrace</m:stacktrace><m:stacktrace>StackTrace2</m:stacktrace></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName", "stacktrace")
                },
                // duplicate (inner) 'm:internalexception' element
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(new ODataInternalExceptionPayload().InnerError(new ODataInternalExceptionPayload())).XmlRepresentation("<m:error><m:innererror><m:internalexception></m:internalexception><m:internalexception></m:internalexception></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomErrorDeserializer_MultipleInnerErrorElementsWithSameName", "internalexception")
                },
                #endregion Duplicate error elements

                #region Element content in string elements
                // Element content in <m:code>
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().Code("ErrorCode").XmlRepresentation("<m:error><m:code><foo></foo>ErrorCode<bar /></m:code></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("XmlReaderExtension_InvalidNodeInStringValue", "Element"),
                },
                // Element content in <m:message>
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().Message("Message").XmlRepresentation("<m:error><m:message><foo></foo>Message<bar /></m:message></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("XmlReaderExtension_InvalidNodeInStringValue", "Element"),
                },
                // Element content in <m:message> (inner)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(PayloadBuilder.InnerError().Message("Message"))
                                     .XmlRepresentation("<m:error><m:innererror><m:message><foo></foo>Message<bar /></m:message></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("XmlReaderExtension_InvalidNodeInStringValue", "Element"),
                },
                // Element content in <m:type> (inner)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(PayloadBuilder.InnerError().TypeName("Type"))
                                     .XmlRepresentation("<m:error><m:innererror><m:type><foo></foo>TypeName<bar /></m:type></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("XmlReaderExtension_InvalidNodeInStringValue", "Element"),
                },
                // Element content in <m:stacktrace> (inner)
                new PayloadReaderTestDescriptor(settings)
                {
                    PayloadElement = PayloadBuilder.Error().InnerError(PayloadBuilder.InnerError().StackTrace("StackTrace"))
                                     .XmlRepresentation("<m:error><m:innererror><m:stacktrace><foo></foo>StackTrace<bar /></m:stacktrace></m:innererror></m:error>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("XmlReaderExtension_InvalidNodeInStringValue", "Element"),
                },
                #endregion Element content in string elements
            });
        }
Example #11
0
 internal ReaderEncodingTestDescriptor(PayloadReaderTestDescriptor.Settings settings, string contentType)
     : base(settings)
 {
     this.contentType = contentType;
 }