/// <inheritdoc/> public override void WriteObject(object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext) { if (messageWriter == null) { throw Error.ArgumentNull("messageWriter"); } if (graph == null) { throw Error.ArgumentNull("graph"); } if (graph.GetType().IsEnum) { messageWriter.WriteValue(graph.ToString()); } else { if (graph is DateTime) { messageWriter.WriteValue(ODataPrimitiveSerializer.ConvertUnsupportedDateTime((DateTime)graph, writeContext != null ? writeContext.TimeZoneInfo : null)); } else { messageWriter.WriteValue(ODataPrimitiveSerializer.ConvertUnsupportedPrimitives(graph)); } } }
public void ConvertUnsupportedDateTime_NonStandardEdmPrimitives(DateTime graph, DateTimeOffset result) { // Arrange & Act object value = ODataPrimitiveSerializer.ConvertUnsupportedDateTime(graph, timeZoneInfo: null); // Assert DateTimeOffset actual = Assert.IsType <DateTimeOffset>(value); Assert.Equal(new DateTimeOffset(graph), actual); }
public void ConvertUnsupportedDateTime_NonStandardEdmPrimitives_TimeZone(DateTime graph, DateTimeOffset result) { // Arrange TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); // Act object value = ODataPrimitiveSerializer.ConvertUnsupportedDateTime(graph, tzi); // Assert DateTimeOffset actual = Assert.IsType <DateTimeOffset>(value); Assert.Equal(result, actual); }