public void WriteObject_ThrowsArgumentNull_WriteContext() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); Assert.ThrowsArgumentNull( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: null), "writeContext"); }
public void ODataEntityReferenceLinkSerializer_Serializes_UrisAndEntityReferenceLinks_Json(object uris) { // Arrange ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First(); ODataPath path = new ODataPath(new EntitySetPathSegment(_customerSet), new KeyValuePathSegment("1"), new NavigationPathSegment(navigationProperty)); ODataSerializerContext writeContext = new ODataSerializerContext { Path = path }; MemoryStream stream = new MemoryStream(); IODataResponseMessage message = new ODataMessageWrapper(stream); ODataMessageWriterSettings settings = new ODataMessageWriterSettings { BaseUri = new Uri("http://any/") }; settings.SetMetadataDocumentUri(new Uri("http://any/$metadata")); settings.SetContentType(ODataFormat.Json); // Act serializer.WriteObject(uris, typeof(ODataEntityReferenceLinks), new ODataMessageWriter(message, settings), writeContext); stream.Seek(0, SeekOrigin.Begin); string result = new StreamReader(stream).ReadToEnd(); // Assert Assert.Equal( string.Format("{0},{1}", "{\"odata.metadata\":\"http://any/$metadata#Default.Container.Customers/$links/Orders\"", "\"value\":[{\"url\":\"http://uri1/\"},{\"url\":\"http://uri2/\"}]}"), result); }
public void WriteObject_ThrowsArgumentNull_MessageWriter() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); Assert.ThrowsArgumentNull( () => serializer.WriteObject(graph: null, messageWriter: null, writeContext: new ODataSerializerContext()), "messageWriter"); }
public void ODataEntityReferenceLinkSerializer_Serializes_UrisAndEntityReferenceLinks_WithCount(object uris) { // Arrange ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First(); ODataPath path = new ODataPath(new EntitySetPathSegment(_customerSet), new NavigationPathSegment(navigationProperty)); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = path }; MemoryStream stream = new MemoryStream(); writeContext.Request = new HttpRequestMessage(); writeContext.Request.ODataProperties().TotalCount = 1; IODataResponseMessage message = new ODataMessageWrapper(stream); // Act serializer.WriteObject(uris, typeof(ODataEntityReferenceLinks), new ODataMessageWriter(message), writeContext); // Assert stream.Seek(0, SeekOrigin.Begin); XElement element = XElement.Load(stream); Assert.Equal(2, element.Elements().Count()); Assert.Equal("1", element.Elements().ElementAt(0).Value); Assert.Equal("http://uri1/", element.Elements().ElementAt(1).Value); }
public void WriteObject_Throws_EntitySetMissingDuringSerialization() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataSerializerContext writeContext = new ODataSerializerContext(); Assert.Throws <SerializationException>( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The related entity set could not be found from the OData path. The related entity set is required to serialize the payload."); }
public void WriteObject_Throws_EntitySetMissingDuringSerialization() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataSerializerContext writeContext = new ODataSerializerContext(); Assert.Throws<SerializationException>( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The related entity set could not be found from the OData path. The related entity set is required to serialize the payload."); }
public void WriteObject_Throws_ODataPathMissing() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet }; Assert.Throws<SerializationException>( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The operation cannot be completed because no ODataPath is available for the request."); }
public void WriteObject_Throws_NavigationPropertyMissingDuringSerialization() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = new ODataPath() }; Assert.Throws<SerializationException>( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The related navigation property could not be found from the OData path. The related navigation property is required to serialize the payload."); }
public void WriteObject_Throws_ODataPathMissing() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet }; Assert.Throws <SerializationException>( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The operation cannot be completed because no ODataPath is available for the request."); }
public void WriteObject_Throws_NavigationPropertyMissingDuringSerialization() { ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = new ODataPath() }; Assert.Throws <SerializationException>( () => serializer.WriteObject(graph: null, messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The related navigation property could not be found from the OData path. The related navigation property is required to serialize the payload."); }
public void WriteObject_Throws_ObjectCannotBeWritten_IfGraphIsNotUri() { IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First(); ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty)); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = path }; Assert.Throws<SerializationException>( () => serializer.WriteObject(graph: "not uri", messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "ODataEntityReferenceLinksSerializer cannot write an object of type 'System.String'."); }
public void WriteObject_Throws_NavigationPropertyMissingDuringSerialization() { // Arrange ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataPath path = new ODataPath(new EntitySetPathSegment(_customerSet)); ODataSerializerContext writeContext = new ODataSerializerContext { Path = path }; // Act & Assert Assert.Throws<SerializationException>( () => serializer.WriteObject(graph: null, type: typeof(ODataEntityReferenceLinks), messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The related navigation property could not be found from the OData path. The related navigation property is required to serialize the payload."); }
public void WriteObject_Throws_ObjectCannotBeWritten_IfGraphIsNotUri() { IEdmNavigationProperty navigationProperty = _customerSet.ElementType.NavigationProperties().First(); ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataPath path = new ODataPath(new NavigationPathSegment(navigationProperty)); ODataSerializerContext writeContext = new ODataSerializerContext { EntitySet = _customerSet, Path = path }; Assert.Throws <SerializationException>( () => serializer.WriteObject(graph: "not uri", messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "ODataEntityReferenceLinksSerializer cannot write an object of type 'System.String'."); }
public void WriteObject_Throws_NavigationPropertyMissingDuringSerialization() { // Arrange ODataEntityReferenceLinksSerializer serializer = new ODataEntityReferenceLinksSerializer(); ODataPath path = new ODataPath(new EntitySetPathSegment(_customerSet)); ODataSerializerContext writeContext = new ODataSerializerContext { Path = path }; // Act & Assert Assert.Throws <SerializationException>( () => serializer.WriteObject(graph: null, type: typeof(ODataEntityReferenceLinks), messageWriter: ODataTestUtil.GetMockODataMessageWriter(), writeContext: writeContext), "The related navigation property could not be found from the OData path. The related navigation property is required to serialize the payload."); }