Пример #1
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);
        }
        public void ReadFromStreamAsync_RawPrimitive(string content, Type type, object expected)
        {
            // Arrange
            IEdmModel model = CreateModel();

            ODataPrimitiveDeserializer deserializer = new ODataPrimitiveDeserializer();
            ODataDeserializerContext   readContext  = new ODataDeserializerContext
            {
                Model        = model,
                ResourceType = type
            };

            // Act
            object value = deserializer.Read(ODataDeserializationTestsCommon.GetODataMessageReader(ODataDeserializationTestsCommon.GetODataMessage(content, new HttpRequestMessage(new HttpMethod("Patch"), "http://localhost/OData/Suppliers(1)/Address")), model), type, readContext);

            // Assert
            Assert.Equal(expected, value);
        }
Пример #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);
        }
        public void ReadFromStreamAsync_RawGuid()
        {
            // Arrange
            string content  = "{\"value\":\"f4b787c7-920d-4993-a584-ceb68968058c\"}";
            Type   type     = typeof(Guid);
            object expected = new Guid("f4b787c7-920d-4993-a584-ceb68968058c");

            IEdmModel model = CreateModel();

            ODataPrimitiveDeserializer deserializer = new ODataPrimitiveDeserializer();
            ODataDeserializerContext   readContext  = new ODataDeserializerContext
            {
                Model        = model,
                ResourceType = type
            };

            // Act
            object value = deserializer.Read(ODataDeserializationTestsCommon.GetODataMessageReader(ODataDeserializationTestsCommon.GetODataMessage(content, new HttpRequestMessage(new HttpMethod("Patch"), "http://localhost/OData/Suppliers(1)/Address")), model), type, readContext);

            // Assert
            Assert.Equal(expected, value);
        }
Пример #5
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);
        }