Exemplo n.º 1
0
        public void SerializesReturnedCountValue()
        {
            // Arrange
            var    serializer  = new ODataRawValueSerializer();
            var    mockRequest = new Mock <IODataRequestMessage>();
            Stream stream      = new MemoryStream();

            mockRequest.Setup(r => r.GetStream()).Returns(stream);
            var messageWriter = new ODataMessageWriter(mockRequest.Object);
            var request       = RequestFactory.Create();

            request.ODataContext().Path = new ODataPath(CountSegment.Instance);
            var context = new ODataSerializerContext {
                Request = request
            };

            // Act
            serializer.WriteObject(5, null, messageWriter, context);
            stream.Seek(0, SeekOrigin.Begin);
            TextReader reader = new StreamReader(stream);
            string     result = reader.ReadToEnd();

            // Assert
            Assert.Equal("5", result);
        }
Exemplo n.º 2
0
        public void SerializesNullablePrimitiveTypes()
        {
            int?value = 5;
            ODataRawValueSerializer     serializer  = new ODataRawValueSerializer();
            Mock <IODataRequestMessage> mockRequest = new Mock <IODataRequestMessage>();
            Stream stream = new MemoryStream();

            mockRequest.Setup(r => r.GetStream()).Returns(stream);
            ODataMessageWriter messageWriter = new ODataMessageWriter(mockRequest.Object);

            serializer.WriteObject(value, value.GetType(), messageWriter, null);
            stream.Seek(0, SeekOrigin.Begin);
            TextReader reader = new StreamReader(stream);

            Assert.Equal(value.ToString(), reader.ReadToEnd());
        }
Exemplo n.º 3
0
        public void SerializesEnumType()
        {
            ODataRawValueSerializer     serializer  = new ODataRawValueSerializer();
            Mock <IODataRequestMessage> mockRequest = new Mock <IODataRequestMessage>();
            Stream stream = new MemoryStream();

            mockRequest.Setup(r => r.GetStream()).Returns(stream);
            ODataMessageWriter messageWriter = new ODataMessageWriter(mockRequest.Object);
            object             value         = Color.Red | Color.Blue;

            serializer.WriteObject(value, value.GetType(), messageWriter, null);
            stream.Seek(0, SeekOrigin.Begin);
            TextReader reader = new StreamReader(stream);
            string     result = reader.ReadToEnd();

            Assert.Equal(value.ToString(), result, ignoreCase: true);
        }
Exemplo n.º 4
0
        public void SerializesDateTimeTypes(object value, DateTimeOffset expect)
        {
            // Arrange
            ODataRawValueSerializer     serializer  = new ODataRawValueSerializer();
            Mock <IODataRequestMessage> mockRequest = new Mock <IODataRequestMessage>();
            Stream stream = new MemoryStream();

            mockRequest.Setup(r => r.GetStream()).Returns(stream);
            ODataMessageWriter messageWriter = new ODataMessageWriter(mockRequest.Object);

            // Act
            serializer.WriteObject(value, value.GetType(), messageWriter, null);
            stream.Seek(0, SeekOrigin.Begin);
            TextReader reader = new StreamReader(stream);

            // Assert
            Assert.Equal(expect, DateTimeOffset.Parse(reader.ReadToEnd()));
        }