Exemplo n.º 1
0
 public void IsDeltaOfT_Returns_BooleanAsExpected()
 {
     // Arrange & Act & Assert
     Assert.False(DeltaHelper.IsDeltaOfT(null));
     Assert.False(DeltaHelper.IsDeltaOfT(typeof(int)));
     Assert.False(DeltaHelper.IsDeltaOfT(typeof(DeltaSet <>)));
 }
        /// <summary>
        /// Returns the URI for NextPageLink
        /// </summary>
        /// <param name="baseUri">BaseUri for nextlink. It should be request URI for top level resource and navigation link for nested resource.</param>
        /// <param name="pageSize">Maximum number of records in the set of partial results for a resource.</param>
        /// <param name="instance">Instance based on which SkipToken value will be generated.</param>
        /// <param name="context">Serializer context</param>
        /// <returns>Returns the URI for NextPageLink. If a null object is passed for the instance, resorts to the default paging mechanism of using $skip and $top.</returns>
        public override Uri GenerateNextPageLink(Uri baseUri, int pageSize, Object instance, ODataSerializerContext context)
        {
            if (context == null)
            {
                return(null);
            }

            if (pageSize <= 0)
            {
                return(null);
            }

            Func <object, string>       skipTokenGenerator = null;
            IList <OrderByNode>         orderByNodes       = null;
            ExpandedReferenceSelectItem expandedItem       = context.CurrentSelectItem as ExpandedReferenceSelectItem;
            IEdmModel model = context.Model;

            DefaultQuerySettings settings = context.QueryContext.DefaultQuerySettings;

            if (settings.EnableSkipToken)
            {
                if (expandedItem != null)
                {
                    // Handle Delta resource; currently not value based.
                    if (DeltaHelper.IsDeltaOfT(context.ExpandedResource.GetType()))
                    {
                        return(GetNextPageHelper.GetNextPageLink(baseUri, pageSize));
                    }

                    if (expandedItem.OrderByOption != null)
                    {
                        orderByNodes = OrderByNode.CreateCollection(expandedItem.OrderByOption);
                    }

                    skipTokenGenerator = (obj) =>
                    {
                        return(GenerateSkipTokenValue(obj, model, orderByNodes));
                    };

                    return(GetNextPageHelper.GetNextPageLink(baseUri, pageSize, instance, skipTokenGenerator));
                }

                if (context.QueryOptions != null && context.QueryOptions.OrderBy != null)
                {
                    orderByNodes = context.QueryOptions.OrderBy.OrderByNodes;
                }

                skipTokenGenerator = (obj) =>
                {
                    return(GenerateSkipTokenValue(obj, model, orderByNodes));
                };
            }

            return(GetNextPageHelper.GetNextPageLink(baseUri, pageSize, instance, skipTokenGenerator));
        }