Esempio n. 1
0
        public void FeedReadingNullUriTest()
        {
            EdmModel model = (EdmModel)Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            model.Fixup();

            EntitySetInstance feed = PayloadBuilder.EntitySet();

            feed.NextLink = null;

            // Run only in version >= 2 since next links are only supported since v2 and not allowed in requests
            this.CombinatorialEngineProvider.RunCombinations(
                baseUriValues,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations.Where(tc => !tc.IsRequest),
                (baseUriValue, testConfiguration) =>
            {
                // The next link should always be null independently of whether a base URI is specified or not
                NullUriValueTestCase <EntitySetInstance> testCase = new NullUriValueTestCase <EntitySetInstance>
                {
                    SetNullUriAction     = (instance, uri, testConfig) => instance.NextLink = null,
                    SetExpectedUriAction = null         // will use SetNullUriAction instead
                };

                this.RunNullUriReadingTest(feed, testCase, model, baseUriValue, testConfiguration);
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Generates an open entity set containing entities with different amounts of primitive open properties.
        /// </summary>
        /// <param name="model">The entity model. The method will modify the model and call Fixup().</param>
        /// <param name="withTypeNames">True if the payloads should specify type names.</param>
        /// <param name="primitiveValueFilter">A function for excluding primitives which are unsupported for open properties.</param>
        /// <returns>The open entity set containing entities with primitive open properties.</returns>
        public static ODataPayloadElement CreateOpenEntitySetInstance(EdmModel model, bool withTypeNames, Func <PrimitiveValue, bool> primitiveValueFilter)
        {
            ExceptionUtilities.CheckArgumentNotNull(model, "model");
            ExceptionUtilities.CheckArgumentNotNull(primitiveValueFilter, "primitiveValueFilter");

            var edmEntityType = new EdmEntityType("TestModel", "OpenEntityType", baseType: null, isAbstract: false, isOpen: true);

            model.AddElement(edmEntityType);
            edmEntityType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String, true);

            var container = new EdmEntityContainer("TestModel", "DefaultContainer");

            container.AddEntitySet("OpenEntityTypes", edmEntityType);
            model.AddElement(container);

            var feed = PayloadBuilder.EntitySet().WithTypeAnnotation(edmEntityType);

            string entityTypeName = withTypeNames ? edmEntityType.FullName() : null;

            var primitiveValues = TestValues.CreatePrimitiveValuesWithMetadata(true).Where(p => primitiveValueFilter(p));

            int idx = 0;

            for (int i = 0; i <= primitiveValues.Count(); ++i)
            {
                var entityInstance = PayloadBuilder.Entity(entityTypeName).PrimitiveProperty("Name", Guid.NewGuid().ToString());
                foreach (var property in primitiveValues.Take(i))
                {
                    entityInstance.PrimitiveProperty("Property" + (idx++), property.ClrValue);
                }
                feed.Add(entityInstance);
            }
            return(feed);
        }
        public void FeedAtomMetadataCategoryTest()
        {
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors =
                this.CreateCategoryTestDescriptors(
                    PayloadBuilder.EntitySet(), "feed");

            this.RunAtomMetadataReaderTests(testDescriptors);
        }
Esempio n. 4
0
        public void CollectionOfComplexInstanceTest()
        {
            EdmModel model       = new EdmModel();
            var      complexType = new EdmComplexType("TestModel", "ComplexType").Property("Name", EdmPrimitiveTypeKind.String, true);

            model.AddElement(complexType);
            var owningType = new EdmEntityType("TestModel", "OwningType");

            owningType.AddKeys(owningType.AddStructuralProperty("ID", EdmCoreModel.Instance.GetInt32(false)));
            owningType.AddStructuralProperty("PrimitiveCollection", EdmCoreModel.GetCollection(EdmCoreModel.Instance.GetInt32(false)));
            owningType.AddStructuralProperty("ComplexCollection", EdmCoreModel.GetCollection(complexType.ToTypeReference()));
            model.AddElement(owningType);
            model.Fixup();

            var primitiveMultiValue = PayloadBuilder.PrimitiveMultiValue("Collection(Edm.Int32)").Item(42).Item(43);
            var complexMultiValue   = PayloadBuilder.EntitySet(new EntityInstance[]
            {
                PayloadBuilder.Entity("TestModel.ComplexType")
                .PrimitiveProperty("Name", "Value")
                .AddAnnotation(new SerializationTypeNameTestAnnotation()
                {
                    TypeName = null
                })
                .IsComplex(true)
            })
                                      .JsonRepresentation("[{\"Name\":\"Value\"}]")
                                      .AddAnnotation(new SerializationTypeNameTestAnnotation()
            {
                TypeName = null
            });

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Simple complex collection.",
                    PayloadEdmModel  = model,
                    PayloadElement   = PayloadBuilder.Property("ComplexCollection", complexMultiValue)
                                       .ExpectedProperty(owningType, "ComplexCollection"),
                    ExpectedResultPayloadElement = tc => tc.IsRequest
                        ? PayloadBuilder.Property(string.Empty, complexMultiValue)
                        : PayloadBuilder.Property("ComplexCollection", complexMultiValue)
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
 /// <summary>
 /// Constructs test descriptors which test feed ATOM metadata elements of type atomTextConstruct ("rights", "title", and "subtitle").
 /// </summary>
 /// <param name="textConstructElementName">The name of the ATOM metadata element to create test descriptors for.</param>
 /// <param name="addTextAtomMetadataAnnotation">A Func which takes an entity set instance, the value of the text construct element,
 /// and the name of the text construct kind and produces the entity set instance with the added text construct ATOM metadata.</param>
 /// <returns>A list of test descriptors.</returns>
 private IEnumerable <PayloadReaderTestDescriptor> CreateTextConstructFeedTestDescriptors(
     string textConstructElementName,
     Func <EntitySetInstance, string, string, EntitySetInstance> addTextAtomMetadataAnnotation)
 {
     return(this.CreateTextConstructTestDescriptors(
                PayloadBuilder.EntitySet(),
                "feed",
                textConstructElementName,
                addTextAtomMetadataAnnotation));
 }
        public void JsonLightTaupoSerializerFeedTest()
        {
            var testCases = new JsonLightSerializerTestCase[]
            {
                // Empty feed
                new JsonLightSerializerTestCase
                {
                    PayloadElement = PayloadBuilder.EntitySet().WithContextUri("http://odata.org/metadatauri"),
                    ExpectedJson   = @"
                        {
                          """ + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + @""":""http://odata.org/metadatauri"",
                          """ + JsonLightConstants.ODataValuePropertyName + @""":[]
                        }"
                },
                // Empty feed with count and next link
                new JsonLightSerializerTestCase
                {
                    PayloadElement = PayloadBuilder.EntitySet()
                                     .InlineCount(42)
                                     .NextLink("http://odata.org/next")
                                     .WithContextUri("http://odata.org/metadatauri"),
                    ExpectedJson = @"
                        {
                          """ + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + @""":""http://odata.org/metadatauri"",
                          """ + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + @""":42,
                          """ + JsonLightConstants.ODataValuePropertyName + @""":[],
                          """ + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + @""":""http://odata.org/next""
                        }"
                },
                // Feed with single entry
                new JsonLightSerializerTestCase
                {
                    PayloadElement = PayloadBuilder.EntitySet()
                                     .Append(PayloadBuilder.Entity().PrimitiveProperty("ID", (long)42))
                                     .WithContextUri("http://odata.org/metadatauri"),
                    ExpectedJson = @"
                        {
                          """ + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + @""":""http://odata.org/metadatauri"",
                          """ + JsonLightConstants.ODataValuePropertyName + @""":[
                            { ""ID"":42 }
                          ]
                        }"
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testCases,
                (testCase) =>
            {
                JsonValue actualValue   = this.JsonLightSerializer.ConvertToJsonLightValue(testCase.PayloadElement);
                JsonValue expectedValue = JsonTextPreservingParser.ParseValue(new StringReader(testCase.ExpectedJson));

                this.JsonValueComparer.Compare(expectedValue, actualValue);
            });
        }
 /// <summary>
 /// Constructs test descriptors which test feed ATOM metadata elements whose value is a URI ("icon" and "logo").
 /// </summary>
 /// <param name="uriElementName">The name of the ATOM metadata element to create test descriptors for.</param>
 /// <param name="addUriValueAtomMetadataAnnotation">A Func which takes an entity set instance and a string URI
 /// and produces the entity set instance with the added URI ATOM metadata.</param>
 /// <returns>A list of test descriptors.</returns>
 private IEnumerable <PayloadReaderTestDescriptor> CreateUriValueFeedTestDescriptors(
     string uriElementName,
     Func <EntitySetInstance, string, EntitySetInstance> addUriValueAtomMetadataAnnotation)
 {
     return(new PayloadReaderTestDescriptor[]
     {
         // Absolute URI
         new PayloadReaderTestDescriptor(this.Settings)
         {
             PayloadElement = addUriValueAtomMetadataAnnotation(PayloadBuilder.EntitySet(), "http://odata.org")
                              .XmlRepresentation(string.Format(CultureInfo.InvariantCulture,
                                                               @"<feed>
                         <{0}>http://odata.org</{0}>
                       </feed>)", uriElementName))
         },
         // Relative URI
         new PayloadReaderTestDescriptor(this.Settings)
         {
             PayloadElement = addUriValueAtomMetadataAnnotation(PayloadBuilder.EntitySet(), "http://odata.org/relative/uri")
                              .XmlRepresentation(string.Format(CultureInfo.InvariantCulture,
                                                               @"<feed xml:base='http://odata.org/'>
                         <{0}>relative/uri</{0}>
                      </feed>", uriElementName))
         },
         // URI with special characters
         new PayloadReaderTestDescriptor(this.Settings)
         {
             PayloadElement = addUriValueAtomMetadataAnnotation(PayloadBuilder.EntitySet(), "http://odata.org:8080/page?param=value&otherparam=other%20value")
                              .XmlRepresentation(string.Format(CultureInfo.InvariantCulture,
                                                               @"<feed>
                         <{0}>http://odata.org:8080/page?param=value&amp;otherparam=other%20value</{0}>
                       </feed>)", uriElementName))
         },
         // URI-valued element with extra attributes
         new PayloadReaderTestDescriptor(this.Settings)
         {
             PayloadElement = addUriValueAtomMetadataAnnotation(PayloadBuilder.EntitySet(), "http://odata.org")
                              .XmlRepresentation(string.Format(CultureInfo.InvariantCulture,
                                                               @"<feed>
                         <{0} extra='attribute' bla='bla'>http://odata.org</{0}>
                       </feed>)", uriElementName))
         },
         // Multiple URI-valued elements (not allowed for logos and icons, which are the only two URI-valued elements in feeds)
         new PayloadReaderTestDescriptor(this.Settings)
         {
             PayloadElement = PayloadBuilder.EntitySet()
                              .XmlRepresentation(string.Format(CultureInfo.InvariantCulture,
                                                               @"<feed>
                         <{0}>http://first.uri</{0}>
                         <{0}>http://second.uri</{0}>
                       </feed>", uriElementName)),
             ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomMetadataDeserializer_MultipleSingletonMetadataElements", uriElementName, "feed")
         },
     });
 }
Esempio n. 8
0
        public void FeedWithSubContextUriTest()
        {
            IEdmModel           model           = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container       = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet = container.FindEntitySet("Cities");
            IEdmType            cityType        = model.FindType("TestModel.CityType") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containing entries with and without sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .XmlRepresentation(
                        "<feed m:context=\"http://odata.org/test/$metadata#Cities(Id)\">" +
                        "<entry m:context=\"http://odata.org/test/$metadata#Cities(Id)/$entity\">" +
                        "<content type=\"application/xml\">" +
                        "<m:properties>" +
                        "<d:Id>1</d:Id>" +
                        "</m:properties>" +
                        "</content>" +
                        "</entry>" +
                        "<entry>" +
                        "<content type=\"application/xml\">" +
                        "<m:properties>" +
                        "<d:Id>2</d:Id>" +
                        "</m:properties>" +
                        "</content>" +
                        "</entry>" +
                        "</feed>")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 9
0
        public void DataServiceVersionHeaderTest()
        {
            EdmModel model = (EdmModel)Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            var entry = PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1)
                        .ExpandedNavigationProperty("CityHall", PayloadBuilder.EntitySet());

            DataServiceVersionTestDescriptor[] testDescriptors = new DataServiceVersionTestDescriptor[]
            {
                // valid entry with DSV 4.0
                new DataServiceVersionTestDescriptor(this.Settings)
                {
                    PayloadElement        = entry,
                    PayloadEdmModel       = model,
                    DataServiceVersion    = ODataVersion.V4.ToText(),
                    SkipTestConfiguration = tc => tc.Version != ODataVersion.V4,
                },
                // invalid DSV (negative number)
                new DataServiceVersionTestDescriptor(this.Settings)
                {
                    PayloadElement     = entry,
                    PayloadEdmModel    = model,
                    DataServiceVersion = "-1.0",
                    ExpectedException  = ODataExpectedExceptions.ODataException("ODataUtils_UnsupportedVersionHeader", "-1.0"),
                },
                // invalid DSV (unsupported positive number)
                new DataServiceVersionTestDescriptor(this.Settings)
                {
                    PayloadElement     = entry,
                    PayloadEdmModel    = model,
                    DataServiceVersion = "12345.0",
                    ExpectedException  = ODataExpectedExceptions.ODataException("ODataUtils_UnsupportedVersionHeader", "12345.0"),
                },
                // invalid DSV (NaN)
                new DataServiceVersionTestDescriptor(this.Settings)
                {
                    PayloadElement     = entry,
                    PayloadEdmModel    = model,
                    DataServiceVersion = "foo",
                    ExpectedException  = ODataExpectedExceptions.ODataException("ODataUtils_UnsupportedVersionHeader", "foo"),
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 10
0
        public void FeedStartElementTest()
        {
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // Empty feed element
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().XmlRepresentation("<feed/>")
                },
                // Element with wrong local name
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement    = PayloadBuilder.EntitySet().XmlRepresentation("<entry/>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomEntryAndFeedDeserializer_FeedElementWrongName", "entry", "http://www.w3.org/2005/Atom")
                },
                // Element with wrong local name
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement    = PayloadBuilder.EntitySet().XmlRepresentation("<Feed/>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomEntryAndFeedDeserializer_FeedElementWrongName", "Feed", "http://www.w3.org/2005/Atom")
                },
                // Element with wrong namespace
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement    = PayloadBuilder.EntitySet().XmlRepresentation("<d:feed/>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomEntryAndFeedDeserializer_FeedElementWrongName", "feed", "http://docs.oasis-open.org/odata/ns/data")
                },
                // Element with wrong namespace
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement    = PayloadBuilder.EntitySet().XmlRepresentation("<m:type/>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomEntryAndFeedDeserializer_FeedElementWrongName", "type", "http://docs.oasis-open.org/odata/ns/metadata")
                },
                // Empty feed element with additional attributes - all attributes are ignored
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().XmlRepresentation("<feed some='bar' m:type='Edm.String' m:null='true' m:etag='foo' d:prop='1' />")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }
        public void FeedAtomMetadataGeneratorTest()
        {
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // Basic generator with name, uri, and version
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomGenerator("Test Generator", "http://odata.org/generator", "1.0")
                },
                // Empty generator (empty element)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomGenerator(null, null, null)
                                     .XmlRepresentation("<feed><generator /></feed>")
                },
                // Empty generator (no children)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomGenerator(String.Empty, null, null)
                                     .XmlRepresentation("<feed><generator></generator></feed>")
                },
                // Generator with extra (ignored) attributes
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomGenerator("Test Generator", null, null)
                                     .XmlRepresentation("<feed><generator extra='attribute'>Test Generator</generator></feed>")
                },
                // Generator with attributes in the wrong namespace
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomGenerator("Test Generator", null, null)
                                     .XmlRepresentation("<feed><generator cn:uri='http://odata.org' cn:version='4.0' xmlns:cn='http://customnamespace.com'>Test Generator</generator></feed>")
                },
                // Feed with multiple generator elements should fail
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet()
                                     .XmlRepresentation(@"<feed>
                                                <generator uri='http://odata.org' version='1'>Some Name</generator>
                                                <generator uri='http://second.uri' version='2'>Another Name</generator>
                                             </feed>"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataAtomMetadataDeserializer_MultipleSingletonMetadataElements", "generator", "feed")
                },
            };

            this.RunAtomMetadataReaderTests(testDescriptors);
        }
        public void FeedAtomMetadataUpdatedTest()
        {
            // new[]
            // {
            //     PayloadBuilder.Entity("DefaultNamespace.Customer")
            // }
            var entitySet = PayloadBuilder.EntitySet();

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors =
                this.CreateDateConstructTestDescriptors(
                    entitySet,
                    "feed",
                    "updated",
                    AtomMetadataBuilder.AtomUpdated);

            this.RunAtomMetadataReaderTests(testDescriptors);
        }
Esempio n. 13
0
        public void FeedWithEntriesTest()
        {
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // Single empty entry (empty element)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().Append(PayloadBuilder.Entity())
                                     .XmlRepresentation("<feed><entry/></feed>")
                },
                // Single empty entry (full end element)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().Append(PayloadBuilder.Entity())
                                     .XmlRepresentation("<feed><entry></entry></feed>")
                },
                // Two entries (first empty element)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().Append(PayloadBuilder.Entity().ETag("etag1"), PayloadBuilder.Entity().ETag("etag2"))
                                     .XmlRepresentation("<feed><entry m:etag='etag1'/><entry m:etag='etag2'></entry></feed>")
                },
                // Two entries (first full end element)
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().Append(PayloadBuilder.Entity().ETag("etag1"), PayloadBuilder.Entity().ETag("etag2"))
                                     .XmlRepresentation("<feed><entry m:etag='etag1'></entry><entry m:etag='etag2'/></feed>")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().InlineCount(42).NextLink("http://odata.org/next").AtomId("urn:id")
                                     .Append(PayloadBuilder.Entity(), PayloadBuilder.Entity().ETag("second")),
                    SkipTestConfiguration = tc => tc.IsRequest
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 14
0
        /// <summary>
        /// Generates various payloads with different link properties set to the specified cross reference value.
        /// </summary>
        /// <param name="crossReferenceLink">The cross reference link values to set on each payload.</param>
        /// <param name="testConfiguration">The test configuration to use.</param>
        /// <returns>The payloads.</returns>
        private static IEnumerable <ODataPayloadElement> GeneratePayloadElementsWithCrossReferenceLinks(string crossReferenceLink, ReaderTestConfiguration testConfiguration)
        {
            List <ODataPayloadElement> payloadElements = new List <ODataPayloadElement>();

            // Entry with edit link
            payloadElements.Add(PayloadBuilder.Entity("TestModel.Address").PrimitiveProperty("Zip", 12345).WithEditLink(crossReferenceLink));

            // Entry with self link
            payloadElements.Add(PayloadBuilder.Entity("TestModel.Address").PrimitiveProperty("Zip", 98765).WithSelfLink(crossReferenceLink));

            // Entry with deferred navprop
            payloadElements.Add(PayloadBuilder.Entity("TestModel.CityType").DeferredNavigationProperty("CityHall", PayloadBuilder.DeferredLink(crossReferenceLink)));

            // Entry with expanded navprop
            payloadElements.Add(PayloadBuilder.Entity("TestModel.CityType").ExpandedNavigationProperty("PoliceStation", PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 0), crossReferenceLink));

            if (!testConfiguration.IsRequest)
            {
                // Entry with deferred navprop with association link
                payloadElements.Add(PayloadBuilder.Entity("TestModel.CityType").DeferredNavigationProperty("DOL", PayloadBuilder.DeferredLink("http://odata.org"), PayloadBuilder.DeferredLink(crossReferenceLink)));

                // Entry with expanded navprop with association link
                payloadElements.Add(PayloadBuilder.Entity("TestModel.CityType").NavigationProperty(
                                        PayloadBuilder.ExpandedNavigationProperty("PoliceStation", PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 0), "http://odata.org", crossReferenceLink)));

                // Entry with stream property with read link
                payloadElements.Add(PayloadBuilder.Entity("TestModel.CityType").StreamProperty("Skyline", crossReferenceLink));

                // Entry with stream property with edit link
                payloadElements.Add(PayloadBuilder.Entity("TestModel.CityType").StreamProperty("Skyline", null, crossReferenceLink));

                // Feed with multiple entries referencing same link
                payloadElements.Add(PayloadBuilder.EntitySet(
                                        new[]
                {
                    PayloadBuilder.Entity("TestModel.CityType").DeferredNavigationProperty("CityHall", PayloadBuilder.DeferredLink(crossReferenceLink)),
                    PayloadBuilder.Entity("TestModel.CityType").DeferredNavigationProperty("CityHall", PayloadBuilder.DeferredLink(crossReferenceLink)),
                }));
            }

            return(payloadElements);
        }
Esempio n. 15
0
        public void NextLinkTest()
        {
            IEnumerable <PayloadReaderTestDescriptor> testDescriptorsWithRecognizedNextLink =
                EntryReaderAtomTests.CreateLinkTestDescriptors(
                    this.Settings,
                    PayloadBuilder.EntitySet(),
                    (entitySet, link) => entitySet.NextLink(link),
                    "next",
                    "<feed>{0}</feed>");

            testDescriptorsWithRecognizedNextLink = testDescriptorsWithRecognizedNextLink.Select(td =>
                                                                                                 new PayloadReaderTestDescriptor(td)
            {
                SkipTestConfiguration = tc => tc.IsRequest,
            });

            IEnumerable <PayloadReaderTestDescriptor> testDescriptorsWithUnrecognizedNextLink =
                EntryReaderAtomTests.CreateLinkTestDescriptors(
                    this.Settings,
                    PayloadBuilder.EntitySet(),
                    (entitySet, link) => entitySet, // Next link should be ignored in requests and in V1
                    "next",
                    "<feed>{0}</feed>");

            // Set the expected exception to null for request and V1 payloads since we should be ignoring next links and not validating.
            testDescriptorsWithUnrecognizedNextLink = testDescriptorsWithUnrecognizedNextLink.Select(td =>
                                                                                                     new PayloadReaderTestDescriptor(td)
            {
                SkipTestConfiguration = tc => !tc.IsRequest,
                ExpectedException     = null,
            });

            // WCF DS client, server and default ODataLib show the same behavior when processing feed/link/[rel=next].
            this.CombinatorialEngineProvider.RunCombinations(
                TestReaderUtils.ODataBehaviorKinds,
                testDescriptorsWithRecognizedNextLink.Concat(testDescriptorsWithUnrecognizedNextLink),
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (behaviorKind, testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration.CloneAndApplyBehavior(behaviorKind));
            });
        }
Esempio n. 16
0
        public void FeedIDTest()
        {
            // TODO: This is not really testing atom:id since the test infrastructure doesn't support it at all (payload element doesn't serialize it, converter doesn't convert it)
            // so we are effectively only testing error/success here, not real reading.
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors =
                EntryReaderAtomTests.CreateIdTestDescriptors(
                    this.Settings,
                    PayloadBuilder.EntitySet(),
                    (entitySet, id) => entitySet.AtomId(id),
                    "<feed>{0}</feed>",
                    TestODataBehaviorKind.Default);

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 17
0
        public void FeedReadingBaseUriTest()
        {
            EdmModel model = (EdmModel)Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel();

            model.Fixup();

            EntitySetInstance feed = PayloadBuilder.EntitySet();

            // Run only in version >= 2 since next links are only supported since v2 and not allowed in requests
            this.CombinatorialEngineProvider.RunCombinations(
                payloadUris,
                baseUriValues,
                resolvers,
                new bool[] { false, true },
                this.ReaderTestConfigurationProvider.AtomFormatConfigurations.Where(tc => !tc.IsRequest),
                (payloadUri, baseUriValue, resolver, runInBatch, testConfiguration) =>
            {
                Action <EntitySetInstance, Uri, ReaderTestConfiguration> setNextLinkAction =
                    (instance, uri, testConfig) => instance.NextLink = UriToString(uri);
                this.RunBaseUriReadingTest(feed, setNextLinkAction, model, payloadUri, baseUriValue, resolver, testConfiguration, runInBatch);
            });
        }
        public void StreamReadWriteEntry()
        {
            EdmModel        model        = Microsoft.Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            ComplexInstance complexValue = ODataStreamingTestCase.GetComplexInstanceWithManyPrimitiveProperties(model);

            var payloadDescriptors = new[]
            {
                // Multiple nesting of Complex Values and Multiple Values.
                new PayloadTestDescriptor()
                {
                    PayloadElement        = PayloadBuilder.Property("propertyName", complexValue),
                    PayloadEdmModel       = model.Clone(),
                    SkipTestConfiguration = (tc) => tc.Version < ODataVersion.V4
                }.InComplexValue().InCollection().InProperty().InComplexValue().InCollection().InProperty().
                InComplexValue()
                .InCollection().InProperty().InComplexValue().InCollection().InProperty().InEntity(),

                // Multiple nesting of Complex Values.
                new PayloadTestDescriptor()
                {
                    PayloadElement  = PayloadBuilder.Property("propertyName", complexValue),
                    PayloadEdmModel = model.Clone(),
                }.InComplexValue().InProperty().InComplexValue().InProperty().InComplexValue().InProperty()
                .InComplexValue().InProperty().InComplexValue().InProperty().InComplexValue().InProperty().
                InEntity(1, 0),

                // Entry With an Expanded Link which is an entry containing a Complex collection.
                new PayloadTestDescriptor()
                {
                    PayloadElement        = complexValue,
                    PayloadEdmModel       = model.Clone(),
                    SkipTestConfiguration = (tc) => tc.Version < ODataVersion.V4
                }.InCollection(1, 1).InProperty().InComplexValue().InCollection().InProperty().InEntity().
                InEntryWithExpandedLink(/*singletonRelationship*/ true),

                // Entry With an Expanded Link which is a Feed containing an Entry with Complex collection properties.
                new PayloadTestDescriptor()
                {
                    PayloadElement        = complexValue,
                    PayloadEdmModel       = model.Clone(),
                    SkipTestConfiguration = (tc) => tc.Version < ODataVersion.V4
                }.InCollection(1, 2).InProperty().InComplexValue(1, 1).InCollection(1, 0).InProperty().
                InEntity(1, 1).InFeed(2).InEntryWithExpandedLink(),

                // Entry With Nested Expanded Links which contain Entries.
                new PayloadTestDescriptor()
                {
                    PayloadElement  = PayloadBuilder.Property("propertyName", complexValue),
                    PayloadEdmModel = model.Clone(),
                }.InEntity(1, 1, ODataVersion.V4).InEntryWithExpandedLink(/*singletonRelationship*/ true).
                InEntryWithExpandedLink(/*singletonRelationship*/ true)
                .InEntryWithExpandedLink(/*singletonRelationship*/ true).InEntryWithExpandedLink(              /*singletonRelationship*/
                    true)
                .InEntryWithExpandedLink(/*singletonRelationship*/ true).InEntryWithExpandedLink(              /*singletonRelationship*/
                    true),

                // Entry with inline expanded feed association to an arbitrary depth (7) where the expanded feed has no entries
                new PayloadTestDescriptor()
                {
                    PayloadElement =
                        PayloadBuilder.EntitySet().WithTypeAnnotation(
                            model.FindDeclaredType("TestModel.OfficeType")),
                    PayloadEdmModel = model.Clone(),
                }.InEntryWithExpandedLink().InFeed(2).InEntryWithExpandedLink().InFeed(2).
                InEntryWithExpandedLink().InFeed(2).InEntryWithExpandedLink()
                .InFeed(2).InEntryWithExpandedLink(),
            };

            var testDescriptors = this.PayloadDescriptorsToStreamDescriptors(payloadDescriptors);

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.ExplicitFormatConfigurations.Where(
                    tc => tc.Synchronous),
                (testDescriptor, testConfiguration) =>
            {
                if (testConfiguration.Format == ODataFormat.Json)
                {
                    testDescriptor.PayloadElement.Accept(new JsonDateTimeV3RepresentationFixup());
                }

                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 19
0
        private IEnumerable <PayloadReaderTestDescriptor> CreateFeedValidatorDescriptors(IEdmModel model)
        {
            var cityType     = model.FindType("TestModel.CityType");
            var personType   = model.FindType("TestModel.Person");
            var employeeType = model.FindType("TestModel.Employee");

            var testCases = new[]
            {
                new
                {
                    Description = "Homogenous collection (no inheritance)",
                    Feed        = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                                  .Append(PayloadBuilder.Entity("TestModel.Person")
                                          .PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
                                  .Append(PayloadBuilder.Entity("TestModel.Person")
                                          .PrimitiveProperty("Id", 2).WithTypeAnnotation(personType)),
                    ExpectedException = (ExpectedException)null,
                    Model             = model
                },
                new
                {
                    Description = "Homogenous collection (inheritance, base type first)",
                    Feed        = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                                  .Append(PayloadBuilder.Entity("TestModel.Person")
                                          .PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
                                  .Append(PayloadBuilder.Entity("TestModel.Employee")
                                          .PrimitiveProperty("Id", 2).WithTypeAnnotation(employeeType)),
                    ExpectedException = (ExpectedException)null,
                    Model             = model
                },
                new
                {
                    Description = "Homogenous collection (inheritance, derived type first)",
                    Feed        = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                                  .Append(PayloadBuilder.Entity("TestModel.Employee")
                                          .PrimitiveProperty("Id", 1).WithTypeAnnotation(employeeType))
                                  .Append(PayloadBuilder.Entity("TestModel.Person")
                                          .PrimitiveProperty("Id", 2).WithTypeAnnotation(personType)),
                    ExpectedException = (ExpectedException)null,
                    Model             = model
                },
                new
                {
                    Description = "Heterogeneous collection",
                    Feed        = (ODataPayloadElement)PayloadBuilder.EntitySet().WithTypeAnnotation(personType).IgnoreEntitySet()
                                  .Append(PayloadBuilder.Entity("TestModel.Person")
                                          .PrimitiveProperty("Id", 1).WithTypeAnnotation(personType))
                                  .Append(PayloadBuilder.Entity("TestModel.CityType")
                                          .PrimitiveProperty("Id", 2).WithTypeAnnotation(cityType)),
                    ExpectedException = ODataExpectedExceptions.ODataException("ResourceSetWithoutExpectedTypeValidator_IncompatibleTypes", "TestModel.CityType", "TestModel.Person"),
                    Model             = model
                },
                new
                {
                    Description = "Heterogeneous collection (no model)",
                    Feed        = (ODataPayloadElement)PayloadBuilder.EntitySet().IgnoreEntitySet()
                                  .Append(PayloadBuilder.Entity("TestModel.Person")
                                          .PrimitiveProperty("Id", 1))
                                  .Append(PayloadBuilder.Entity("TestModel.CityType")
                                          .PrimitiveProperty("Id", 2)),
                    ExpectedException = (ExpectedException)null,
                    Model             = (IEdmModel)null
                },
            };

            // Create the tests for a top-level feed
            return(testCases.Select(testCase =>
                                    new PayloadReaderTestDescriptor(this.Settings)
            {
                DebugDescription = testCase.Description,
                PayloadDescriptor = new PayloadTestDescriptor()
                {
                    DebugDescription = testCase.Description,
                    PayloadElement = testCase.Feed,
                },
                PayloadEdmModel = testCase.Model,
                ExpectedException = testCase.ExpectedException,
            }));
        }
Esempio n. 20
0
        public void EntryAtomMetadataSourceTest()
        {
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                // Empty source element
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet())
                                     .XmlRepresentation("<entry><source /></entry>")
                },
                // Source element with no children
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet())
                                     .XmlRepresentation("<entry><source></source></entry>")
                },
                // Source element with only text value
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet())
                                     .XmlRepresentation("<entry><source>test text</source></entry>")
                },
                // Source element with every type of feed metadata inside
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    // This includes two elements for every feed metadata element where duplicates are allowed.
                    PayloadElement = PayloadBuilder.Entity().AtomSource(
                        PayloadBuilder.EntitySet()
                        .AtomAuthor("John Smith", "http://john.smith", "*****@*****.**")
                        .AtomAuthor("Jane Doe", null, null)
                        .AtomCategory("term", "http://scheme.org", "label")
                        .AtomContributor("John Smith", "http://john.smith", "*****@*****.**")
                        .AtomContributor("Jane Doe", null, null)
                        .AtomGenerator("Generator Name", "http://odata.org", "2.5")
                        .AtomIcon("http://odata.org/icon")
                        .AtomId("http://some.unique.id/")
                        .AtomLink("http://testlink.com", "http://somerel.com", null)
                        .AtomLink("http://otherlink.com", "relval", "text/html", "en", "LinkTitle", "100")
                        .AtomLogo("http://odata.org/logo")
                        .AtomRights("Copyright (C) Some Company, 2015", TestAtomConstants.AtomTextConstructTextKind)
                        .AtomSubtitle("Subtitle <em>text</em>", TestAtomConstants.AtomTextConstructHtmlKind)
                        .AtomTitle("A Title", TestAtomConstants.AtomTextConstructTextKind)
                        .AtomUpdated("2001-10-26T21:32:52Z")
                        )
                },
                // Source element with feed metadata elements which would be interpreted differently if they were entry metadata
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(
                        PayloadBuilder.EntitySet()
                        // The following links have rel values which are special to entries but not to feeds
                        .AtomLink("http://odata.org/edit", "edit", null)
                        .AtomLink("http://odata.org/editmedia", "edit-media", null)
                        .AtomLink("http://odata.org/namedstream", "http://docs.oasis-open.org/odata/ns/mediaresource/NamedStream", null)
                        .AtomLink("http://odata.org/editnamedstream", "http://docs.oasis-open.org/odata/ns/edit-media/NamedStream", null)
                        .AtomLink("http://odata.org/assoclink", "http://docs.oasis-open.org/odata/ns/relatedlinks/AssociationLink", null)
                        .AtomLink("http://odata.org/navprop", "http://docs.oasis-open.org/odata/ns/related/NavProp", null)
                        // On an entry this would modify the type name, but should have no effect with feeds
                        .AtomCategory("TestModel.TypeName", "http://docs.oasis-open.org/odata/ns/scheme", "someLabel"))
                },
            };

            this.RunAtomMetadataReaderTests(testDescriptors);
        }
Esempio n. 21
0
        public void FeedReaderTest()
        {
            IEdmModel           model           = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container       = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet = container.FindEntitySet("Cities");
            IEdmType            cityType        = model.FindType("TestModel.CityType") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                #region Test cases
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed without next link or inline count.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a next link annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink")
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a next link annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink")
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a inline count annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet(null, 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with a inline count annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet(null, 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link and inline count annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link and inline count annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link before and inline count after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link after and inline count before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with next link after and inline count before the feed property and custom annotations.",
                    PayloadElement   = PayloadBuilder.EntitySet("http://odata.org/test/nextlink", 42)
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"@my.annotation\":\"annotation-value\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":\"http://odata.org/test/nextlink\"," +
                                                           "\"@my.annotation2\":\"annotation-value2\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"@my.annotation3\":\"annotation-value3\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42," +
                                                           "\"@my.annotation4\":\"annotation-value4\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with primitive item in feed property value.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ 1 ]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonReader_CannotReadResourcesOfResourceSet", "PrimitiveValue"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with array item in feed property value.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Edm.Untyped\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[ [ 1 ] ]" +
                                                           "}")
                                       .ExpectedEntityType(EdmCoreModel.Instance.GetUntyped()),
                    ExpectedResultPayloadElement = (ReaderTestConfiguration t) => { return(PayloadBuilder.EntitySet().Append(new ODataPayloadElement[] { PayloadBuilder.EntitySet().Append(new PrimitiveValue("Edm.Int32", 1)) })); },
                    PayloadEdmModel = model,
                },
                #endregion Test cases
            };

            // TODO: all of the above for feeds in expanded navigation links

            // TODO: non-empty feed with entries of base type, of base + derived type, only derived type (with and without derived type specified as expected type)
            // TODO: non-empty feed at top-level and expanded navigation link

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 22
0
        public void NullValueNonPropertyErrorTests()
        {
            EdmModel model      = new EdmModel();
            var      entityType = model.EntityType("OwningType", "TestModel").KeyProperty("ID", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference);

            model.EntityContainer("DefaultContainer");
            var entitySet = model.EntitySet("EntitySet", entityType);

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null collection - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = PayloadBuilder.PrimitiveCollection().ExpectedCollectionItemType(EdmDataTypes.Int32)
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                        "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Collection")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null entry - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = PayloadBuilder.NullEntity().ExpectedEntityType(entityType, entitySet)
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                        "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Entry")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "null feed - should fail.",
                    PayloadEdmModel  = model,
                    PayloadElement   = PayloadBuilder.EntitySet().ExpectedEntityType(entityType, entitySet)
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Edm.Null\"" +
                        "}"),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightContextUriParser_ContextUriDoesNotMatchExpectedPayloadKind", "http://odata.org/test/$metadata#Edm.Null", "Feed")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                if (testConfiguration.IsRequest)
                {
                    return;
                }

                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 23
0
        public void TestInvalidUriInAtomMetadata()
        {
            // A string which breaks URI syntax, as defined by RFC 2396
            const string invalidUri = "http://::";

            // Other unimportant values to use for creating payloads to test.
            const string personName       = "Name";
            const string personEmail      = "*****@*****.**";
            const string collectionTitle  = "Collection";
            const string validUri         = "http://odata.org";
            const string generatorName    = "Test Generator";
            const string generatorVersion = "1.0";
            const string nonOdataRelValue = "someRel";
            const string linkType         = "text/html";

            // Create a test descriptor for each possible place the spec says a Uri can appear and is exposed as ATOM metadata.
            // Note: This excludes the two spots where the spec says the value is a Uri, but we expose it as a string:
            //       scheme attributes of category and categories elements, and the id of the source feed of an entry.
            //       This also excludes any Uri values that are always parsed, whether or not ATOM metadata reading is on,
            //       such as the href attribute in a collection element.
            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new PayloadReaderTestDescriptor[]
            {
                #region uri attribute in a generator
                // atom:feed/atom:generator/@uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomGenerator(generatorName, invalidUri, generatorVersion),
                },
                // atom:entry/atom:source/atom:generator/@uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet().AtomGenerator(generatorName, invalidUri, generatorVersion)),
                },
                #endregion uri attribute in a generator

                #region uri element in person constructs
                // atom:feed/atom:author/atom:uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomAuthor(personName, invalidUri, personEmail),
                },
                // atom:feed/atom:contributor/atom:uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomContributor(personName, invalidUri, personEmail),
                },
                // atom:entry/atom:author/atom:uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomAuthor(personName, invalidUri, personEmail),
                },
                // atom:entry/atom:contributor/atom:uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomContributor(personName, invalidUri, personEmail),
                },
                // atom:entry/atom:source/atom:author/atom:uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet().AtomAuthor(personName, invalidUri, personEmail)),
                },
                // atom:entry/atom:source/atom:contributor/atom:uri
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet().AtomContributor(personName, invalidUri, personEmail)),
                },
                #endregion uri element in person constructs

                #region content of icon element
                // atom:feed/atom:icon
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomIcon(invalidUri),
                },
                // atom:entry/atom:source/atom:icon
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet().AtomIcon(invalidUri)),
                },
                #endregion content of icon element

                #region content of logo element
                // atom:feed/atom:logo
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomLogo(invalidUri),
                },
                // atom:entry/atom:source/atom:logo
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet().AtomLogo(invalidUri)),
                },
                #endregion content of logo element

                #region href attribute in a link
                // atom:feed/atom:link/@href
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.EntitySet().AtomLink(invalidUri, nonOdataRelValue, linkType),
                },
                // atom:entry/atom:link/@href
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomLink(invalidUri, nonOdataRelValue, linkType),
                },
                // atom:entry/atom:source/atom:link/@href
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.Entity().AtomSource(PayloadBuilder.EntitySet().AtomLink(invalidUri, nonOdataRelValue, linkType)),
                },
                #endregion href attribute in a link

                #region href attribute in an out-of-line categories element
                // app:service/app:workspace/app:collection/app:categories/@href
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.ServiceDocument()
                                     .Workspace(PayloadBuilder.Workspace()
                                                .ResourceCollection(PayloadBuilder.ResourceCollection(collectionTitle, validUri)
                                                                    .AppOutOfLineCategories(invalidUri))),
                    SkipTestConfiguration = tc => tc.IsRequest,
                },
                #endregion href attribute in an out-of-line categories element
            };

            // Add the expected exception to all test descriptors.
            testDescriptors = testDescriptors.Select(td =>
                                                     new PayloadReaderTestDescriptor(td)
            {
                ExpectedException = new ExpectedException(typeof(System.UriFormatException)),
            });

            // This method is set up so that expected exceptions are only expected when ATOM metadata reading is on.
            this.RunAtomMetadataReaderTests(testDescriptors);
        }
Esempio n. 24
0
        /// <summary>
        /// Creates a set of interesting entity set instances along with metadata.
        /// </summary>
        /// <param name="settings">The test descriptor settings to use.</param>
        /// <param name="model">If non-null, the method creates types as needed and adds them to the model.</param>
        /// <param name="withTypeNames">true if the payloads should specify type names.</param>
        /// <returns>List of test descriptors with interesting entity instances as payload.</returns>
        public static IEnumerable <PayloadTestDescriptor> CreateEntitySetTestDescriptors(
            EdmModel model,
            bool withTypeNames)
        {
            EdmEntityType  personType = null;
            EdmComplexType carType    = null;
            var            container  = model.EntityContainer as EdmEntityContainer;

            if (container == null)
            {
                container = new EdmEntityContainer("TestModel", "DefaultNamespace");
                model.AddElement(container);
            }

            if (model != null)
            {
                personType = model.FindDeclaredType("TestModel.TFPerson") as EdmEntityType;
                carType    = model.FindDeclaredType("TestModel.TFCar") as EdmComplexType;

                // Create the metadata types for the entity instance used in the entity set
                if (carType == null)
                {
                    carType = new EdmComplexType("TestModel", "TFCar");
                    carType.AddStructuralProperty("Make", EdmPrimitiveTypeKind.String);
                    carType.AddStructuralProperty("Color", EdmPrimitiveTypeKind.String);
                    model.AddElement(carType);
                }

                if (personType == null)
                {
                    personType = new EdmEntityType("TestModel", "TFPerson");
                    var keyProperty = personType.AddStructuralProperty("Id", EdmPrimitiveTypeKind.Int32);
                    personType.AddStructuralProperty("Name", EdmPrimitiveTypeKind.String);
                    personType.AddStructuralProperty("Car", carType.ToTypeReference());
                    personType.AddKeys(keyProperty);
                    model.AddElement(personType);
                    container.AddEntitySet("TFPerson", personType);
                }
            }

            ComplexInstance carInstance = PayloadBuilder.ComplexValue(withTypeNames ? "TestModel.TFCar" : null)
                                          .Property("Make", PayloadBuilder.PrimitiveValue("Ford"))
                                          .Property("Color", PayloadBuilder.PrimitiveValue("Blue"));

            EntityInstance personInstance = PayloadBuilder.Entity(withTypeNames ? "TestModel.TFPerson" : null)
                                            .Property("Id", PayloadBuilder.PrimitiveValue(1))
                                            .Property("Name", PayloadBuilder.PrimitiveValue("John Doe"))
                                            .Property("Car", carInstance);

            // empty feed
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet().WithTypeAnnotation(personType), PayloadEdmModel = model
            });

            // entity set with a single entity
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet().Append(personInstance).WithTypeAnnotation(personType), PayloadEdmModel = model
            });

            // entity set with the person instance in the middle
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet()
                                 .Append(personInstance.GenerateSimilarEntries(2))
                                 .Append(personInstance)
                                 .Append(personInstance.GenerateSimilarEntries(1))
                                 .WithTypeAnnotation(personType),
                PayloadEdmModel = model
            });

            // entity set with a single entity and a next link
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet().Append(personInstance).NextLink(nextLink).WithTypeAnnotation(personType),
                PayloadEdmModel = model,
                SkipTestConfiguration = tc => tc.IsRequest
            });

            // entity set with a single entity and inline count
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet().Append(personInstance).InlineCount(1).WithTypeAnnotation(personType),
                PayloadEdmModel = model,
                SkipTestConfiguration = tc => tc.IsRequest
            });

            // entity set with a single entity, a next link and inline count
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet().Append(personInstance).NextLink(nextLink).InlineCount(1).WithTypeAnnotation(personType),
                PayloadEdmModel = model,
                SkipTestConfiguration = tc => tc.IsRequest
            });

            // entity set with a single entity, a next link and a negative inline count
            yield return(new PayloadTestDescriptor()
            {
                PayloadElement = PayloadBuilder.EntitySet().Append(personInstance).NextLink(nextLink).InlineCount(-1).WithTypeAnnotation(personType),
                PayloadEdmModel = model,
                SkipTestConfiguration = tc => tc.IsRequest
            });
            // entity set containing many entities of types derived from the same base
            //yield return new PayloadTestDescriptor()
            //{
            //    PayloadElement = CreateDerivedEntitySetInstance(model, withTypeNames),
            //    PayloadEdmModel = model,
            //};
        }
        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 FeedMessageSizeLimitReadTest()
        {
            EdmModel model = Test.OData.Utils.Metadata.TestModels.BuildTestModel() as EdmModel;

            var entityType = model.FindDeclaredType("TestModel.Person") as EdmEntityType;

            ODataPayloadElement payload = PayloadBuilder.EntitySet(new EntityInstance[]
            {
                PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 1),
                PayloadBuilder.Entity("TestModel.Person").PrimitiveProperty("Id", 2),
            }).WithTypeAnnotation(entityType);

            var testCases = new MessageSizeLimitTestCase[]
            {
                // Single byte size should fail
                new MessageSizeLimitTestCase
                {
                    MaxMessageSize = 1,
                    AtomSizes      = new RequestResponseSizes {
                        RequestSize = 735, ResponseSize = 735
                    },
                    JsonLightSizes = new RequestResponseSizes {
                        RequestSize = 200, ResponseSize = 202
                    },
                },
                // Small number should fail
                new MessageSizeLimitTestCase
                {
                    MaxMessageSize = 40,
                    AtomSizes      = new RequestResponseSizes {
                        RequestSize = 735, ResponseSize = 735
                    },
                    JsonLightSizes = new RequestResponseSizes {
                        RequestSize = 200, ResponseSize = 202
                    },
                },
                // ATOM & JSON-L fails, Verbose JSON works
                new MessageSizeLimitTestCase
                {
                    MaxMessageSize = 150,
                    AtomSizes      = new RequestResponseSizes {
                        RequestSize = 735, ResponseSize = 735
                    },
                    JsonLightSizes = new RequestResponseSizes {
                        RequestSize = 200, ResponseSize = 202
                    },
                },
                // Large number should work
                new MessageSizeLimitTestCase
                {
                    MaxMessageSize = 10000,
                },
                // Default should work
                new MessageSizeLimitTestCase
                {
                    MaxMessageSize = -1,
                },
            };

            this.RunAtomJsonMessageSizeLimitTests(model, payload, testCases);
        }
Esempio n. 27
0
        public void FeedReaderErrorTest()
        {
            IEdmModel           model           = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container       = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet = container.FindEntitySet("Cities");
            IEdmType            cityType        = model.FindType("TestModel.CityType") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                #region Test cases
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with OData property annotation before top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with OData property annotation after top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName(JsonLightConstants.ODataValuePropertyName, JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with invalid feed property value.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":{}" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_CannotReadResourceSetContentStart", "StartObject")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"other\":\"42\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_InvalidPropertyInTopLevelResourceSet", "other", JsonLightConstants.ODataValuePropertyName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property annotation before the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName("other", JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"other\":\"42\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_InvalidPropertyInTopLevelResourceSet", "other", JsonLightConstants.ODataValuePropertyName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with invalid property annotation after the feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightUtils.GetPropertyAnnotationName("other", JsonLightConstants.ODataCountAnnotationName) + "\":\"42\"" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedAnnotationProperties", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed with missing feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":42" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightResourceDeserializer_ExpectedResourceSetPropertyNotFound", "value")
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with odata.count annotation with null value before top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataCountAnnotationName + "\":null," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataCountAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with odata.nextLink annotation with null value before top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":null," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataNextLinkAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with odata.nextLink annotation with null value after top-level feed property.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataNextLinkAnnotationName + "\":null" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataNextLinkAnnotationName)
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed with duplicate feed properties.",
                    PayloadElement   = PayloadBuilder.EntitySet()
                                       .JsonRepresentation("{" +
                                                           "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities\"," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]," +
                                                           "\"" + JsonLightConstants.ODataValuePropertyName + "\":[]" +
                                                           "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException("DuplicatePropertyNamesNotAllowed", JsonLightConstants.ODataValuePropertyName)
                },
                #endregion Test cases
            };

            // TODO: all of the above for feeds in expanded navigation links

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
        public void NoMetadataTest()
        {
            EdmModel model     = new EdmModel();
            var      container = new EdmEntityContainer("TestModel", "DefaultContainer");

            model.AddElement(container);

            var testDescriptors = new[]
            {
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.EntitySet(),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.EntitySet(),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.EntitySet(),
                    PayloadEdmModel       = model,
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_NoEntitySetForRequest"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.Entity(),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.Entity(),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.Entity(),
                    PayloadEdmModel       = model,
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_NoEntitySetForRequest"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.PrimitiveProperty("propertyName", 42),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.Property("propertyName", PayloadBuilder.ComplexValue()),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.Property("propertyName", PayloadBuilder.PrimitiveMultiValue()),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.PrimitiveCollection(),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.PrimitiveCollection(),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement = PayloadBuilder.PrimitiveCollection(),
                    //PayloadModel = model,
                    PayloadEdmModel       = model,
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ItemTypeRequiredForCollectionReaderInRequests"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.ComplexCollection(),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.ComplexCollection(),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.ComplexCollection(),
                    PayloadEdmModel       = model,
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ItemTypeRequiredForCollectionReaderInRequests"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.ServiceDocument().Workspace(PayloadBuilder.Workspace()),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.DeferredLink("http://odata.org/deferred"),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.DeferredLink("http://odata.org/deferred"),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.LinkCollection(),
                    SkipTestConfiguration = tc => tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightDeserializer_ContextLinkNotFoundAsFirstProperty"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.ComplexValue(),
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ODataException("ODataJsonLightInputContext_ModelRequiredForReading"),
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    PayloadElement        = PayloadBuilder.ComplexValue(),
                    PayloadEdmModel       = model,
                    SkipTestConfiguration = tc => !tc.IsRequest,
                    ExpectedException     = ODataExpectedExceptions.ArgumentNullException("ODataJsonLightInputContext_OperationCannotBeNullForCreateParameterReader", "operation")
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                // These descriptors are already tailored specifically for Json Light and
                // do not require normalization.
                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 29
0
        public void FeedReaderWithSubContextUriTest()
        {
            IEdmModel           model            = Test.OData.Utils.Metadata.TestModels.BuildTestModel();
            IEdmEntityContainer container        = model.FindEntityContainer("DefaultContainer");
            IEdmEntitySet       citiesEntitySet  = container.FindEntitySet("Cities");
            IEdmType            cityType         = model.FindType("TestModel.CityType") as IEdmType;
            IEdmEntitySet       personsEntitySet = container.FindEntitySet("Persons");
            IEdmType            personType       = model.FindType("TestModel.Person") as IEdmType;

            IEnumerable <PayloadReaderTestDescriptor> testDescriptors = new[]
            {
                #region Test cases
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containing entries with and without sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities/$entity\"," +
                        "\"Id\":1" +
                        "}," +
                        "{" +
                        "\"Id\":2" +
                        "}," +
                        "]" +
                        "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containing entries with expanded navigation properties with sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[] {
                        PayloadBuilder
                        .Entity("TestModel.CityType")
                        .PrimitiveProperty("Id", 1)
                        .ExpandedNavigationProperty(
                            "CityHall",
                            PayloadBuilder.EntitySet(new EntityInstance[]
                        {
                            PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                            {
                                TypeName = null
                            }),
                        }))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        })
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id,CityHall(Id))/$entity\"," +
                        "\"Id\":1," +
                        "\"CityHall\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Offices/$entity\"," +
                        "\"Id\":1" +
                        "}" +
                        "]" +
                        "}" +
                        "]" +
                        "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel = model
                },
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Feed containg entries with mismatch sub context uri",
                    PayloadElement   = PayloadBuilder
                                       .EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 1).AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Cities(Id)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Offices/$entity\"," +
                        "\"Id\":1" +
                        "}," +
                        "]" +
                        "}")
                                       .ExpectedEntityType(cityType, citiesEntitySet),
                    PayloadEdmModel   = model,
                    ExpectedException = ODataExpectedExceptions.ODataException(
                        "ReaderValidationUtils_ContextUriValidationInvalidExpectedEntitySet",
                        "http://odata.org/test/$metadata#Offices/$entity",
                        "Offices",
                        "Cities")
                },

                /* TODO: Enable this case after updating SelectedPropertiesNode class to adapt to V4
                 * new PayloadReaderTestDescriptor(this.Settings)
                 * {
                 *  DebugDescription = "Empty feed without next link or inline count.",
                 *  PayloadElement = PayloadBuilder.EntitySet( new EntityInstance[]
                 *  {
                 *      PayloadBuilder.Entity("TestModel.CityType")
                 *          .PrimitiveProperty("Id", 1)
                 *          .NavigationProperty(new NavigationPropertyInstance("PoliceStation",null))
                 *          .AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }),
                 *      PayloadBuilder.Entity("TestModel.CityType").PrimitiveProperty("Id", 2).AddAnnotation(new SerializationTypeNameTestAnnotation() { TypeName = null }),
                 *  })
                 *      .JsonRepresentation(
                 *          "{" +
                 *              "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#Collection(TestModel.CityType)\"," +
                 *              "\"" + JsonLightConstants.ODataValuePropertyName + "\":[" +
                 *                  "{" +
                 *                      "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities/$entity\"," +
                 *                      "\"Id\":1" +
                 *                  "}," +
                 *                  "{" +
                 *                      "\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataContextAnnotationName + "\":\"http://odata.org/test/$metadata#TestModel.DefaultContainer.Cities/$entity\"," +
                 *                      "\"Id\":2" +
                 *                  "}," +
                 *              "]" +
                 *          "}")
                 *      .ExpectedEntityType(cityType, citiesEntitySet),
                 *  PayloadEdmModel = model
                 * },
                 */
                new PayloadReaderTestDescriptor(this.Settings)
                {
                    DebugDescription = "Empty feed without next link or inline count.",
                    PayloadElement   = PayloadBuilder.EntitySet(new EntityInstance[]
                    {
                        PayloadBuilder.Entity("TestModel.Person")
                        .PrimitiveProperty("Id", 1)
                        .ExpandedNavigationProperty(
                            "Friend",
                            PayloadBuilder.EntitySet(new EntityInstance[] {}))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.Person")
                        .PrimitiveProperty("Id", 2)
                        .ExpandedNavigationProperty(
                            "Friend",
                            PayloadBuilder.EntitySet(new EntityInstance[] {}))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                        PayloadBuilder.Entity("TestModel.Person")
                        .PrimitiveProperty("Id", 3)
                        .ExpandedNavigationProperty(
                            "Friend",
                            PayloadBuilder.EntitySet(new EntityInstance[] {}))
                        .AddAnnotation(new SerializationTypeNameTestAnnotation()
                        {
                            TypeName = null
                        }),
                    })
                                       .JsonRepresentation(
                        "{" +
                        "\"@odata.context\":\"http://odata.org/test/$metadata#Collection(TestModel.Person)\"," +
                        "\"value\":[" +
                        "{" +
                        "\"@odata.context\":\"$metadata#TestModel.DefaultContainer.Persons/$entity\"," +
                        "\"Id\":1," +
                        "\"Friend\":[]" +
                        "}," +
                        "{" +
                        "\"@odata.context\":\"#Persons/$entity\"," +
                        "\"Id\":2," +
                        "\"Friend\":[]" +
                        "}," +
                        "{" +
                        "\"@odata.context\":\"#TestModel.Person\"," +
                        "\"Id\":3," +
                        "\"Friend\":[]" +
                        "}," +
                        "]" +
                        "}")
                                       .ExpectedEntityType(personType, personsEntitySet),
                    PayloadEdmModel = model
                },
                #endregion Test cases
            };

            this.CombinatorialEngineProvider.RunCombinations(
                testDescriptors,
                this.ReaderTestConfigurationProvider.JsonLightFormatConfigurations,
                (testDescriptor, testConfiguration) =>
            {
                if (testConfiguration.IsRequest && testDescriptor.ExpectedException != null)
                {
                    return;
                }

                testDescriptor.TestDescriptorNormalizers.Clear();
                testDescriptor.RunTest(testConfiguration);
            });
        }
Esempio n. 30
0
        public void CollectionNavigationLinkInRequestTest()
        {
            IEnumerable <NavigationLinkTestCase> testCases = new[]
            {
                new NavigationLinkTestCase
                {
                    DebugDescription           = "Just binding links - one",
                    Json                       = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[\"http://odata.org/referencelink1\"]",
                    ExpectedEntity             = PayloadBuilder.Entity().NavigationProperty("CityHall", "http://odata.org/referencelink1"),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Just binding links - multiple",
                    Json             = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[" +
                                       "\"http://odata.org/referencelink1\"," +
                                       "\"http://odata.org/referencelink2\"," +
                                       "\"http://odata.org/referencelink3\"]",
                    ExpectedEntity = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new LinkCollection(
                                                                                                         PayloadBuilder.DeferredLink("http://odata.org/referencelink1"),
                                                                                                         PayloadBuilder.DeferredLink("http://odata.org/referencelink2"),
                                                                                                         PayloadBuilder.DeferredLink("http://odata.org/referencelink3")))),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Empty binding array - invalid",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[]",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_EmptyBindArray", JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding annotation value - object",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":{}",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding annotation value - null",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":null",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding annotation value - number",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":42",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_CannotReadPropertyValueAsString", "42", JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding annotation value - string - we need array for collection nav. prop.",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":\"http://odata.org/referencelink1\"",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightEntryAndFeedDeserializer_StringValueForCollectionBindPropertyAnnotation", "CityHall", JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding item value - object",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[{}]",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartObject"),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding item value - array",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[[]]",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_UnexpectedNodeDetected", "PrimitiveValue", "StartArray"),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding item value - null",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[null]",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightReaderUtils_AnnotationWithNullValue", JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription  = "Invalid binding item value - number",
                    Json              = "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[42]",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("JsonReaderExtensions_CannotReadPropertyValueAsString", "42", JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Binding links with custom annotation before",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", "custom.annotation") + "\":null," +
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[\"http://odata.org/referencelink1\"]",
                    ExpectedEntity             = PayloadBuilder.Entity().NavigationProperty("CityHall", "http://odata.org/referencelink1"),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Binding links with custom annotation after",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[\"http://odata.org/referencelink1\"]," +
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", "custom.annotation") + "\":null",
                    ExpectedEntity             = PayloadBuilder.Entity().NavigationProperty("CityHall", "http://odata.org/referencelink1"),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Collection navigation property with just custom annotation - invalid",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", "custom.annotation") + "\":null",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException(
                        "ODataJsonLightEntryAndFeedDeserializer_NavigationPropertyWithoutValueAndEntityReferenceLink",
                        "CityHall",
                        JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed - empty",
                    Json             = "\"CityHall\":[]",
                    ExpectedEntity   = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                    })),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed - one entry",
                    Json             = "\"CityHall\":[{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}]",
                    ExpectedEntity   = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                    })),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed - multiple entries",
                    Json             =
                        "\"CityHall\":[" +
                        "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}," +
                        "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}," +
                        "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}" +
                        "]",
                    ExpectedEntity = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                    })),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed with custom annotation",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", "custom.annotation") + "\":null," +
                        "\"CityHall\":[{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}]",
                    ExpectedEntity = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                    })),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed with next link before - should fail",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataNextLinkAnnotationName) + "\":\"http://odata.org/nextlink\"," +
                        "\"CityHall\":[{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}]",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException(
                        "ODataJsonLightEntryAndFeedDeserializer_UnexpectedNavigationLinkInRequestPropertyAnnotation",
                        "CityHall",
                        JsonLightConstants.ODataNextLinkAnnotationName,
                        JsonLightConstants.ODataBindAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed with next link after - should fail",
                    Json             =
                        "\"CityHall\":[{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}]," +
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataNextLinkAnnotationName) + "\":\"http://odata.org/nextlink\"",
                    ExpectedEntity    = PayloadBuilder.Entity(),
                    ExpectedException = ODataExpectedExceptions.ODataException("ODataJsonLightPropertyAndValueDeserializer_UnexpectedPropertyAnnotation", "CityHall", JsonLightConstants.ODataNextLinkAnnotationName),
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded empty feed with binding link",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[\"http://odata.org/referencelink1\"]," +
                        "\"CityHall\":[]",
                    ExpectedEntity = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new LinkCollection(
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink1"
                    },
                                                                                                         new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                    }))),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded empty feed with binding links",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[" +
                        "\"http://odata.org/referencelink1\"," +
                        "\"http://odata.org/referencelink2\"," +
                        "\"http://odata.org/referencelink3\"" +
                        "]," +
                        "\"CityHall\":[]",
                    ExpectedEntity = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new LinkCollection(
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink1"
                    },
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink2"
                    },
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink3"
                    },
                                                                                                         new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                    }))),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
                new NavigationLinkTestCase
                {
                    DebugDescription = "Expanded feed with multiple entries and multiple binding links",
                    Json             =
                        "\"" + JsonLightUtils.GetPropertyAnnotationName("CityHall", JsonLightConstants.ODataBindAnnotationName) + "\":[" +
                        "\"http://odata.org/referencelink1\"," +
                        "\"http://odata.org/referencelink2\"," +
                        "\"http://odata.org/referencelink3\"" +
                        "]," +
                        "\"CityHall\":[" +
                        "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}," +
                        "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}," +
                        "{\"" + JsonLightConstants.ODataPropertyAnnotationSeparator + JsonLightConstants.ODataTypeAnnotationName + "\":\"TestModel.OfficeType\", \"Id\":1}" +
                        "]",
                    ExpectedEntity = PayloadBuilder.Entity().Property(new NavigationPropertyInstance("CityHall", new LinkCollection(
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink1"
                    },
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink2"
                    },
                                                                                                         new DeferredLink()
                    {
                        UriString = "http://odata.org/referencelink3"
                    },
                                                                                                         new ExpandedLink()
                    {
                        ExpandedElement = PayloadBuilder.EntitySet()
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                                          .Append(PayloadBuilder.Entity("TestModel.OfficeType").PrimitiveProperty("Id", 1))
                    }))),
                    ExpectedIsCollectionValues = new Dictionary <string, bool?> {
                        { "CityHall", true }
                    },
                },
            };

            this.RunNavigationLinkInRequestTest(testCases);
        }