コード例 #1
0
        public async Task ReadFromStreamAsync_ModelAlias()
        {
            // Arrange
            string content = "{\"@odata.type\":\"#NS.level\",\"value\":\"veryhigh\"}";

            var builder = new ODataConventionModelBuilder();

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

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

            HttpRequest request = RequestFactory.Create("Post", "http://localhost/", _edmModel);

            // Act
            object value = await deserializer.ReadAsync(ODataTestUtil.GetODataMessageReader(request.GetODataMessage(content), model),
                                                        typeof(Level), readContext);

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

            Assert.Equal(Level.High, level);
        }
コード例 #2
0
        public async Task 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/", _edmModel);

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

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

            Assert.Equal(Color.Blue, color);
        }
コード例 #3
0
        public async Task ReadFromStreamAsync_ForUnType()
        {
            // Arrange
            string content = "{\"@odata.type\":\"#NS.Color\",\"value\":\"Blue\"}";

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

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

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

            Assert.NotNull(color);

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