Exemplo n.º 1
0
 /// <inheritdoc />
 public override object Read(
     ODataMessageReader messageReader,
     Type type,
     ODataDeserializerContext readContext)
 {
     return(enumDeserializer.Read(messageReader, type, readContext));
 }
Exemplo n.º 2
0
        public void ReadFromStreamAsync_ModelAlias()
        {
            // Arrange
            string content = "{\"@odata.type\":\"#NS.level\",\"value\":\"veryhigh\"}";

            var builder = ODataConventionModelBuilderFactory.Create();

            builder.EnumType <Level>().Namespace = "NS";
            IEdmModel model = builder.GetEdmModel();

            ODataEnumDeserializer    deserializer = new ODataEnumDeserializer();
            ODataDeserializerContext readContext  = new ODataDeserializerContext
            {
                Model        = model,
                ResourceType = typeof(Level)
            };

            // Act
            object value = deserializer.Read(ODataDeserializationTestsCommon.GetODataMessageReader(ODataDeserializationTestsCommon.GetODataMessage(content, new HttpRequestMessage(new HttpMethod("Post"), "http://localhost/OData/TestUri")), model),
                                             typeof(Level), readContext);

            // Assert
            Level level = Assert.IsType <Level>(value);

            Assert.Equal(Level.High, level);
        }
Exemplo n.º 3
0
        public void ReadFromStreamAsync_RawValue()
        {
            // Arrange
            string content = "{\"value\":\"Blue\"}";

            ODataEnumDeserializer    deserializer = new ODataEnumDeserializer();
            ODataDeserializerContext readContext  = new ODataDeserializerContext
            {
                Model        = _edmModel,
                ResourceType = typeof(Color)
            };

            // Act
            object value = deserializer.Read(ODataDeserializationTestsCommon.GetODataMessageReader(ODataDeserializationTestsCommon.GetODataMessage(content, new HttpRequestMessage(new HttpMethod("Post"), "http://localhost/OData/TestUri")), _edmModel),
                                             typeof(Color), readContext);

            // Assert
            Color color = Assert.IsType <Color>(value);

            Assert.Equal(Color.Blue, color);
        }
Exemplo n.º 4
0
        public void ReadFromStreamAsync()
        {
            // Arrange
            string content = "{\"@odata.type\":\"#NS.Color\",\"value\":\"Blue\"}";

            ODataEnumDeserializer    deserializer = new ODataEnumDeserializer();
            ODataDeserializerContext readContext  = new ODataDeserializerContext
            {
                Model        = _edmModel,
                ResourceType = typeof(Color)
            };

            // Act
            object value = deserializer.Read(GetODataMessageReader(GetODataMessage(content), _edmModel),
                                             typeof(Color), readContext);

            // Assert
            Color color = Assert.IsType <Color>(value);

            Assert.Equal(Color.Blue, color);
        }
        public void ReadFromStreamAsync_RawValue()
        {
            // Arrange
            string content = "{\"value\":\"Blue\"}";

            ODataEnumDeserializer    deserializer = new ODataEnumDeserializer();
            ODataDeserializerContext readContext  = new ODataDeserializerContext
            {
                Model        = _edmModel,
                ResourceType = typeof(Color)
            };
            HttpRequest request = RequestFactory.Create("Post", "http://localhost/OData/TestUri", _edmModel);

            // Act
            object value = deserializer.Read(ODataTestUtil.GetODataMessageReader(request.GetODataMessage(content), _edmModel),
                                             typeof(Color), readContext);

            // Assert
            Color color = Assert.IsType <Color>(value);

            Assert.Equal(Color.Blue, color);
        }
Exemplo n.º 6
0
        public void ReadFromStreamAsync_ForUnType()
        {
            // Arrange
            string content = "{\"@odata.type\":\"#NS.Color\",\"value\":\"Blue\"}";

            ODataEnumDeserializer    deserializer = new ODataEnumDeserializer();
            ODataDeserializerContext readContext  = new ODataDeserializerContext
            {
                Model        = _edmModel,
                ResourceType = typeof(IEdmEnumObject)
            };

            // Act
            object value = deserializer.Read(ODataDeserializationTestsCommon.GetODataMessageReader(ODataDeserializationTestsCommon.GetODataMessage(content, new HttpRequestMessage(new HttpMethod("Post"), "http://localhost/OData/TestUri")), _edmModel),
                                             typeof(Color), readContext);

            // Assert
            EdmEnumObject color = Assert.IsType <EdmEnumObject>(value);

            Assert.NotNull(color);

            Assert.Equal("Blue", color.Value);
        }