public void WriteObject_Throws_RootElementNameMissing() { ODataSerializerContext writeContext = new ODataSerializerContext(); ODataPrimitiveSerializer serializer = new ODataPrimitiveSerializer(); Assert.Throws <ArgumentException>( () => serializer.WriteObject(42, typeof(int), ODataTestUtil.GetMockODataMessageWriter(), writeContext), "The 'RootElementName' property is required on 'ODataSerializerContext'.\r\nParameter name: writeContext"); }
public void WriteObject_Throws_RootElementNameMissing() { ODataSerializerContext writeContext = new ODataSerializerContext(); ODataPrimitiveSerializer serializer = new ODataPrimitiveSerializer(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true)); Assert.Throws <ArgumentException>( () => serializer.WriteObject(42, ODataTestUtil.GetMockODataMessageWriter(), writeContext), "The 'RootElementName' property is required on 'ODataSerializerContext'.\r\nParameter name: writeContext"); }
public void WriteObject_EdmPrimitives(object graph) { IEdmPrimitiveTypeReference edmPrimitiveType = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(int)); var serializer = new ODataPrimitiveSerializer(edmPrimitiveType); ODataMessageWriter writer = new ODataMessageWriter(new ODataMessageWrapper(new MemoryStream()) as IODataResponseMessage); Assert.DoesNotThrow(() => serializer.WriteObject(graph, writer, new ODataSerializerContext() { ServiceOperationName = "PropertyName" })); }
public void WriteObject_EdmPrimitives(object graph) { IEdmPrimitiveTypeReference edmPrimitiveType = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(int)); var serializer = new ODataPrimitiveSerializer(); ODataSerializerContext writecontext = new ODataSerializerContext() { RootElementName = "PropertyName", Model = EdmCoreModel.Instance }; ODataMessageWriter writer = new ODataMessageWriter(new ODataMessageWrapper(new MemoryStream()) as IODataResponseMessage); Assert.DoesNotThrow(() => serializer.WriteObject(graph, typeof(int), writer, writecontext)); }
public void Read_Primitive(object obj) { // Arrange IEdmPrimitiveTypeReference primitive = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(int)); ODataPrimitiveSerializer serializer = new ODataPrimitiveSerializer(primitive); ODataPrimitiveDeserializer deserializer = new ODataPrimitiveDeserializer(primitive); MemoryStream stream = new MemoryStream(); ODataMessageWrapper message = new ODataMessageWrapper(stream); serializer.WriteObject( obj, new ODataMessageWriter(message as IODataResponseMessage, new ODataMessageWriterSettings(), EdmCoreModel.Instance), new ODataSerializerContext { RootElementName = "Property" }); stream.Seek(0, SeekOrigin.Begin); Assert.Equal( obj, deserializer.Read( new ODataMessageReader(message as IODataResponseMessage, new ODataMessageReaderSettings(), EdmCoreModel.Instance), new ODataDeserializerContext())); }
public void WriteObject_Throws_RootElementNameMissing() { ODataSerializerContext writeContext = new ODataSerializerContext(); ODataPrimitiveSerializer serializer = new ODataPrimitiveSerializer(); Assert.Throws<ArgumentException>( () => serializer.WriteObject(42, typeof(int), ODataTestUtil.GetMockODataMessageWriter(), writeContext), "The 'RootElementName' property is required on 'ODataSerializerContext'.\r\nParameter name: writeContext"); }
public void WriteObject_Throws_RootElementNameMissing() { ODataSerializerContext writeContext = new ODataSerializerContext(); ODataPrimitiveSerializer serializer = new ODataPrimitiveSerializer(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int32, isNullable: true)); Assert.Throws<ArgumentException>( () => serializer.WriteObject(42, ODataTestUtil.GetMockODataMessageWriter(), writeContext), "The 'RootElementName' property is required on 'ODataSerializerContext'.\r\nParameter name: writeContext"); }
public void Read_MappedPrimitive(object obj, object expected) { // Arrange IEdmPrimitiveTypeReference primitive = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(int)); IEdmModel model = EdmCoreModel.Instance; ODataPrimitiveSerializer serializer = new ODataPrimitiveSerializer(); ODataPrimitiveDeserializer deserializer = new ODataPrimitiveDeserializer(); MemoryStream stream = new MemoryStream(); ODataMessageWrapper message = new ODataMessageWrapper(stream); ODataMessageWriter messageWriter = new ODataMessageWriter(message as IODataResponseMessage, new ODataMessageWriterSettings(), model); ODataMessageReader messageReader = new ODataMessageReader(message as IODataResponseMessage, new ODataMessageReaderSettings(), model); ODataSerializerContext writeContext = new ODataSerializerContext { RootElementName = "Property", Model = model }; ODataDeserializerContext readContext = new ODataDeserializerContext { Model = model }; serializer.WriteObject(obj, typeof(int), messageWriter, writeContext); stream.Seek(0, SeekOrigin.Begin); // Act && Assert Assert.Equal(expected, deserializer.Read(messageReader, typeof(int), readContext)); }