public void ReadInline_ReturnsNull_IfItemIsNull()
        {
            // Arrange
            var deserializer = new ODataResourceSetDeserializer(_deserializerProvider);

            // Act & Assert
            Assert.Null(deserializer.ReadInline(item: null, edmType: _customersType, readContext: new ODataDeserializerContext()));
        }
예제 #2
0
        public void ReadInline_Throws_ArgumentMustBeOfType()
        {
            var deserializer = new ODataResourceSetDeserializer(_deserializerProvider);

            ExceptionAssert.ThrowsArgument(
                () => deserializer.ReadInline(item: 42, edmType: _customersType, readContext: new ODataDeserializerContext()),
                "item",
                "The argument must be of type 'ODataResourceSetWrapper'.");
        }
        public void ReadInline_ThrowsArgumentNull_ReadContext()
        {
            // Arrange
            var deserializer = new ODataResourceSetDeserializer(_deserializerProvider);
            IEdmTypeReference typeReference = new Mock <IEdmTypeReference>().Object;

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => deserializer.ReadInline(42, typeReference, null), "readContext");
        }
예제 #4
0
        private static object ConvertResourceSet(ODataMessageReader oDataMessageReader,
                                                 IEdmTypeReference edmTypeReference, ODataDeserializerContext readContext)
        {
            IEdmCollectionTypeReference collectionType = edmTypeReference.AsCollection();

            EdmEntitySet tempEntitySet = null;

            if (collectionType.ElementType().IsEntity())
            {
                tempEntitySet = new EdmEntitySet(readContext.Model.EntityContainer, "temp",
                                                 collectionType.ElementType().AsEntity().EntityDefinition());
            }

            // TODO: Sam xu, can we use the parameter-less overload
            ODataReader odataReader = oDataMessageReader.CreateODataUriParameterResourceSetReader(tempEntitySet,
                                                                                                  collectionType.ElementType().AsStructured().StructuredDefinition());
            ODataResourceSetWrapper resourceSet =
                odataReader.ReadResourceOrResourceSet() as ODataResourceSetWrapper;

            ODataDeserializerProvider deserializerProvider = readContext.Request.GetDeserializerProvider();

            ODataResourceSetDeserializer resourceSetDeserializer =
                (ODataResourceSetDeserializer)deserializerProvider.GetEdmTypeDeserializer(collectionType);

            object      result     = resourceSetDeserializer.ReadInline(resourceSet, collectionType, readContext);
            IEnumerable enumerable = result as IEnumerable;

            if (enumerable != null)
            {
                IEnumerable newEnumerable = enumerable;
                if (collectionType.ElementType().IsEntity())
                {
                    newEnumerable = CovertResourceSetIds(enumerable, resourceSet, collectionType, readContext);
                }

                if (readContext.IsUntyped)
                {
                    return(newEnumerable.ConvertToEdmObject(collectionType));
                }
                else
                {
                    IEdmTypeReference elementTypeReference = collectionType.ElementType();

                    Type elementClrType = EdmLibHelpers.GetClrType(elementTypeReference,
                                                                   readContext.Model);
                    IEnumerable castedResult =
                        CastMethodInfo.MakeGenericMethod(elementClrType)
                        .Invoke(null, new object[] { newEnumerable }) as IEnumerable;
                    return(castedResult);
                }
            }

            return(null);
        }
        public void ReadInline_Throws_ArgumentTypeMustBeResourceSet()
        {
            // Arrange
            var deserializer          = new ODataResourceSetDeserializer(_deserializerProvider);
            IEdmTypeReference edmType = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)));

            // Act & Assert
            ExceptionAssert.ThrowsArgument(
                () => deserializer.ReadInline(42, edmType, new ODataDeserializerContext()),
                "edmType",
                "'[Collection([Edm.String Nullable=False Unicode=True]) Nullable=False]' is not a resource set type. Only resource set are supported.");
        }