Ejemplo n.º 1
0
        public void EntityReferenceLinkTest()
        {
            ODataEntityReferenceLink[] resultLinks = new ODataEntityReferenceLink[]
            {
                new ODataEntityReferenceLink {
                    Url = new Uri("http://odata.org/linkresult")
                },
                new ODataEntityReferenceLink {
                    Url = new Uri("relative", UriKind.Relative)
                },
            };

            this.CombinatorialEngineProvider.RunCombinations(
                resultLinks,
                TestWriterUtils.ODataBehaviorKinds,
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent,
                (resultLink, behaviorKind, testConfiguration) =>
            {
                bool expectMetadataNamespace = false;
                PayloadWriterTestDescriptor <ODataEntityReferenceLink> testDescriptor =
                    new PayloadWriterTestDescriptor <ODataEntityReferenceLink>(
                        this.Settings,
                        resultLink,
                        CreateExpectedCallback(resultLink, expectMetadataNamespace, "http://odata.org/test/$metadata#$ref"));

                // When writing JSON lite, always provide a model and a non-null nav prop.
                // The error cases when a model isn't provided or the nav prop is null are tested in JsonLightEntityReferenceLinkWriterTests
                if (testConfiguration.Format == ODataFormat.Json)
                {
                    testDescriptor.Model = CreateModelWithNavProps();
                    var model            = testDescriptor.GetMetadataProvider();
                }

                testConfiguration = testConfiguration.CloneAndApplyBehavior(behaviorKind);
                testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                TestWriterUtils.WriteAndVerifyTopLevelContent(
                    testDescriptor,
                    testConfiguration,
                    (messageWriter) => messageWriter.WriteEntityReferenceLink(testDescriptor.PayloadItems.Single()),
                    this.Assert,
                    baselineLogger: this.Logger);
            });
        }
Ejemplo n.º 2
0
        public void EntityReferenceLinksPropertyAccessOrderTest()
        {
            //// NOTE: this tests is important as Astoria relies on this behavior. Astoria only provides a next link after all the entity reference
            ////       links have been written so we must not access the next link before that point.

            ODataEntityReferenceLink entityReferenceLink1 = new ODataEntityReferenceLink {
                Url = new Uri("http://odata.org/linkresult1")
            };
            ODataEntityReferenceLink entityReferenceLink2 = new ODataEntityReferenceLink {
                Url = new Uri("http://odata.org/linkresult2")
            };
            ODataEntityReferenceLink entityReferenceLink3 = new ODataEntityReferenceLink {
                Url = new Uri("http://odata.org/linkresult3")
            };

            Uri  nextPageLink          = new Uri("http://odata.org/nextpage");
            Uri  incorrectNextPageLink = new Uri("http://odata.org/incorrectnextpage");
            long correctCountValue     = 3;

            // the expected result instance
            ODataEntityReferenceLinks expectedResult = new ODataEntityReferenceLinks
            {
                Count        = 3,
                Links        = new ODataEntityReferenceLink[] { entityReferenceLink1, entityReferenceLink2, entityReferenceLink3 },
                NextPageLink = nextPageLink
            };

            PayloadWriterTestDescriptor.WriterTestExpectedResultCallback expectedResultCallback = this.CreateExpectedCallback(expectedResult, /*forceNextLinkAndCountAtEnd*/ true);

            this.CombinatorialEngineProvider.RunCombinations(
                this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent.Where(tc => !tc.IsRequest),
                (testConfiguration) =>
            {
                testConfiguration = testConfiguration.Clone();
                testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri);

                // The instance with the proper inline count set but an incorrect next link; as we enumerate the links themselves
                // we will invalidate the inline count and set the correct next link to guarantee the correct order of property accesses
                // NOTE: we need to create this new for each iteration since the checking enumerable can (intentionally) only be enumerated once.
                ODataEntityReferenceLinks testReferenceLink = new ODataEntityReferenceLinks
                {
                    Count = correctCountValue,
                    // In JSON lite, we will write the next link first if one is available.  Otherwise, we'll write it at the end.
                    NextPageLink = testConfiguration.Format == ODataFormat.Json ? null : incorrectNextPageLink
                };
                testReferenceLink.Links = new CheckingEntityReferenceLinkEnumerable(
                    testReferenceLink,
                    correctCountValue,
                    nextPageLink /* correct next link */,
                    entityReferenceLink1,
                    entityReferenceLink2,
                    entityReferenceLink3);

                PayloadWriterTestDescriptor <ODataEntityReferenceLinks> testDescriptor =
                    new PayloadWriterTestDescriptor <ODataEntityReferenceLinks>(this.Settings, testReferenceLink, expectedResultCallback);

                IEdmNavigationProperty navProp = null;
                IEdmEntitySet entitySet        = null;
                // When writing JSON lite, always provide a model and a non-null nav prop.
                // The error cases when a model isn't provided or the nav prop is null are tested in JsonLightEntityReferenceLinkWriterTests
                if (testConfiguration.Format == ODataFormat.Json)
                {
                    testDescriptor.Model = CreateModelWithNavProps();
                    var edmModel         = testDescriptor.GetMetadataProvider();
                    navProp   = GetCollectionNavProp(edmModel);
                    entitySet = GetCollectionEntitySet(edmModel);
                }

                ODataEntityReferenceLinks entityReferenceLinks = testDescriptor.PayloadItems.Single();

                TestWriterUtils.WriteAndVerifyTopLevelContent(
                    testDescriptor,
                    testConfiguration,
                    (messageWriter) => messageWriter.WriteEntityReferenceLinks(entityReferenceLinks),
                    this.Assert,
                    baselineLogger: this.Logger);
            });
        }