/// <inheritdoc /> public override object Read( ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext) { return(enumDeserializer.Read(messageReader, type, readContext)); }
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); }
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); }
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); }
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); }