/// <summary> /// Writes a single top-level Uri in response to a $ref query. /// </summary> /// <param name="link">The entity reference link to write out.</param> internal void WriteEntityReferenceLink(ODataEntityReferenceLink link) { Debug.Assert(link != null, "link != null"); this.WriteTopLevelPayload( () => this.WriteEntityReferenceLinkImplementation(link, /* isTopLevel */ true)); }
public void InstanceAnnotationsPropertyShouldReturnAWritableCollectionAtCreation() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink(); referencelink.InstanceAnnotations.Should().NotBeNull(); referencelink.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestNamespace.name", new ODataPrimitiveValue("value"))); referencelink.InstanceAnnotations.Count.Should().Be(1); }
/// <summary> /// Writes a single Uri in response to a $ref query. /// </summary> /// <param name="entityReferenceLink">The entity reference link to write out.</param> internal void WriteEntityReferenceLink(ODataEntityReferenceLink entityReferenceLink) { Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null"); this.WritePayloadStart(); this.WriteEntityReferenceLink(entityReferenceLink, true); this.WritePayloadEnd(); }
/// <summary> /// Writes a single top-level Uri in response to a $links query. /// </summary> /// <param name="link">The entity reference link to write out.</param> internal void WriteEntityReferenceLink(ODataEntityReferenceLink link) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(link != null, "link != null"); this.WriteTopLevelPayload( () => this.WriteEntityReferenceLinkImplementation(link)); }
public void ShouldBeAbleToSetAndClearIdOnEntityReferenceLink() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink(); referencelink.Url.Should().BeNull(); referencelink.Url = new Uri("http://my/Id"); referencelink.Url.ToString().Should().Be("http://my/Id"); referencelink.Url = null; referencelink.Url.Should().BeNull(); }
/// <summary> /// Writes a single Uri in response to a $links query. /// </summary> /// <param name="entityReferenceLink">The entity reference link to write out.</param> private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink entityReferenceLink) { DebugUtils.CheckNoExternalCallers(); Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null"); WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink); this.JsonWriter.StartObjectScope(); this.JsonWriter.WriteName(JsonConstants.ODataUriName); this.JsonWriter.WriteValue(this.UriToAbsoluteUriString(entityReferenceLink.Url)); this.JsonWriter.EndObjectScope(); }
public void ShouldBeAbleToSetLinksReferenceLinks() { ODataEntityReferenceLink link = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(1)") }; ODataEntityReferenceLinks referencelinks = new ODataEntityReferenceLinks() { Links = new[] { link } }; referencelinks.Should().NotBeNull(); referencelinks.Links.Should().NotBeNull(); referencelinks.Links.Count().Should().Be(1); }
/// <summary> /// Writes a single Uri in response to a $ref query. /// </summary> /// <param name="entityReferenceLink">The entity reference link to write out.</param> /// <param name="isTopLevel">true if the entity reference link being written is at the top level of the payload.</param> private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel) { Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null"); WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink); this.JsonWriter.StartObjectScope(); if (isTopLevel) { this.WriteContextUriProperty(ODataPayloadKind.EntityReferenceLink); } this.JsonWriter.WriteInstanceAnnotationName(ODataAnnotationNames.ODataId); this.JsonWriter.WriteValue(this.UriToString(entityReferenceLink.Url)); this.JsonWriter.EndObjectScope(); }
public void EntityReferenceLinkTest() { ODataEntityReferenceLink entityReferenceLink1 = new ODataEntityReferenceLink { Url = new Uri("http://odata.org/linkresult") }; ODataEntityReferenceLink entityReferenceLink2 = new ODataEntityReferenceLink { Url = new Uri("relative", UriKind.Relative) }; ODataEntityReferenceLink entityReferenceLink3 = new ODataEntityReferenceLink { Url = new Uri("http://odata.org/linkresult") }; entityReferenceLink3.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestModel.unknown", new ODataPrimitiveValue(123))); entityReferenceLink3.InstanceAnnotations.Add(new ODataInstanceAnnotation("custom.name", new ODataPrimitiveValue(456))); ODataEntityReferenceLink entityReferenceLink4 = new ODataEntityReferenceLink { Url = new Uri("relative", UriKind.Relative) }; entityReferenceLink4.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestModel.unknown", new ODataPrimitiveValue(123))); entityReferenceLink4.InstanceAnnotations.Add(new ODataInstanceAnnotation("custom.name", new ODataPrimitiveValue(456))); ODataEntityReferenceLink[] resultLinks = new ODataEntityReferenceLink[] { entityReferenceLink1, entityReferenceLink2, entityReferenceLink3, entityReferenceLink4 }; 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); if (!testConfiguration.IsRequest) { testConfiguration.MessageWriterSettings.ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*"); } TestWriterUtils.WriteAndVerifyTopLevelContent( testDescriptor, testConfiguration, (messageWriter) => messageWriter.WriteEntityReferenceLink(testDescriptor.PayloadItems.Single()), this.Assert, baselineLogger: this.Logger); }); }
/// <summary> /// Writes a singleton result of a $ref query as the message payload. /// </summary> /// <param name="link">The entity reference link to write as message payload.</param> private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink link) { ODataJsonLightEntityReferenceLinkSerializer jsonLightEntityReferenceLinkSerializer = new ODataJsonLightEntityReferenceLinkSerializer(this); jsonLightEntityReferenceLinkSerializer.WriteEntityReferenceLink(link); }
/// <summary> /// Writes a singleton result of a $ref query as the message payload. /// </summary> /// <param name="link">The entity reference link to write as message payload.</param> /// <remarks>It is the responsibility of this method to flush the output before the method returns.</remarks> internal override void WriteEntityReferenceLink(ODataEntityReferenceLink link) { this.AssertSynchronous(); this.WriteEntityReferenceLinkImplementation(link); this.Flush(); }
/// <summary> /// Read an entity reference link. /// </summary> /// <returns>An instance of <see cref="ODataEntityReferenceLink"/> which was read.</returns> /// <remarks> /// Pre-Condition: XmlNodeType.Element - the 'm:ref' element to read. /// Post-Condition: Any - the node after the 'm:ref' element which was read. /// </remarks> private ODataEntityReferenceLink ReadEntityReferenceId() { Debug.Assert(this.XmlReader != null, "this.XmlReader != null"); this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert(this.XmlReader.NamespaceURI == this.XmlReader.ODataMetadataNamespace, "this.XmlReader.NamespaceURI == this.XmlReader.ODataMetadataNamespace"); Debug.Assert(this.XmlReader.LocalName == this.ODataRefElementName, "this.XmlReader.LocalName == this.ODataRefElementName"); ODataEntityReferenceLink link = new ODataEntityReferenceLink(); string uriString = this.XmlReader.GetAttribute(AtomConstants.AtomIdElementName); Debug.Assert(uriString != null, "In ATOM a entity reference id attribute on ref element can never represent a null value."); Uri xmlBaseUri = this.XmlReader.XmlBaseUri; Uri uri = this.ProcessUriFromPayload(uriString, xmlBaseUri); link.Url = uri; this.XmlReader.Skip(); ReaderValidationUtils.ValidateEntityReferenceLink(link); return link; }
/// <summary> /// Writes a singleton result of a $links query as the message payload. /// </summary> /// <param name="link">The entity reference link to write as message payload.</param> private void WriteEntityReferenceLinkImplementation(ODataEntityReferenceLink link) { ODataAtomEntityReferenceLinkSerializer atomEntityReferenceLinkSerializer = new ODataAtomEntityReferenceLinkSerializer(this); atomEntityReferenceLinkSerializer.WriteEntityReferenceLink(link); }
/// <summary> /// Read an entity reference link. /// </summary> /// <returns>An instance of <see cref="ODataEntityReferenceLink"/> which was read.</returns> /// <remarks> /// Pre-Condition: XmlNodeType.Element - the 'd:uri' element to read. /// Post-Condition: Any - the node after the 'd:uri' element which was read. /// </remarks> private ODataEntityReferenceLink ReadUriElement() { Debug.Assert(this.XmlReader != null, "this.XmlReader != null"); this.AssertXmlCondition(XmlNodeType.Element); Debug.Assert( this.XmlReader.NamespaceURI == this.XmlReader.ODataNamespace || this.XmlReader.NamespaceURI == this.XmlReader.ODataMetadataNamespace, "this.XmlReader.NamespaceURI == this.XmlReader.ODataNamespace || this.XmlReader.NamespaceURI == this.XmlReader.ODataMetadataNamespace"); Debug.Assert(this.XmlReader.LocalName == this.ODataUriElementName, "this.XmlReader.LocalName == this.ODataUriElementName"); ODataEntityReferenceLink link = new ODataEntityReferenceLink(); // NOTE: get the base URI here before we read the content as string; reading the content as string will move the // reader to the end element and thus we lose the xml:base definition on the element. Uri xmlBaseUri = this.XmlReader.XmlBaseUri; string uriString = this.XmlReader.ReadElementValue(); Debug.Assert(uriString != null, "In ATOM a URI element can never represent a null value."); Uri uri = this.ProcessUriFromPayload(uriString, xmlBaseUri); link.Url = uri; ReaderValidationUtils.ValidateEntityReferenceLink(link); return link; }
public void WriteForEntityReferenceLinkWithDuplicateAnnotationNameShouldThrow() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(1)") }; referencelink.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestNamespace.unknown", new ODataPrimitiveValue(123))); referencelink.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestNamespace.unknown", new ODataPrimitiveValue(456))); string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#$ref\",\"@odata.id\":\"http://host/Customers(1)\",\"@TestNamespace.unknown\":123,\"@TestNamespace.unknown\":456}"; Action writeResult = () => WriteAndValidate(referencelink, expectedPayload, writingResponse: false); writeResult.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.JsonLightInstanceAnnotationWriter_DuplicateAnnotationNameInCollection("TestNamespace.unknown")); writeResult = () => WriteAndValidate(referencelink, expectedPayload, writingResponse: true); writeResult.ShouldThrow<ODataException>().WithMessage(ODataErrorStrings.JsonLightInstanceAnnotationWriter_DuplicateAnnotationNameInCollection("TestNamespace.unknown")); }
public void ShouldWriteForEntityReferenceLinksWithMultpleLinks() { ODataEntityReferenceLink link1 = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(1)") }; link1.InstanceAnnotations.Add(new ODataInstanceAnnotation("Is.New", new ODataPrimitiveValue(true))); ODataEntityReferenceLink link2 = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(2)") }; link2.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestNamespace.unknown", new ODataPrimitiveValue(123))); link2.InstanceAnnotations.Add(new ODataInstanceAnnotation("custom.annotation", new ODataPrimitiveValue(456))); ODataEntityReferenceLinks referencelinks = new ODataEntityReferenceLinks() { Links = new[] { link1, link2 } }; string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#Collection($ref)\",\"value\":[{\"@odata.id\":\"http://host/Customers(1)\",\"@Is.New\":true},{\"@odata.id\":\"http://host/Customers(2)\",\"@TestNamespace.unknown\":123,\"@custom.annotation\":456}]}"; WriteAndValidate(referencelinks, expectedPayload, writingResponse: false); WriteAndValidate(referencelinks, expectedPayload, writingResponse: true); }
public void ShouldWriteForEntityReferenceLinksWithSingleLink() { ODataEntityReferenceLink link = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(1)") }; link.InstanceAnnotations.Add(new ODataInstanceAnnotation("Is.New", new ODataPrimitiveValue(true))); ODataEntityReferenceLinks referencelinks = new ODataEntityReferenceLinks() { Links = new[] { link } }; string expectedPayload = "{\"@odata.context\":\"http://odata.org/test/$metadata#Collection($ref)\",\"value\":[{\"@odata.id\":\"http://host/Customers(1)\",\"@Is.New\":true}]}"; WriteAndValidate(referencelinks, expectedPayload, writingResponse: false); WriteAndValidate(referencelinks, expectedPayload, writingResponse: true); }
public void SetNullValueToInstanceAnnotationsPropertyShouldThrow() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink(); Action test = () => referencelink.InstanceAnnotations = null; test.ShouldThrow<ArgumentException>().WithMessage("Value cannot be null.\r\nParameter name: value"); }
public void ShouldWriteForEntityReferenceLink() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(1)") }; referencelink.InstanceAnnotations.Add(new ODataInstanceAnnotation("Is.New", new ODataPrimitiveValue(true))); WriteAndValidate(referencelink, "{\"@odata.context\":\"http://odata.org/test/$metadata#$ref\",\"@odata.id\":\"http://host/Customers(1)\",\"@Is.New\":true}", writingResponse: false); WriteAndValidate(referencelink, "{\"@odata.context\":\"http://odata.org/test/$metadata#$ref\",\"@odata.id\":\"http://host/Customers(1)\",\"@Is.New\":true}", writingResponse: true); }
public void ShouldWriteAndReadForEntityReferenceLink() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink { Url = new Uri("http://host/Customers(1)") }; referencelink.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestNamespace.unknown", new ODataPrimitiveValue(123))); referencelink.InstanceAnnotations.Add(new ODataInstanceAnnotation("custom.annotation", new ODataPrimitiveValue(456))); string midplayoad = WriteToString(referencelink, writingResponse: false); var deserializer = this.CreateJsonLightEntryAndFeedDeserializer(midplayoad); ODataEntityReferenceLink link = deserializer.ReadEntityReferenceLink(); SameEntityReferenceLink(referencelink, link); }
/// <summary> /// Writes a singleton result of a $links query as the message payload. /// </summary> /// <param name="link">The entity reference link to write as message payload.</param> /// <remarks>It is the responsibility of this method to flush the output before the method returns.</remarks> internal override void WriteEntityReferenceLink(ODataEntityReferenceLink link) { DebugUtils.CheckNoExternalCallers(); this.AssertSynchronous(); this.WriteEntityReferenceLinkImplementation(link); this.Flush(); }
private static void SameEntityReferenceLink(ODataEntityReferenceLink link1, ODataEntityReferenceLink link2) { link1.Should().NotBeNull(); link2.Should().NotBeNull(); link1.Url.ToString().Should().Be(link2.Url.ToString()); link1.InstanceAnnotations.Count.Should().Equals(link2.InstanceAnnotations.Count); foreach (ODataInstanceAnnotation instanceannotation in link1.InstanceAnnotations) { TestUtils.AssertODataValueAreEqual(instanceannotation.Value, link2.InstanceAnnotations.Single(ia => ia.Name == instanceannotation.Name.ToString()).Value); } }
/// <summary> /// Writes a single Uri in response to a $ref query. /// </summary> /// <param name="entityReferenceLink">The entity reference link to write out.</param> /// <param name="isTopLevel"> /// A flag indicating whether the link is written as top-level element or not; /// this controls whether to include namespace declarations etc. /// </param> private void WriteEntityReferenceLink(ODataEntityReferenceLink entityReferenceLink, bool isTopLevel) { Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null"); WriterValidationUtils.ValidateEntityReferenceLink(entityReferenceLink); if (isTopLevel) { // <metadata:ref ... this.XmlWriter.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataRefElementName, AtomConstants.ODataMetadataNamespace); // metadata:context this.WriteContextUriProperty(this.contextUriBuilder.BuildContextUri(ODataPayloadKind.EntityReferenceLink)); } else { // <metadata:ref ... this.XmlWriter.WriteStartElement(AtomConstants.ODataMetadataNamespacePrefix, AtomConstants.ODataRefElementName, null); } this.XmlWriter.WriteAttributeString(AtomConstants.AtomIdElementName, null, this.UriToUrlAttributeValue(entityReferenceLink.Url)); // </uri> this.XmlWriter.WriteEndElement(); }
private static string WriteToString(ODataEntityReferenceLink referencelink, bool writingResponse = true, bool synchronous = true) { MemoryStream stream = new MemoryStream(); var outputContext = CreateJsonLightOutputContext(stream, writingResponse, synchronous); outputContext.WriteEntityReferenceLink(referencelink); stream.Seek(0, SeekOrigin.Begin); return (new StreamReader(stream)).ReadToEnd(); }
/// <summary> /// Creates a navigation link info for a singleton entity reference link. /// </summary> /// <param name="navigationLink">The navigation link to report.</param> /// <param name="navigationProperty">The navigation property for which the link will be reported.</param> /// <param name="entityReferenceLink">The entity reference link for the navigation link to report.</param> /// <param name="isExpanded">true if the navigation link is expanded.</param> /// <returns>The navigation link info created.</returns> internal static ODataJsonLightReaderNavigationLinkInfo CreateSingletonEntityReferenceLinkInfo( ODataNavigationLink navigationLink, IEdmNavigationProperty navigationProperty, ODataEntityReferenceLink entityReferenceLink, bool isExpanded) { Debug.Assert(navigationLink != null, "navigationLink != null"); Debug.Assert(navigationLink.IsCollection == false, "Singleton entity reference can only be reported for a singleton navigation links."); Debug.Assert(navigationProperty != null, "navigationProperty != null"); ODataJsonLightReaderNavigationLinkInfo navigationLinkInfo = new ODataJsonLightReaderNavigationLinkInfo(navigationLink, navigationProperty, isExpanded); if (entityReferenceLink != null) { navigationLinkInfo.entityReferenceLinks = new LinkedList<ODataEntityReferenceLink>(); navigationLinkInfo.entityReferenceLinks.AddFirst(entityReferenceLink); } return navigationLinkInfo; }
private static void WriteAndValidate(ODataEntityReferenceLink referencelink, string expectedPayload, bool writingResponse = true, bool synchronous = true) { string payload = WriteToString(referencelink, writingResponse, synchronous); payload.Should().Be(expectedPayload); }
/// <summary> /// Write an entity reference link. /// </summary> /// <param name="parentNavigationLink">The parent navigation link which is being written around the entity reference link.</param> /// <param name="entityReferenceLink">The entity reference link to write.</param> protected override void WriteEntityReferenceInNavigationLinkContent(ODataNavigationLink parentNavigationLink, ODataEntityReferenceLink entityReferenceLink) { Debug.Assert(parentNavigationLink != null, "parentNavigationLink != null"); Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null"); Debug.Assert(entityReferenceLink.Url != null, "We should have already verifies that the Url specified on the entity reference link is not null."); this.WriteNavigationLinkStart(parentNavigationLink, entityReferenceLink.Url); this.WriteNavigationLinkEnd(); }
/// <summary> /// Write an entity reference link. /// </summary> /// <param name="parentNavigationLink">The parent navigation link which is being written around the entity reference link.</param> /// <param name="entityReferenceLink">The entity reference link to write.</param> protected override void WriteEntityReferenceInNavigationLinkContent(ODataNavigationLink parentNavigationLink, ODataEntityReferenceLink entityReferenceLink) { Debug.Assert(parentNavigationLink != null, "parentNavigationLink != null"); Debug.Assert(entityReferenceLink != null, "entityReferenceLink != null"); Debug.Assert(!this.jsonLightOutputContext.WritingResponse, "Entity reference links are only supported in request, we should have verified this already."); // In JSON Light, we can only write entity reference links at the beginning of a navigation link in requests; // once we wrote a feed, entity reference links are not allowed anymore (we require all the entity reference // link to come first because of the grouping in the JSON Light wire format). JsonLightNavigationLinkScope navigationLinkScope = (JsonLightNavigationLinkScope)this.CurrentScope; if (navigationLinkScope.FeedWritten) { throw new ODataException(OData.Core.Strings.ODataJsonLightWriter_EntityReferenceLinkAfterFeedInRequest); } if (!navigationLinkScope.EntityReferenceLinkWritten) { // Write the property annotation for the entity reference link(s) this.odataAnnotationWriter.WritePropertyAnnotationName(parentNavigationLink.Name, ODataAnnotationNames.ODataBind); Debug.Assert(parentNavigationLink.IsCollection.HasValue, "parentNavigationLink.IsCollection.HasValue"); if (parentNavigationLink.IsCollection.Value) { this.jsonWriter.StartArrayScope(); } navigationLinkScope.EntityReferenceLinkWritten = true; } Debug.Assert(entityReferenceLink.Url != null, "The entity reference link Url should have been validated by now."); this.jsonWriter.WriteValue(this.jsonLightEntryAndFeedSerializer.UriToString(entityReferenceLink.Url)); }
/// <summary> /// Asynchronously writes a singleton result of a $ref query as the message payload. /// </summary> /// <param name="link">The link result to write as message payload.</param> /// <returns>A running task representing the writing of the link.</returns> /// <remarks>It is the responsibility of this method to flush the output before the task finishes.</remarks> internal override Task WriteEntityReferenceLinkAsync(ODataEntityReferenceLink link) { this.AssertAsynchronous(); return TaskUtils.GetTaskForSynchronousOperationReturningTask( () => { this.WriteEntityReferenceLinkImplementation(link); return this.FlushAsync(); }); }
public void EntityReferenceLinksTest() { string resultUri1String = "http://odata.org/linkresult1"; string resultUri2String = "linkresult2"; string resultUri3String = "http://odata.org/linkresult3"; ODataEntityReferenceLink entityReferenceLink1 = new ODataEntityReferenceLink { Url = new Uri(resultUri1String) }; ODataEntityReferenceLink entityReferenceLink2 = new ODataEntityReferenceLink { Url = new Uri(resultUri2String, UriKind.Relative) }; ODataEntityReferenceLink entityReferenceLink3 = new ODataEntityReferenceLink { Url = new Uri(resultUri3String) }; entityReferenceLink3.InstanceAnnotations.Add(new ODataInstanceAnnotation("TestModel.unknown", new ODataPrimitiveValue(123))); entityReferenceLink3.InstanceAnnotations.Add(new ODataInstanceAnnotation("custom.name", new ODataPrimitiveValue(456))); Uri nextPageLink = new Uri("http://odata.org/nextpage"); Uri relativeNextPageLink = new Uri("relative-nextpage", UriKind.Relative); long?[] inputCounts = new long?[] { null, 1, 3, -1, -3, 0, long.MaxValue, long.MinValue }; Uri[] inputNextLinks = new Uri[] { nextPageLink, relativeNextPageLink, null }; ODataInstanceAnnotation[][] inputAnnotations = new ODataInstanceAnnotation[][] { new ODataInstanceAnnotation[0], new ODataInstanceAnnotation[] { new ODataInstanceAnnotation("TestModel.annotation", new ODataPrimitiveValue(321)), new ODataInstanceAnnotation("custom.annotation", new ODataPrimitiveValue(654)) } }; ODataEntityReferenceLink[][] inputReferenceLinks = new ODataEntityReferenceLink[][] { new ODataEntityReferenceLink[] { entityReferenceLink1, entityReferenceLink2, entityReferenceLink3 }, new ODataEntityReferenceLink[] { entityReferenceLink1, entityReferenceLink3 }, new ODataEntityReferenceLink[] { entityReferenceLink1 }, new ODataEntityReferenceLink[0], null }; var testCases = inputCounts.SelectMany( inputCount => inputNextLinks.SelectMany( inputNextLink => inputReferenceLinks.Select( (inputReferenceLink, index) => new ODataEntityReferenceLinks { Count = inputCount, Links = inputReferenceLink, NextPageLink = inputNextLink, InstanceAnnotations = inputAnnotations[index == 1 ? 1 : 0] }))); var testDescriptors = testCases.Select( testCase => new PayloadWriterTestDescriptor <ODataEntityReferenceLinks>(this.Settings, testCase, this.CreateExpectedCallback(testCase, /*forceNextLinkAndCountAtEnd*/ false))); // TODO: also cover the cases in protocol v1 (errors for inline count and next page link; different format for JSON) this.CombinatorialEngineProvider.RunCombinations( testDescriptors, this.WriterTestConfigurationProvider.ExplicitFormatConfigurationsWithIndent, (testDescriptor, testConfiguration) => { ODataEntityReferenceLinks entityReferenceLinks = testDescriptor.PayloadItems.Single(); testConfiguration = testConfiguration.Clone(); testConfiguration.MessageWriterSettings.SetServiceDocumentUri(ServiceDocumentUri); if (!testConfiguration.IsRequest) { testConfiguration.MessageWriterSettings.ShouldIncludeAnnotation = ODataUtils.CreateAnnotationFilter("*"); } // 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(); } TestWriterUtils.WriteAndVerifyTopLevelContent( testDescriptor, testConfiguration, (messageWriter) => messageWriter.WriteEntityReferenceLinks(entityReferenceLinks), this.Assert, baselineLogger: this.Logger); }); }
public void InstanceAnnotationsPropertyShouldNotBeNullAtCreation() { ODataEntityReferenceLink referencelink = new ODataEntityReferenceLink(); referencelink.InstanceAnnotations.Should().NotBeNull(); referencelink.InstanceAnnotations.Count.Should().Be(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); }); }
protected override void WriteEntityReferenceInNavigationLinkContent(ODataNavigationLink parentNavigationLink, ODataEntityReferenceLink entityReferenceLink) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of <see cref="ODataEntityReferenceLinkWrapper"/>. /// </summary> /// <param name="link">The wrapped entity reference item.</param> public ODataEntityReferenceLinkWrapper(ODataEntityReferenceLink link) { EntityReferenceLink = link; }