public void GetEdmType_Returns_EdmTypeInitializedByCtor()
        {
            IEdmEntityTypeReference _entityReferenceType = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), isNullable: false);
            var edmObject = new EdmDeltaCollectionType(_entityReferenceType);

            Assert.Same(_entityReferenceType, edmObject.ElementType);
        }
        public void CollectionType_IsDeltaFeed_ReturnsTrueForDeltaCollectionType()
        {
            IEdmEntityType              _entityType       = new EdmEntityType("NS", "Entity");
            EdmDeltaCollectionType      _edmType          = new EdmDeltaCollectionType(new EdmEntityTypeReference(_entityType, isNullable: true));
            IEdmCollectionTypeReference _edmTypeReference = new EdmCollectionTypeReference(_edmType);

            Assert.True(_edmTypeReference.Definition.IsDeltaFeed());
        }
        public void CtorEdmDeltaCollectionType_SetsProperties()
        {
            // Arrange & Act
            IEdmTypeReference      typeRef   = new Mock <IEdmTypeReference>().Object;
            EdmDeltaCollectionType deltaType = new EdmDeltaCollectionType(typeRef);

            // Assert
            Assert.Equal(EdmTypeKind.Collection, deltaType.TypeKind);
            Assert.Same(typeRef, deltaType.ElementType);
        }
        /// <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));
        }