/// <inheritdoc />
        public override async Task <object> ReadAsync(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull(nameof(messageReader));
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull(nameof(readContext));
            }

            // TODO: Need to modify how to get the Edm type for the delta resource set?
            IEdmTypeReference edmType = readContext.GetEdmType(type);

            Contract.Assert(edmType != null);

            IEdmEntityType entityType = edmType.Definition as IEdmEntityType;

            EdmDeltaCollectionType edmCollectionType = new EdmDeltaCollectionType(edmType);

            edmType = new EdmCollectionTypeReference(edmCollectionType);

            // TODO: is it ok to read the top level collection of entity?
            if (!(edmType.IsCollection() && edmType.AsCollection().ElementType().IsStructured()))
            {
                throw Error.Argument("edmType", SRResources.ArgumentMustBeOfType, EdmTypeKind.Complex + " or " + EdmTypeKind.Entity);
            }

            IEdmNavigationSource navigationSource;

            if (readContext.Path == null)
            {
                throw Error.Argument("readContext", SRResources.ODataPathMissing);
            }

            navigationSource = readContext.Path.GetNavigationSource();
            if (navigationSource == null)
            {
                throw new SerializationException(SRResources.NavigationSourceMissingDuringDeserialization);
            }

            ODataReader resourceSetReader = await messageReader.CreateODataDeltaResourceSetReaderAsync(navigationSource as IEdmEntitySet, entityType).ConfigureAwait(false);

            object deltaResourceSet = await resourceSetReader.ReadResourceOrResourceSetAsync().ConfigureAwait(false);

            return(ReadInline(deltaResourceSet, edmType, readContext));
        }
示例#2
0
        public void GetElementType_ReturnsCorrectly()
        {
            // 1) null
            IEdmTypeReference typeReference = null;
            IEdmType          actualTypeRef = typeReference.GetElementType();

            Assert.Null(actualTypeRef);

            // 2) non-collection
            typeReference = EdmCoreModel.Instance.GetString(false);
            actualTypeRef = typeReference.GetElementType();
            Assert.Same(actualTypeRef, typeReference.Definition);

            // 3) Collection
            typeReference = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(false)));
            actualTypeRef = typeReference.GetElementType();
            Assert.Same(actualTypeRef, typeReference.AsCollection().ElementType().Definition);
        }