public void ShouldReadEntityReferenceNextLinkAnnotationValue()
        {
            string payload = @"{
                ""@odata.context"":""http://odata.org/test/$metadata#Collection($ref)"",
                ""@odata.nextLink"":""http://odata.org/nextpage"",
                ""@TestNamespace.name"":321,
                ""@custom.name"":654,
                ""value"":[]
            }";

            ODataJsonLightEntityReferenceLinkDeserializer deserializer =
                this.CreateJsonLightEntryAndFeedDeserializer(payload);

            ODataEntityReferenceLinks links = deserializer.ReadEntityReferenceLinks();

            Assert.Equal(new Uri("http://odata.org/nextpage"), links.NextPageLink);
        }
        private async Task SetupJsonLightEntityReferenceLinkDeserializerAndRunTestAsync(
            string payload,
            Func <ODataJsonLightEntityReferenceLinkDeserializer, Task> func,
            bool isResponse = false)
        {
            using (var jsonInputContext = CreateJsonLightInputContext(
                       payload,
                       this.model,
                       isIeee754Compatible: false,
                       isAsync: true,
                       isResponse: isResponse))
            {
                var jsonLightEntityReferenceLinkDeserializer = new ODataJsonLightEntityReferenceLinkDeserializer(jsonInputContext);

                await func(jsonLightEntityReferenceLinkDeserializer);
            }
        }
        public void ReadEntityReferenceLinks_ThrowsExceptionForInvalidPropertyAnnotationInEntityReferenceLinks()
        {
            var payload = "{\"@odata.context\":\"http://tempuri.org/$metadata#Collection($ref)\"," +
                          "\"[email protected]\":\"foobar\"}";

            using (var jsonInputContext = CreateJsonLightInputContext(
                       payload,
                       this.model))
            {
                var jsonLightEntityReferenceLinkDeserializer = new ODataJsonLightEntityReferenceLinkDeserializer(jsonInputContext);

                var exception = Assert.Throws <ODataException>(
                    () => jsonLightEntityReferenceLinkDeserializer.ReadEntityReferenceLinks());

                Assert.Equal(
                    ODataErrorStrings.ODataJsonLightEntityReferenceLinkDeserializer_InvalidPropertyAnnotationInEntityReferenceLinks("value"),
                    exception.Message);
            }
        }
        public void ShouldReadEntityReferenceCountAnnotationValue()
        {
            string payload = @"{
                ""@odata.count"":2,
                ""@odata.context"":""http://odata.org/test/$metadata#Collection($ref)"",
                ""@TestNamespace.name"":321,
                ""@custom.name"":654,
                ""value"":[
                    {""@odata.id"":""http://host/Customers(1)"",""@Is.New"":true},
                    {""@odata.id"":""http://host/Customers(2)"",""@TestNamespace.unknown"":123,""@custom.annotation"":456}
                ]
            }";

            ODataJsonLightEntityReferenceLinkDeserializer deserializer =
                this.CreateJsonLightEntryAndFeedDeserializer(payload);

            ODataEntityReferenceLinks links = deserializer.ReadEntityReferenceLinks();

            Assert.Equal(2, links.Count);
        }
        public void ReadEntityReferenceLink_ThrowsExceptionForInvalidPropertyOrAnnotationInEntityReferenceLink(string invalidPart)
        {
            var payload = "{\"@odata.context\":\"http://tempuri.org/$metadata#$ref\"," +
                          "\"@odata.id\":\"http://tempuri.org/Orders(1)\"," +
                          $"{invalidPart}}}";

            using (var jsonInputContext = CreateJsonLightInputContext(
                       payload,
                       this.model))
            {
                var jsonLightEntityReferenceLinkDeserializer = new ODataJsonLightEntityReferenceLinkDeserializer(jsonInputContext);

                var exception = Assert.Throws <ODataException>(
                    () => jsonLightEntityReferenceLinkDeserializer.ReadEntityReferenceLink());

                Assert.Equal(
                    ODataErrorStrings.ODataJsonLightEntityReferenceLinkDeserializer_InvalidAnnotationInEntityReferenceLink("UnexpectedProp"),
                    exception.Message);
            }
        }