public async Task SerializesReturnedCountValue() { // Arrange var serializer = new ODataRawValueSerializer(); var mockRequest = new Mock <IODataRequestMessageAsync>(); Stream stream = new MemoryStream(); mockRequest.Setup(r => r.GetStreamAsync()).ReturnsAsync(stream); var messageWriter = new ODataMessageWriter(mockRequest.Object); HttpRequest request = RequestFactory.Create(opt => opt.AddRouteComponents(EdmCoreModel.Instance)); request.ODataFeature().Path = new ODataPath(CountSegment.Instance); var context = new ODataSerializerContext { Request = request }; // Act await serializer.WriteObjectAsync(5, null, messageWriter, context); stream.Seek(0, SeekOrigin.Begin); TextReader reader = new StreamReader(stream); string result = await reader.ReadToEndAsync(); // Assert Assert.Equal("5", result); }
public async Task SerializesDateTimeTypes(object value, DateTimeOffset expect) { // Arrange ODataRawValueSerializer serializer = new ODataRawValueSerializer(); Mock <IODataRequestMessageAsync> mockRequest = new Mock <IODataRequestMessageAsync>(); Stream stream = new MemoryStream(); mockRequest.Setup(r => r.GetStreamAsync()).ReturnsAsync(stream); ODataMessageWriter messageWriter = new ODataMessageWriter(mockRequest.Object); // Act await serializer.WriteObjectAsync(value, value.GetType(), messageWriter, null); stream.Seek(0, SeekOrigin.Begin); TextReader reader = new StreamReader(stream); // Assert Assert.Equal(expect, DateTimeOffset.Parse(await reader.ReadToEndAsync())); }
public async Task SerializesNullablePrimitiveTypes() { // Arrange int?value = 5; ODataRawValueSerializer serializer = new ODataRawValueSerializer(); Mock <IODataRequestMessageAsync> mockRequest = new Mock <IODataRequestMessageAsync>(); Stream stream = new MemoryStream(); mockRequest.Setup(r => r.GetStreamAsync()).ReturnsAsync(stream); ODataMessageWriter messageWriter = new ODataMessageWriter(mockRequest.Object); // Act await serializer.WriteObjectAsync(value, value.GetType(), messageWriter, null); stream.Seek(0, SeekOrigin.Begin); TextReader reader = new StreamReader(stream); // Assert Assert.Equal(value.ToString(), await reader.ReadToEndAsync()); }
public async Task SerializesEnumType() { // Arrange ODataRawValueSerializer serializer = new ODataRawValueSerializer(); Mock <IODataRequestMessageAsync> mockRequest = new Mock <IODataRequestMessageAsync>(); Stream stream = new MemoryStream(); mockRequest.Setup(r => r.GetStreamAsync()).ReturnsAsync(stream); ODataMessageWriter messageWriter = new ODataMessageWriter(mockRequest.Object); object value = Color.Red | Color.Blue; // Act await serializer.WriteObjectAsync(value, value.GetType(), messageWriter, null); stream.Seek(0, SeekOrigin.Begin); TextReader reader = new StreamReader(stream); string result = await reader.ReadToEndAsync(); // Assert Assert.Equal(value.ToString(), result, ignoreCase: true); }