public void InStreamAtomDeeplyRecursiveErrorTest() { int depthLimit = 5; IEnumerable <PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateErrorDeeplyNestedReaderTestDescriptors(this.Settings, depthLimit); // Convert the payload element to an Xml representation usable for in-stream error testing testDescriptors = testDescriptors.Select(td => { XElement xmlPayload = this.PayloadElementToXmlConverter.ConvertToXml(td.PayloadElement); return(new PayloadReaderTestDescriptor(td) { PayloadElement = td.PayloadElement.XmlRepresentation(xmlPayload) }); }); // Convert top-level error test descriptors to in-stream errors. testDescriptors = testDescriptors.Select(td => td.ToInStreamErrorTestDescriptor(ODataFormat.Atom)); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations.Where(tc => !tc.IsRequest), (testDescriptor, testConfiguration) => { // Copy the test configuration so we can modify the depth limit. testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.MessageQuotas.MaxNestingDepth = depthLimit; testDescriptor.RunTest(testConfiguration); }); }
/// <summary> /// Called to write the payload to the specified <paramref name="messageWriter"/>. /// </summary> /// <param name="messageWriter">The <see cref="ODataMessageWriterTestWrapper"/> to use for writing the payload.</param> /// <param name="testConfiguration">The test configuration to generate the payload for.</param> protected override void WritePayload(ODataMessageWriterTestWrapper messageWriter, WriterTestConfiguration testConfiguration) { Debug.Assert(this.messageStream != null, "Streaming test stream must have been created."); TestMessage testMessage = this.CreateInputMessageFromStream((TestStream)this.messageStream, testConfiguration, this.PayloadKind, string.Empty, this.UrlResolver); testMessage.SetContentType(testConfiguration.Format, this.PayloadKind); Exception exception = TestExceptionUtils.RunCatching(() => { ODataMessageReaderSettings readerSettings = this.settings.MessageReaderSettings.Clone(); readerSettings.EnableMessageStreamDisposal = testConfiguration.MessageWriterSettings.EnableMessageStreamDisposal; ReaderTestConfiguration readerConfig = new ReaderTestConfiguration( testConfiguration.Format, readerSettings, testConfiguration.IsRequest, testConfiguration.Synchronous); IEdmModel model = this.GetMetadataProvider(); using (ODataMessageReaderTestWrapper messageReaderWrapper = TestReaderUtils.CreateMessageReader(testMessage, model, readerConfig)) { ODataPayloadElementToObjectModelConverter payloadElementToOMConverter = new ODataPayloadElementToObjectModelConverter(!testConfiguration.IsRequest); ObjectModelToPayloadElementConverter reverseConverter = new ObjectModelToPayloadElementConverter(); ObjectModelWriteReadStreamer streamer = new ObjectModelWriteReadStreamer(); this.readObject = reverseConverter.Convert(streamer.WriteMessage(messageWriter, messageReaderWrapper, this.PayloadKind, payloadElementToOMConverter.Convert(this.PayloadElement)), !testConfiguration.IsRequest); } }); }
protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { TestMessage testMessage = base.CreateInputMessage(testConfiguration); testMessage.SetHeader(ODataConstants.ContentTypeHeader, contentType); return(testMessage); }
private void RunMessageSizeLimitTests( IEnumerable <ReaderTestConfiguration> testConfigurations, EdmModel model, ODataPayloadElement payload, MessageSizeLimitTestCase[] testCases, Func <ReaderTestConfiguration, bool> skipTestConfigurationFunc = null) { var transformScope = this.Settings.PayloadTransformFactory.EmptyScope(); using (transformScope.Apply()) { this.CombinatorialEngineProvider.RunCombinations( testCases, testConfigurations, (testCase, testConfiguration) => { int size = -1; if (testConfiguration.Format == ODataFormat.Atom && testCase.AtomSizes != null) { size = testConfiguration.IsRequest ? testCase.AtomSizes.RequestSize : testCase.AtomSizes.ResponseSize; } else if (testConfiguration.Format == ODataFormat.Json && testCase.JsonLightSizes != null) { size = testConfiguration.IsRequest ? testCase.JsonLightSizes.RequestSize : testCase.JsonLightSizes.ResponseSize; } else if (testCase.RawSizes != null) { size = testConfiguration.IsRequest ? testCase.RawSizes.RequestSize : testCase.RawSizes.ResponseSize; } int maxSize = testCase.MaxMessageSize >= 0 ? testCase.MaxMessageSize : 1024 * 1024; ExpectedException expectedException = size < 0 ? null : ODataExpectedExceptions.ODataException("MessageStreamWrappingStream_ByteLimitExceeded", size.ToString(), maxSize.ToString()); var testDescriptor = new PayloadReaderTestDescriptor(this.Settings) { PayloadEdmModel = model, PayloadElement = payload.DeepCopy(), ExpectedException = expectedException, SkipTestConfiguration = skipTestConfigurationFunc, ApplyPayloadTransformations = false, }; testDescriptor.ExpectedResultNormalizers.Add( tc => (Func <ODataPayloadElement, ODataPayloadElement>)null); if (testCase.MaxMessageSize > 0) { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.MessageQuotas.MaxReceivedMessageSize = testCase.MaxMessageSize; } testDescriptor.RunTest(testConfiguration); }); } }
/// <summary> /// Called to create the input message for the reader test. Replaces the default DSV header with the /// value specified in the constructor. /// </summary> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The newly created test message to use.</returns> protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { TestMessage testMessage = base.CreateInputMessage(testConfiguration); // now overwrite the DSV header testMessage.SetHeader(Microsoft.OData.ODataConstants.ODataVersionHeader, this.DataServiceVersion); return(testMessage); }
public override void RunTest(ReaderTestConfiguration testConfiguration) { //TODO: Use Logger to verify result, right now this change is only to unblock writer testcase checkin BaselineLogger logger = null; if (this.ShouldSkipForTestConfiguration(testConfiguration)) { return; } var originalPayload = this.PayloadElement; this.PayloadElement = this.PayloadElement.DeepCopy(); // Create messages (payload gets serialized in createInputMessage) TestMessage readerMessage = this.CreateInputMessage(testConfiguration); var settings = new ODataMessageWriterSettings() { Version = testConfiguration.Version, BaseUri = testConfiguration.MessageReaderSettings.BaseUri, EnableMessageStreamDisposal = testConfiguration.MessageReaderSettings.EnableMessageStreamDisposal, }; settings.SetContentType(testConfiguration.Format); WriterTestConfiguration writerConfig = new WriterTestConfiguration(testConfiguration.Format, settings, testConfiguration.IsRequest, testConfiguration.Synchronous); TestMessage writerMessage = TestWriterUtils.CreateOutputMessageFromStream(new TestStream(new MemoryStream()), writerConfig, this.PayloadKind, String.Empty, this.UrlResolver); IEdmModel model = this.GetMetadataProvider(testConfiguration); WriterTestExpectedResults expectedResult = this.GetExpectedResult(writerConfig); ExceptionUtilities.Assert(expectedResult != null, "The expected result could not be determined for the test. Did you specify it?"); Exception exception = TestExceptionUtils.RunCatching(() => { using (ODataMessageReaderTestWrapper messageReaderWrapper = TestReaderUtils.CreateMessageReader(readerMessage, model, testConfiguration)) using (ODataMessageWriterTestWrapper messageWriterWrapper = TestWriterUtils.CreateMessageWriter(writerMessage, model, writerConfig, this.settings.Assert)) { var streamer = new ObjectModelReadWriteStreamer(); streamer.StreamMessage(messageReaderWrapper, messageWriterWrapper, this.PayloadKind, writerConfig); expectedResult.VerifyResult(writerMessage, this.PayloadKind, writerConfig, logger); } }); this.PayloadElement = originalPayload; try { expectedResult.VerifyException(exception); } catch (Exception) { this.TraceFailureInformation(testConfiguration); throw; } }
// TODO: add encoding tests /// <summary> /// Ignore some test configurations based on the content type since we need to serialize the payloads /// with a supported format for that content type. /// </summary> /// <param name="contentType"></param> /// <param name="testConfiguration"></param> /// <returns></returns> private static bool IgnoreTestConfiguration(string contentType, ReaderTestConfiguration testConfiguration) { if (testConfiguration.Format != ODataFormat.Json) { string formatName = testConfiguration.Format == null ? "null" : testConfiguration.Format.GetType().Name; throw new NotSupportedException("Unsupported format " + formatName + " for method IgnoreTestConfiguration."); } return(false); }
private void RunStreamPropertyTest(IEdmModel model, IEnumerable <StreamPropertyTestCase> testCases) { var cityType = model.FindDeclaredType("TestModel.CityType").ToTypeReference(); var cities = model.EntityContainer.FindEntitySet("Cities"); IEnumerable <PayloadReaderTestDescriptor> testDescriptors = testCases.Select(testCase => { IEdmTypeReference entityType = testCase.OwningEntityType ?? cityType; EntityInstance entity = PayloadBuilder.Entity(entityType.FullName()).PrimitiveProperty("Id", 1) .JsonRepresentation( "{" + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities/" + entityType.FullName() + "()/$entity\"," + "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"" + entityType.FullName() + "\"," + "\"Id\": 1," + testCase.Json + "}") .ExpectedEntityType(entityType, cities); foreach (NamedStreamInstance streamProperty in testCase.ExpectedEntity.Properties.OfType <NamedStreamInstance>()) { entity.Add(streamProperty.DeepCopy()); } return(new PayloadReaderTestDescriptor(this.Settings) { DebugDescription = testCase.DebugDescription, PayloadEdmModel = model, PayloadElement = entity, ExpectedException = testCase.ExpectedException, SkipTestConfiguration = tc => testCase.OnlyResponse ? tc.IsRequest : false, InvalidOnRequest = testCase.InvalidOnRequest }); }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations, (testDescriptor, testConfiguration) => { if (testConfiguration.IsRequest && testDescriptor.InvalidOnRequest) { testDescriptor = new PayloadReaderTestDescriptor(testDescriptor) { ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_StreamPropertyInRequest") }; } // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); var testConfigClone = new ReaderTestConfiguration(testConfiguration); testConfigClone.MessageReaderSettings.BaseUri = null; testDescriptor.RunTest(testConfigClone); }); }
/// <summary> /// Runs each test descriptor with each ATOM reader test configuration and with ATOM metadata both enabled and disabled. /// </summary> /// <param name="testDescriptors">The test descriptors to run</param> /// <param name="runOnlyWithMetadataReadingOn">If true, then the test descriptors are only run with ATOM metadata reading enabled; false means run each descriptor with ATOM metadata reading both enabled and disabled.</param> protected void RunAtomMetadataReaderTests(IEnumerable <PayloadReaderTestDescriptor> testDescriptors, bool runOnlyWithMetadataReadingOn = false) { bool[] enableMetadataReadingOptions = runOnlyWithMetadataReadingOn ? new bool[] { true } : new bool[] { true, false }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations, enableMetadataReadingOptions, (testDescriptor, testConfiguration, enableMetadataReading) => { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.EnableAtomMetadataReading = enableMetadataReading; testDescriptor = new PayloadReaderTestDescriptor(testDescriptor); // Normalize the payload elements so that if an ATOM metadata property is set, the corresponding ATOM metadata // annotation is created, and vice versa. testDescriptor.ExpectedResultNormalizers.Add(tc => ODataPayloadElementAtomMetadataNormalizer.GenerateNormalizer(tc)); if (!enableMetadataReading) { // If we are running with ATOM metadata reading turned off, strip off all ATOM metadata annotations and // properties from the expected result. testDescriptor.ExpectedResultNormalizers.Add(tc => RemoveAtomMetadataFromPayloadElementVisitor.Visit); // Association links are only recognized in response and MPV >= V3 if (testConfiguration.IsRequest) { testDescriptor.ExpectedResultNormalizers.Add(tc => (payloadElement => RemoveAssociationLinkPayloadElementNormalizer.Normalize(payloadElement))); } // Stream properties are only recognized in response and >=V3 if (testConfiguration.IsRequest) { testDescriptor.ExpectedResultNormalizers.Add(tc => (payloadElement => RemoveStreamPropertyPayloadElementNormalizer.Normalize(payloadElement))); } // In this test class, expected exceptions apply only when ATOM metadata reading is on. testDescriptor.ExpectedException = null; } else { // In requests when metadata reading is enabled we have to turn stream properties and association links // into Atom metadata (and XmlTree annotation instances) testDescriptor.ExpectedResultNormalizers.Add(tc => (payloadElement) => ConvertAtomMetadataForConfigurationPayloadElementNormalizer.Normalize(payloadElement, tc)); } testDescriptor.RunTest(testConfiguration); }); }
private static ODataFormat ComputeExpectedFormat(ReaderTestConfiguration testConfiguration, string contentType) { switch (contentType) { case ApplicationJson: case ApplicationJsonODataLight: return(ODataFormat.Json); default: return(null); } }
public void EncodingPropertyTest() { // NOTE: the XmlReader (when created via XmlReader.Create) will use the Xml declaration and/or scan // ahead to detect the encoding from the payload. Only if both fail, do we have the opportunity // to make a difference by specifying the encoding in the content type. // // Create an non-standard character in the iso-8859-9 (Turkish) encoding Encoding iso88599Encoding = Encoding.GetEncoding("iso-8859-9"); char[] chars = iso88599Encoding.GetChars(new byte[] { 250 }); string payloadValue = new string(chars); var testCases = new[] { new { ContentType = "application/xml", ResultString = payloadValue, ExpectedException = new ExpectedException(typeof(XmlException)), }, new { ContentType = "application/xml;charset=iso-8859-9", ResultString = payloadValue, ExpectedException = (ExpectedException)null, }, }; var testDescriptors = testCases.Select(testCase => new ReaderEncodingTestDescriptor(this.Settings, testCase.ContentType) { PayloadElement = PayloadBuilder.PrimitiveProperty(null, payloadValue) .SerializationEncoding("iso-8859-9", /*omitDeclaration*/ true), ExpectedResultPayloadElement = tc => PayloadBuilder.PrimitiveProperty(null, testCase.ResultString), ExpectedException = testCase.ExpectedException, } ); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) => { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.DisableMessageStreamDisposal = true; testDescriptor.RunTest(testConfiguration); }); }
/// <summary> /// Called to get the expected result of the test. /// </summary> /// <param name="testConfiguration">The test configuration to use.</param> /// <returns>The expected result.</returns> protected override ReaderTestExpectedResult GetExpectedResult(ReaderTestConfiguration testConfiguration) { var baseResult = base.GetExpectedResult(testConfiguration) as PayloadReaderTestExpectedResult; var aggregateValidator = new AggregateODataObjectModelValidator(baseResult.ODataObjectModelValidator as AggregateODataObjectModelValidator); aggregateValidator.AddValidator( new NavigationLinkIsCollectionPropertyValidator { Assert = this.settings.Assert, ExpectedIsCollectionValues = this.ExpectedIsCollectionValues, }); baseResult.ODataObjectModelValidator = aggregateValidator; return baseResult; }
public void TopLevelNullPropertyWithInvalidTypeNameTest() { EdmModel model = new EdmModel().Fixup(); IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[] { new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.PrimitiveProperty(null, null) .XmlRepresentation("<m:value m:null='true' m:type='UnknownType' />"), PayloadEdmModel = model, }, }; var expectedTypes = new DataType[] { null, EdmDataTypes.Int32.NotNullable(), EdmDataTypes.Int32.Nullable(), }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors, new bool[] { true, false }, expectedTypes, this.ReaderTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, disablePrimitiveTypeConversion, expectedType, testConfiguration) => { if (disablePrimitiveTypeConversion) { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.DisablePrimitiveTypeConversion = true; } if (expectedType != null) { testDescriptor = new PayloadReaderTestDescriptor(testDescriptor); ((PropertyInstance)testDescriptor.PayloadElement).ExpectedPropertyType(expectedType); if (!disablePrimitiveTypeConversion && !expectedType.IsNullable) { testDescriptor.ExpectedException = ODataExpectedExceptions.ODataException("ReaderValidationUtils_NullValueForNonNullableType", "Edm.Int32"); } } testDescriptor.RunTest(testConfiguration); }); }
/// <summary> /// Called to get the expected result of the test. /// </summary> /// <param name="testConfiguration">The test configuration to use.</param> /// <returns>The expected result.</returns> protected override ReaderTestExpectedResult GetExpectedResult(ReaderTestConfiguration testConfiguration) { var baseResult = base.GetExpectedResult(testConfiguration) as PayloadReaderTestExpectedResult; var aggregateValidator = new AggregateODataObjectModelValidator(baseResult.ODataObjectModelValidator as AggregateODataObjectModelValidator); aggregateValidator.AddValidator( new NavigationLinkIsCollectionPropertyValidator { Assert = this.settings.Assert, ExpectedIsCollectionValues = this.ExpectedIsCollectionValues, }); baseResult.ODataObjectModelValidator = aggregateValidator; return(baseResult); }
private void RunNavigationLinkInRequestTest(IEnumerable <NavigationLinkTestCase> testCases, bool withMetadataAnnotation = false) { IEdmModel model = Test.OData.Utils.Metadata.TestModels.BuildTestModel(); this.CombinatorialEngineProvider.RunCombinations( testCases.Select(testCase => testCase.ToTestDescriptor(this.Settings, model, withMetadataAnnotation)), // Entity reference links are request only this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => tc.IsRequest), (testDescriptor, testConfiguration) => { // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); var testConfigClone = new ReaderTestConfiguration(testConfiguration); testDescriptor.RunTest(testConfigClone); }); }
public void TopLevelDeeplyRecursiveErrorTest() { int depthLimit = 5; IEnumerable <PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateErrorDeeplyNestedReaderTestDescriptors(this.Settings, depthLimit); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => !tc.IsRequest), (testDescriptor, testConfiguration) => { // Copy the test configuration so we can modify the depth limit. testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.MessageQuotas.MaxNestingDepth = depthLimit; testDescriptor.RunTest(testConfiguration); }); }
public void UndeclaredPropertyBehaviorKindStreamPropertyJsonLightTest() { this.CombinatorialEngineProvider.RunCombinations( TestReaderUtils.ODataUndeclaredPropertyBehaviorKindsCombinations, undeclaredPropertyBehaviorKinds => { var testDescriptors = CreateUndeclaredPropertyBehaviorKindStreamPropertyTestDescriptors(undeclaredPropertyBehaviorKinds, this.JsonLightSettings); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest), (testDescriptor, testConfiguration) => { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.UndeclaredPropertyBehaviorKinds = undeclaredPropertyBehaviorKinds; testDescriptor.RunTest(testConfiguration); }); }); }
/// <summary> /// Verifies that the result of the test (the message reader) is what the test expected. /// </summary> /// <param name="messageReader">The message reader which is the result of the test. This method should use it to read the results /// of the parsing and verify those.</param> /// <param name="payloadKind">The payload kind specified in the test descriptor.</param> /// <param name="testConfiguration">The test configuration to use.</param> public override void VerifyResult( ODataMessageReaderTestWrapper messageReader, ODataPayloadKind payloadKind, ReaderTestConfiguration testConfiguration) { object odataObject = this.settings.MessageToObjectModelReader.ReadMessage( messageReader, ODataPayloadKind.Batch, this.PayloadModel, PayloadReaderTestDescriptor.ReaderMetadata.None, this.ExpectedBatchPayload, testConfiguration); // only compare the payloads if the expected payload is not 'null'; null indicates to skip the comparison if (this.ExpectedBatchPayload != null) { ODataPayloadElement actualPayloadElement = this.settings.ObjectModelToPayloadElementConverter.Convert(odataObject, !testConfiguration.IsRequest); this.settings.BatchComparer.CompareBatchPayload(this.ExpectedBatchPayload, actualPayloadElement); } }
/// <summary> /// Called to create the input message for the reader test. /// </summary> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The newly created test message to use.</returns> protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { bool originalApplyTransformValue = false; var odataTransformFactory = this.settings.PayloadTransformFactory as ODataLibPayloadTransformFactory; try { if (this.ApplyPayloadTransformations.HasValue && odataTransformFactory != null) { originalApplyTransformValue = odataTransformFactory.ApplyTransform; odataTransformFactory.ApplyTransform = this.ApplyPayloadTransformations.Value; } MemoryStream memoryStream = new MemoryStream(TestReaderUtils.GetPayload(testConfiguration, this.PayloadNormalizers, this.settings, this.PayloadElement)); TestStream messageStream = new BatchReaderTestStream(memoryStream); if (testConfiguration.Synchronous) { messageStream.FailAsynchronousCalls = true; } else { messageStream.FailSynchronousCalls = true; } TestMessage testMessage = TestReaderUtils.CreateInputMessageFromStream( messageStream, testConfiguration, this.PayloadElement.GetPayloadKindFromPayloadElement(), this.PayloadElement.GetCustomContentTypeHeader(), this.UrlResolver); return(testMessage); } finally { if (this.ApplyPayloadTransformations.HasValue && odataTransformFactory != null) { odataTransformFactory.ApplyTransform = originalApplyTransformValue; } } }
public void OpenTypeFeedWithHeterogenousItems() { var model = new EdmModel(); var openTestDescriptor = new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = TestFeeds.CreateOpenEntitySetInstance(model, true, (p) => true), PayloadEdmModel = model, }; this.CombinatorialEngineProvider.RunCombinations( this.PayloadGenerator.GenerateReaderPayloads(openTestDescriptor), this.ReaderTestConfigurationProvider.AtomFormatConfigurations, (testDescriptor, testConfiguration) => { // These payloads get quite large and exceed default size limits var actualConfiguration = new ReaderTestConfiguration(testConfiguration); actualConfiguration.MessageReaderSettings.MessageQuotas.MaxReceivedMessageSize = long.MaxValue; testDescriptor.RunTest(actualConfiguration); }); }
public void SpatialPropertyWithDisabledPrimitiveTypeConversionTest() { IEdmModel testModel = TestModels.BuildTestModel(); var testValues = new object[] { GeographyFactory.Point(10, 20).Build(), GeometryFactory.Point(10, 20).Build() }; IEnumerable <PayloadReaderTestDescriptor> testDescriptors = TestValues.PrimitiveTypes.SelectMany(primitiveTypes => testValues.Select(testValue => { PrimitiveDataType targetType = EntityModelUtils.GetPrimitiveEdmType(primitiveTypes); ODataPayloadElement payloadElement = PayloadBuilder .Property(null, PayloadBuilder.PrimitiveValue(testValue)) .ExpectedPropertyType(targetType); return(new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = payloadElement, PayloadEdmModel = testModel }); })); // TODO: Task 1429690:Fix places where we've lost JsonVerbose coverage to add JsonLight this.CombinatorialEngineProvider.RunCombinations( testDescriptors, new bool[] { false, true }, this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations.Where(tc => false), (testDescriptor, disableStrictValidation, testConfig) => { testConfig = new ReaderTestConfiguration(testConfig); testConfig.MessageReaderSettings.EnablePrimitiveTypeConversion = false; if (disableStrictValidation) { testConfig = testConfig.CloneAndApplyBehavior(TestODataBehaviorKind.WcfDataServicesServer); } testDescriptor.RunTest(testConfig); }); }
private void RunMetadataMessageSizeLimitTests(IEdmModel model, MessageSizeLimitTestCase[] testCases) { this.CombinatorialEngineProvider.RunCombinations( testCases, this.ReaderTestConfigurationProvider.DefaultFormatConfigurations.Where(tc => !tc.IsRequest && tc.Synchronous), (testCase, testConfiguration) => { int size = -1; if (testConfiguration.Format == ODataFormat.Atom && testCase.AtomSizes != null) { size = testConfiguration.IsRequest ? testCase.AtomSizes.RequestSize : testCase.AtomSizes.ResponseSize; } else if (testConfiguration.Format == ODataFormat.Json && testCase.JsonLightSizes != null) { size = testConfiguration.IsRequest ? testCase.JsonLightSizes.RequestSize : testCase.JsonLightSizes.ResponseSize; } else if (testCase.RawSizes != null) { size = testConfiguration.IsRequest ? testCase.RawSizes.RequestSize : testCase.RawSizes.ResponseSize; } ExpectedException expectedException = size < 0 ? null : ODataExpectedExceptions.ODataException("MessageStreamWrappingStream_ByteLimitExceeded", size.ToString(), testCase.MaxMessageSize.ToString()); var testDescriptor = new MetadataReaderTestDescriptor(this.MetadataSettings) { PayloadEdmModel = model, ExpectedException = expectedException, }; if (testCase.MaxMessageSize > 0) { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.MessageQuotas.MaxReceivedMessageSize = testCase.MaxMessageSize; } testDescriptor.RunTest(testConfiguration); }); }
public void UndeclaredPropertyBehaviorKindStreamPropertyJsonLightTest() { this.CombinatorialEngineProvider.RunCombinations( new[] { false, true }, throwOnUndeclaredPropertyForNonOpenType => { var testDescriptors = CreateUndeclaredPropertyBehaviorKindStreamPropertyTestDescriptors(throwOnUndeclaredPropertyForNonOpenType, this.JsonLightSettings); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest), (testDescriptor, testConfiguration) => { testConfiguration = new ReaderTestConfiguration(testConfiguration); if (!throwOnUndeclaredPropertyForNonOpenType) { testConfiguration.MessageReaderSettings.Validations = ~ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType; } testDescriptor.RunTest(testConfiguration); }); }); }
protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { MemoryStream memoryStream = new MemoryStream(this.RawMessage); TestStream messageStream = new TestStream(memoryStream); if (testConfiguration.Synchronous) { messageStream.FailAsynchronousCalls = true; } else { messageStream.FailSynchronousCalls = true; } TestMessage testMessage = TestReaderUtils.CreateInputMessageFromStream( messageStream, testConfiguration, this.PayloadElement.GetPayloadKindFromPayloadElement(), this.BatchContentTypeHeader, this.UrlResolver); return(testMessage); }
/// <summary> /// Called to create the input message for the reader test. /// </summary> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The newly created test message to use.</returns> protected override TestMessage CreateInputMessage(ReaderTestConfiguration testConfiguration) { bool originalApplyTransformValue = false; var odataTransformFactory = this.settings.PayloadTransformFactory as ODataLibPayloadTransformFactory; try { if (this.ApplyPayloadTransformations.HasValue && odataTransformFactory != null) { originalApplyTransformValue = odataTransformFactory.ApplyTransform; odataTransformFactory.ApplyTransform = this.ApplyPayloadTransformations.Value; } MemoryStream memoryStream = new MemoryStream(TestReaderUtils.GetPayload(testConfiguration,this.PayloadNormalizers, this.settings, this.PayloadElement)); TestStream messageStream = new BatchReaderTestStream(memoryStream); if (testConfiguration.Synchronous) { messageStream.FailAsynchronousCalls = true; } else { messageStream.FailSynchronousCalls = true; } TestMessage testMessage = TestReaderUtils.CreateInputMessageFromStream( messageStream, testConfiguration, this.PayloadElement.GetPayloadKindFromPayloadElement(), this.PayloadElement.GetCustomContentTypeHeader(), this.UrlResolver); return testMessage; } finally { if (this.ApplyPayloadTransformations.HasValue && odataTransformFactory != null) { odataTransformFactory.ApplyTransform = originalApplyTransformValue; } } }
public void UndeclaredValuePropertyTests() { IEdmModel model = TestModels.BuildTestModel(); IEnumerable <UndeclaredPropertyTestCase> testCases = new[] { new UndeclaredPropertyTestCase { DebugDescription = "Number without type", Json = "\"UndeclaredProperty\":42", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), }, new UndeclaredPropertyTestCase { DebugDescription = "String without type", Json = "\"UndeclaredProperty\":\"value\"", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), }, new UndeclaredPropertyTestCase { DebugDescription = "null without type", Json = "\"UndeclaredProperty\":null", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), }, new UndeclaredPropertyTestCase { DebugDescription = "Boolean without type", Json = "\"UndeclaredProperty\":false", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), }, new UndeclaredPropertyTestCase { DebugDescription = "Number with type", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataTypeAnnotationName) + "\":\"Edm.Int16\"," + "\"UndeclaredProperty\":42", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), }, new UndeclaredPropertyTestCase { DebugDescription = "Number with invalid type - should work, the type is ignored", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataTypeAnnotationName) + "\":\"TestModel.Unknown\"," + "\"UndeclaredProperty\":42", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), }, new UndeclaredPropertyTestCase { DebugDescription = "Number with another odata annotation - should fail", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataBindAnnotationName) + "\":\"http://odata.org/reference\"," + "\"UndeclaredProperty\":42", IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedDataPropertyAnnotation", "UndeclaredProperty", JsonLightConstants.ODataBindAnnotationName) }, new UndeclaredPropertyTestCase { DebugDescription = "Property without value and with no recognized annotations - should fail", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", "custom.annotation") + "\":\"value\"", ExpectedEntity = PayloadBuilder.Entity(), ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_PropertyWithoutValueWithUnknownType", "UndeclaredProperty") }, new UndeclaredPropertyTestCase { DebugDescription = "Property without value and with known annotation - should fail", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataBindAnnotationName) + "\":\"http://odata.org/reference\"", ExpectedEntity = PayloadBuilder.Entity(), ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_PropertyWithoutValueWithUnknownType", "UndeclaredProperty") }, }; this.CombinatorialEngineProvider.RunCombinations( testCases, TestReaderUtils.ODataUndeclaredPropertyBehaviorKindsCombinations, // Undeclared properties are only allowed in responses this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest), (testCase, undeclaredPropertyBehaviorKinds, testConfiguration) => { PayloadReaderTestDescriptor testDescriptor = testCase.ToTestDescriptor(this.Settings, model, undeclaredPropertyBehaviorKinds); testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.UndeclaredPropertyBehaviorKinds = undeclaredPropertyBehaviorKinds; // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }
public void ExpandedLinkTest() { IEdmModel model = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel(); // TODO: add test cases that use relative URIs IEnumerable <PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateDeferredNavigationLinkTestDescriptors(this.Settings, true); // Generate interesting payloads around the navigation property // Note that this will actually expand the deferred nav links as well. testDescriptors = testDescriptors.SelectMany(td => this.PayloadGenerator.GenerateReaderPayloads(td)); IEnumerable <PayloadReaderTestDescriptor> customTestDescriptors = new PayloadReaderTestDescriptor[] { // Expanded null entry new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.CityType") .PrimitiveProperty("Id", 1) .ExpandedNavigationProperty("PoliceStation", PayloadBuilder.NullEntity()), }, // Expanded null entry after another expanded collection link new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.CityType") .PrimitiveProperty("Id", 1) .ExpandedNavigationProperty("CityHall", PayloadBuilder.EntitySet()) .ExpandedNavigationProperty("PoliceStation", PayloadBuilder.NullEntity()), }, // incorrect type at related end new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.CityType") .PrimitiveProperty("Id", 1) .ExpandedNavigationProperty("PoliceStation", PayloadBuilder.Entity("TestModel.CityType")), ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_EntryTypeNotAssignableToExpectedType", "TestModel.CityType", "TestModel.OfficeType"), }, // Nested entry of depth 4 should fail because we set MaxNestingDepth = 3 below new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1), ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_MaxDepthOfNestedEntriesExceeded", "3"), }.InEntryWithExpandedLink(true /* isSingleton */) .InEntryWithExpandedLink(true) .InEntryWithExpandedLink(true), // Nested entry of depth 4 within expanded feeds should fail new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1), ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_MaxDepthOfNestedEntriesExceeded", "3"), }.InFeed() .InEntryWithExpandedLink(false /* isSingleton */) .InFeed() .InEntryWithExpandedLink(false) .InFeed() .InEntryWithExpandedLink(false), // Nested entry of depth 3 should succeed new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1) }.InEntryWithExpandedLink(true /* isSingleton */) .InEntryWithExpandedLink(true), // Nested entry of depth 3 within expanded feeds should succeed new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1) }.InFeed() .InEntryWithExpandedLink(false /* isSingleton */) .InFeed() .InEntryWithExpandedLink(false), // Expanded feed with a number of child entries greater than recursive depth limit should succeed. new PayloadReaderTestDescriptor(this.Settings) { PayloadDescriptor = new PayloadTestDescriptor(), PayloadEdmModel = model, PayloadElement = PayloadBuilder.EntitySet().Append( PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1), PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 2), PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 3), PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 4), PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 5)), }.InEntryWithExpandedLink(false /* isSingleton */) .InEntryWithExpandedLink(true), }; this.CombinatorialEngineProvider.RunCombinations( testDescriptors.Concat(customTestDescriptors), this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations, (testDescriptor, testConfiguration) => { testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.MessageQuotas.MaxNestingDepth = 3; testDescriptor.RunTest(testConfiguration); }); }
public void UndeclaredStreamPropertyTests() { IEdmModel model = TestModels.BuildTestModel(); IEnumerable<UndeclaredPropertyTestCase> testCases = new[] { new UndeclaredPropertyTestCase { DebugDescription = "Just edit link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/mediaeditlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().StreamProperty("UndeclaredProperty", null, "http://odata.org/mediaeditlink", null, null) }, new UndeclaredPropertyTestCase { DebugDescription = "Just read link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaReadLinkAnnotationName) + "\":\"http://odata.org/mediareadlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().StreamProperty("UndeclaredProperty", "http://odata.org/mediareadlink", null, null, null) }, new UndeclaredPropertyTestCase { DebugDescription = "Just content type", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaContentTypeAnnotationName) + "\":\"media/contenttype\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().StreamProperty("UndeclaredProperty", null, null, "media/contenttype", null) }, new UndeclaredPropertyTestCase { DebugDescription = "Just ETag", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaETagAnnotationName) + "\":\"etag\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().StreamProperty("UndeclaredProperty", null, null, null, "etag") }, new UndeclaredPropertyTestCase { DebugDescription = "Everything", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/mediaeditlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaReadLinkAnnotationName) + "\":\"http://odata.org/mediareadlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaContentTypeAnnotationName) + "\":\"media/contenttype\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaETagAnnotationName) + "\":\"etag\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().StreamProperty("UndeclaredProperty", "http://odata.org/mediareadlink", "http://odata.org/mediaeditlink", "media/contenttype", "etag") }, new UndeclaredPropertyTestCase { DebugDescription = "Everything with custom annotations", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/mediaeditlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaReadLinkAnnotationName) + "\":\"http://odata.org/mediareadlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", "custom.annotation") + "\":\"value\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaContentTypeAnnotationName) + "\":\"media/contenttype\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaETagAnnotationName) + "\":\"etag\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", "custom.annotation2") + "\":42", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().StreamProperty("UndeclaredProperty", "http://odata.org/mediareadlink", "http://odata.org/mediaeditlink", "media/contenttype", "etag") }, //new UndeclaredPropertyTestCase //{ // DebugDescription = "Stream property with odata.type annotation", // Json = // "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/mediaeditlink\"," + // "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataTypeAnnotationName) + "\":\"#Stream\"", // IsLink = true, // ExpectedEntity = PayloadBuilder.Entity(), // ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_UnexpectedStreamPropertyAnnotation", "UndeclaredProperty", JsonLightConstants.ODataTypeAnnotationName) //}, //new UndeclaredPropertyTestCase //{ // DebugDescription = "Stream property with a value", // Json = // "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/mediaeditlink\"," + // "\"UndeclaredProperty\":null", // IsLink = true, // ExpectedEntity = PayloadBuilder.Entity(), // ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_StreamPropertyWithValue", "UndeclaredProperty") //}, }; this.CombinatorialEngineProvider.RunCombinations( testCases, new[] { false, true }, // Undeclared properties are only allowed in responses this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest), (testCase, throwOnUndeclaredPropertyForNonOpenType, testConfiguration) => { var settings = testConfiguration.Format == ODataFormat.Json ? this.JsonLightSettings : this.Settings; PayloadReaderTestDescriptor testDescriptor = testCase.ToTestDescriptor(settings, model, throwOnUndeclaredPropertyForNonOpenType); testConfiguration = new ReaderTestConfiguration(testConfiguration); if (!throwOnUndeclaredPropertyForNonOpenType) { testConfiguration.MessageReaderSettings.Validations &= ~ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType; } // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }
public void ServiceDocumentReaderJsonLightCustomAnnotationsTest() { var testCases = new[] { #region success test cases new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Custom property annotation on \"name\" should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""*****@*****.**"":""ignored"", ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Custom instance annotation inside a resource collection should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""@cn.foo"":""ignored"", ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Custom property annotation on \"value\" should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""*****@*****.**"": ""ignored"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Custom instance annotation on the top level should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""@cn.foo"": ""ignored"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Annotations at different scopes with the same name should be ignored and should not throw.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""@cn.foo"": ""ignored"", ""*****@*****.**"": ""ignored"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""@cn.foo"": ""ignored"", ""name"":""EntitySetName"", ""*****@*****.**"": ""ignored"", ""url"":""EntitySetLink"" }, ] }", }, #endregion success test cases #region error test cases new JsonLightServiceDocumentReaderTestCase { Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""*****@*****.**"":""out of order"", ""url"":""EntitySetLink"", ""name"":""EntitySetName"" }, ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_PropertyAnnotationWithoutProperty", "name") }, new JsonLightServiceDocumentReaderTestCase { Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""url"":""EntitySetLink"", ""name"":""EntitySetName"" }, ], ""*****@*****.**"":""out of order"" }", ExpectedException = ODataExpectedExceptions.ODataException("PropertyAnnotationAfterTheProperty", "cn.foo", "value") }, new JsonLightServiceDocumentReaderTestCase { Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""*****@*****.**"":""ignored"", ""*****@*****.**"":""ignored"", ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, new JsonLightServiceDocumentReaderTestCase { Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""@cn.foo"":""ignored"", ""name"":""EntitySetName"", ""url"":""EntitySetLink"", ""@cn.foo"":""ignored"" }, ] }", ExpectedException = null }, new JsonLightServiceDocumentReaderTestCase { Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""*****@*****.**"":""ignored"", ""*****@*****.**"":""ignored"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, new JsonLightServiceDocumentReaderTestCase { Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""@cn.foo"":""ignored"", ""@cn.foo"":""ignored"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, #endregion error test cases }; var testDescriptors = testCases.Select(tc => new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ServiceDocument().Workspace( PayloadBuilder.Workspace().ResourceCollection(null, baseUri + "EntitySetLink", "EntitySetName")) .JsonRepresentation(tc.Json), PayloadEdmModel = new EdmModel(), SkipTestConfiguration = testConfiguration => testConfiguration.IsRequest, DebugDescription = tc.DebugDescription, ExpectedException = tc.ExpectedException }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations, (testDescriptor, testConfiguration) => { // clone the ReaderTestConfiguration and set the base URI. testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.BaseUri = null; // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }
public void ServiceDocumentReaderJsonLightUnrecognizedODataAnnotationsTest() { var testCases = new[] { new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Unrecognized odata property annotation in a resource collection should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""*****@*****.**"":""fail"", ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Unrecognized odata instance annotation in a resource collection should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""@odata.foo"":""fail"", ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Unrecognized odata property annotation on 'value' should be ignored. ", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""*****@*****.**"": ""fail"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "Unrecognized odata instance annotation on the top level should be ignored.", Json = @"{ ""@" + JsonLightConstants.ODataContextAnnotationName + @""": ""http://odata.org/test/$metadata"", ""@odata.foo"": ""fail"", """ + JsonLightConstants.ODataValuePropertyName + @""": [ { ""name"":""EntitySetName"", ""url"":""EntitySetLink"" }, ] }", ExpectedException = null }, }; var testDescriptors = testCases.Select(tc => new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ServiceDocument().Workspace( PayloadBuilder.Workspace().ResourceCollection(null, baseUri + "EntitySetLink", "EntitySetName")) .JsonRepresentation(tc.Json), PayloadEdmModel = new EdmModel(), SkipTestConfiguration = testConfiguration => testConfiguration.IsRequest, ExpectedException = tc.ExpectedException, DebugDescription = tc.DebugDescription }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations, (testDescriptor, testConfiguration) => { // clone the ReaderTestConfiguration and set the base URI. testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.BaseUri = null; // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }
/// <summary> /// Converts ATOM metadata from the given payload element and its descendants into /// XmlTree annotations suitable for payloads when ATOM metadata reading is enabled. /// This happens for stream properties and association links that are read as atom:link elements /// but otherwise ignored in some cases. /// </summary> /// <param name="payloadElement">The root of the payload element tree to visit.</param> /// <param name="readerTestConfiguration">The reader test configuration to use.</param> /// <returns>The <paramref name="payloadElement"/> after it has been visited.</returns> public static ODataPayloadElement Normalize(ODataPayloadElement payloadElement, ReaderTestConfiguration readerTestConfiguration) { new ConvertAtomMetadataForConfigurationPayloadElementNormalizer(readerTestConfiguration).Recurse(payloadElement); return payloadElement; }
public void UndeclaredNavigationLinkTests() { IEdmModel model = TestModels.BuildTestModel(); IEnumerable<UndeclaredPropertyTestCase> testCases = new[] { new UndeclaredPropertyTestCase { DebugDescription = "Just navigation link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", "http://odata.org/navigationlink") }, new UndeclaredPropertyTestCase { DebugDescription = "Just association link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/associationlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", null, "http://odata.org/associationlink") }, new UndeclaredPropertyTestCase { DebugDescription = "Navigation and association link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/associationlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", "http://odata.org/navigationlink", "http://odata.org/associationlink") }, new UndeclaredPropertyTestCase { DebugDescription = "Navigation and association link with custom annotation", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", "custom.annotation") + "\":null," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/associationlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", "http://odata.org/navigationlink", "http://odata.org/associationlink") }, new UndeclaredPropertyTestCase { DebugDescription = "Navigation link with odata.type annotation", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataTypeAnnotationName) + "\":\"TestModel.OfficeType\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", "http://odata.org/navigationlink") }, new UndeclaredPropertyTestCase { DebugDescription = "Association link with another odata.mediaEditLink annotation - should fail", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataMediaEditLinkAnnotationName) + "\":\"http://odata.org/mediaeditlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/associationlink\"", IsLink = true, ExpectedEntity = PayloadBuilder.Entity(), ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_UnexpectedStreamPropertyAnnotation", "UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) }, new UndeclaredPropertyTestCase { DebugDescription = "Expanded feed navigation link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"," + "\"UndeclaredProperty\":[]", IsLink = true, IsValue = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", "http://odata.org/navigationlink"), }, new UndeclaredPropertyTestCase { DebugDescription = "Expanded entry navigation link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/associationlink\"," + "\"UndeclaredProperty\":{}", IsLink = true, IsValue = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", null, "http://odata.org/associationlink"), }, new UndeclaredPropertyTestCase { DebugDescription = "Expanded null entry navigation link", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"," + "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataAssociationLinkUrlAnnotationName) + "\":\"http://odata.org/associationlink\"," + "\"UndeclaredProperty\":null", IsLink = true, IsValue = true, ExpectedEntity = PayloadBuilder.Entity().NavigationProperty("UndeclaredProperty", "http://odata.org/navigationlink", "http://odata.org/associationlink"), }, new UndeclaredPropertyTestCase { DebugDescription = "Expanded navigation link with wrong value", Json = "\"" + JsonLightUtils.GetPropertyAnnotationName("UndeclaredProperty", JsonLightConstants.ODataNavigationLinkUrlAnnotationName) + "\":\"http://odata.org/navigationlink\"," + "\"UndeclaredProperty\":42", IsLink = true, IsValue = true, ExpectedEntity = PayloadBuilder.Entity(), ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_CannotReadNestedResource", "UndeclaredProperty") }, }; this.CombinatorialEngineProvider.RunCombinations( testCases, new[] { false, true }, // Undeclared properties are only allowed in responses this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations.Where(tc => !tc.IsRequest), (testCase, throwOnUndeclaredPropertyForNonOpenType, testConfiguration) => { PayloadReaderTestDescriptor testDescriptor = testCase.ToTestDescriptor(this.Settings, model, throwOnUndeclaredPropertyForNonOpenType); testConfiguration = new ReaderTestConfiguration(testConfiguration); if (!throwOnUndeclaredPropertyForNonOpenType) { testConfiguration.MessageReaderSettings.Validations &= ~ValidationKinds.ThrowOnUndeclaredPropertyForNonOpenType; } // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }
public void InStreamAtomDeeplyRecursiveErrorTest() { int depthLimit = 5; IEnumerable<PayloadReaderTestDescriptor> testDescriptors = PayloadReaderTestDescriptorGenerator.CreateErrorDeeplyNestedReaderTestDescriptors(this.Settings, depthLimit); // Convert the payload element to an Xml representation usable for in-stream error testing testDescriptors = testDescriptors.Select(td => { XElement xmlPayload = this.PayloadElementToXmlConverter.ConvertToXml(td.PayloadElement); return new PayloadReaderTestDescriptor(td) { PayloadElement = td.PayloadElement.XmlRepresentation(xmlPayload) }; }); // Convert top-level error test descriptors to in-stream errors. testDescriptors = testDescriptors.Select(td => td.ToInStreamErrorTestDescriptor(ODataFormat.Atom)); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.AtomFormatConfigurations.Where(tc => !tc.IsRequest), (testDescriptor, testConfiguration) => { // Copy the test configuration so we can modify the depth limit. testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.MessageQuotas.MaxNestingDepth = depthLimit; testDescriptor.RunTest(testConfiguration); }); }
public void ServiceDocumentReaderJsonLightTest() { var errorTestCases = new[] { new JsonLightServiceDocumentReaderTestCase { DebugDescription = "unrecognized property in the workspace object.", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"unrecognized\": 42, \"value\": [ {\"name\": \"EntitySetName\", \"url\":\"EntitySetLink\"} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_UnexpectedPropertyInServiceDocument", "unrecognized", "value") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "unrecognized property in a service document element.", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\":\"EntitySetName\", \"url\":\"EntitySetLink\", \"unrecognized\": 42} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_UnexpectedPropertyInServiceDocumentElement", "unrecognized", "name", "url") }, #region missing required properties new JsonLightServiceDocumentReaderTestCase { DebugDescription = "service document element without a 'name' (required in JSON light, but doesn't exist in the other formats)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"url\":\"EntitySetLink\"} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_MissingRequiredPropertyInServiceDocumentElement", "name") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "service document element without a 'url'", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\":\"EntitySetName\"} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_MissingRequiredPropertyInServiceDocumentElement", "url") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "null value for 'name'", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\":null, \"url\":\"EntitySetLink\"} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_MissingRequiredPropertyInServiceDocumentElement", "name") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "null value for 'url'", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\":\"EntitySetName\", \"url\":null} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ValidationUtils_ServiceDocumentElementUrlMustNotBeNull") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "no 'value' property", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\" }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_MissingValuePropertyInServiceDocument", "value") }, #endregion missing required properties #region duplicate properties new JsonLightServiceDocumentReaderTestCase { DebugDescription = "multiple 'value' properties", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\": \"EntitySetName\", \"url\":\"EntitySetLink\"} ], \"value\": [ {\"name\": \"EntitySetName\", \"url\":\"EntitySetLink\"} ] }", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_DuplicatePropertiesInServiceDocument", "value") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "multiple 'name' properties in an entity set.", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\": \"EntitySetName\", \"url\":\"EntitySetLink\", \"name\": \"Second name\"}]}", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_DuplicatePropertiesInServiceDocumentElement", "name") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "multiple 'url' properties in an entity set.", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ {\"name\": \"EntitySetName\", \"url\":\"EntitySetLink\", \"url\": \"SecondLink\"}]}", ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightServiceDocumentDeserializer_DuplicatePropertiesInServiceDocumentElement", "url") }, #endregion duplicate properties/annotations #region incorrect json structure new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid top-level JSON node (an array)", Json = "[]", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid top-level JSON node (a primitive value)", Json = "42", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value of 'value' property (a primitive value)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": 42 }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartArray", "PrimitiveValue") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value of 'value' property (an object value)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": { } }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartArray", "StartObject") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value inside the array value of the 'value' property (a nested array value)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ [] ] }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "StartArray") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value inside the array value of the 'value' property (integer value)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ 42 ] }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value inside the array value of the 'value' property (boolean value)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ true ] }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value inside the array value of the 'value' property (string value)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ \"string\" ] }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue") }, new JsonLightServiceDocumentReaderTestCase { DebugDescription = "invalid value inside the array value of the 'value' property (null)", Json = "{ \"@" + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata\", \"value\": [ null ] }", ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "StartObject", "PrimitiveValue") }, #endregion incorrect json structure }; var testDescriptors = errorTestCases.Select(tc => new PayloadReaderTestDescriptor(this.Settings) { PayloadElement = PayloadBuilder.ServiceDocument().Workspace( PayloadBuilder.Workspace().ResourceCollection(null, baseUri + "EntitySetLink", "EntitySetName")) .JsonRepresentation(tc.Json), PayloadEdmModel = new EdmModel(), SkipTestConfiguration = testConfiguration => testConfiguration.IsRequest, ExpectedException = tc.ExpectedException, DebugDescription = tc.DebugDescription }); this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations, (testDescriptor, testConfiguration) => { // clone the ReaderTestConfiguration and set the base URI. testConfiguration = new ReaderTestConfiguration(testConfiguration); testConfiguration.MessageReaderSettings.BaseUri = null; // These descriptors are already tailored specifically for Json Light and // do not require normalization. testDescriptor.TestDescriptorNormalizers.Clear(); testDescriptor.RunTest(testConfiguration); }); }
/// <summary> /// Constructor. /// </summary> /// <param name="rootPayloadElement">The payload element this normalizer was created for; /// used to detect whether we are visiting the top-level element or not.</param> /// <param name="testConfig"></param> private JsonLightPayloadElementNormalizer(ODataPayloadElement rootPayloadElement, ReaderTestConfiguration testConfiguration) { this.rootPayloadElement = rootPayloadElement; this.testConfiguration = testConfiguration; }
/// <summary> /// Normalizes JSON Light payload. /// </summary> /// <param name="payloadElement">The payload element to normalize.</param> /// <param name="testConfiguration">The test configuration.</param> /// <returns>The normalized payload element.</returns> public static ODataPayloadElement Normalize(ODataPayloadElement payloadElement, ReaderTestConfiguration testConfiguration) { new JsonLightPayloadElementNormalizer(payloadElement, testConfiguration).Recurse(payloadElement); return payloadElement; }
/// <summary> /// Constructor. /// </summary> /// <param name="readerTestConfiguration">The reader test configuration for the payload.</param> private ConvertAtomMetadataForConfigurationPayloadElementNormalizer(ReaderTestConfiguration readerTestConfiguration) { this.readerTestConfiguration = readerTestConfiguration; }