public async Task TakeLastSingle()
        {
            // arrange
            var           typeInspector = new DefaultTypeInspector();
            IExtendedType sourceType    = typeInspector.GetType(typeof(List <string>));

            IPagingProvider pagingProvider = new QueryableCursorPagingProvider();
            IPagingHandler  pagingHandler  = pagingProvider.CreateHandler(sourceType, default);

            var list = new List <string> {
                "f", "g"
            };

            var pagingDetails = new CursorPagingArguments(last: 1);
            var context       = new MockContext(pagingDetails);

            // act
            var connection = (Connection)await pagingHandler.SliceAsync(context, list);

            // assert
            Assert.Collection(connection.Edges,
                              t =>
            {
                Assert.Equal("g", t.Node);
                Assert.Equal(1, GetPositionFromCursor(t.Cursor));
            });

            Assert.True(
                connection.Info.HasPreviousPage,
                "HasPreviousPage");

            Assert.False(
                connection.Info.HasNextPage,
                "HasNextPage");
        }
        public async Task HasPrevious_True()
        {
            // arrange
            var           typeInspector = new DefaultTypeInspector();
            IExtendedType sourceType    = typeInspector.GetType(typeof(List <string>));

            IPagingProvider pagingProvider = new QueryableCursorPagingProvider();
            IPagingHandler  pagingHandler  = pagingProvider.CreateHandler(sourceType, default);

            var list = new List <string> {
                "a", "b", "c", "d", "e", "f", "g"
            };

            var pagingDetails = new CursorPagingArguments(first: 1);
            var context       = new MockContext(pagingDetails);
            var connection    = (Connection)await pagingHandler.SliceAsync(context, list);

            pagingDetails = new CursorPagingArguments(after: connection.Info.EndCursor, first: 2);
            context       = new MockContext(pagingDetails);

            // act
            connection = (Connection)await pagingHandler.SliceAsync(context, list);

            // assert
            Assert.True(connection.Info.HasPreviousPage);
        }
Ejemplo n.º 3
0
 public PagingMiddleware(FieldDelegate next, IPagingHandler pagingHandler)
 {
     _next = next ??
             throw new ArgumentNullException(nameof(next));
     _pagingHandler = pagingHandler ??
                      throw new ArgumentNullException(nameof(pagingHandler));
 }
Ejemplo n.º 4
0
 public PostController(DbContext dbContext, IPostService postService, ICommentService commentService, IPagingHandler<Post> pagingHandler)
     : base(dbContext)
 {
     this._postService = postService;
     _commentService = commentService;
     _pagingHandler = pagingHandler;
 }
Ejemplo n.º 5
0
        private static void ApplyConfiguration(
            ITypeCompletionContext context,
            ObjectFieldDefinition definition,
            Type?entityType,
            GetPagingProvider?resolvePagingProvider,
            PagingOptions options,
            FieldMiddleware placeholder)
        {
            options = context.GetSettings(options);
            entityType ??= context.GetType <IOutputType>(definition.Type).ToRuntimeType();
            resolvePagingProvider ??= ResolvePagingProvider;

            IExtendedType   sourceType     = GetSourceType(context.TypeInspector, definition, entityType);
            IPagingProvider pagingProvider = resolvePagingProvider(context.Services, sourceType);
            IPagingHandler  pagingHandler  = pagingProvider.CreateHandler(sourceType, options);
            FieldMiddleware middleware     = CreateMiddleware(pagingHandler);

            var index = definition.MiddlewareComponents.IndexOf(placeholder);

            definition.MiddlewareComponents[index] = middleware;
        }
Ejemplo n.º 6
0
 public CategoryController(DbContext dbContext, ICategoryService categoryService, IPagingHandler<Post> pagingHandler)
     : base(dbContext)
 {
     this._categoryService = categoryService;
     _pagingHandler = pagingHandler;
 }
Ejemplo n.º 7
0
 private static FieldMiddleware CreateMiddleware(
     IPagingHandler handler) =>
 FieldClassMiddlewareFactory.Create(
     typeof(PagingMiddleware),
     (typeof(IPagingHandler), handler));