public async Task <ActionResult <ResourceCollection <FolderResource> > > GetAsync(
            [FromQuery] int limit = 100, [FromQuery] string nextPageToken = "")
        {
            try
            {
                var query    = new ReadFoldersQuery(limit, nextPageToken);
                var response = await mediator.Send(query);

                var folders = response.Items.Select(x => new FolderResource(x)).ToArray();
                foreach (var folder in folders)
                {
                    folder.EnrichWithLinks(this);
                }

                var foldersCollection = new ResourceCollection <FolderResource>(folders, response.NextPageToken);
                foldersCollection.AddLinks(
                    new Link("self", this.Url.Link("GetFolders", new { Limit = limit, NextPageToken = nextPageToken })),
                    response.NextPageToken != null
                        ? new Link("next", this.Url.Link("GetFolders", new { Limit = limit, NextPageToken = response.NextPageToken }))
                        : new Link("next", null),
                    new Link("post", this.Url.Link("CreateFolder", null))
                    );

                return(foldersCollection);
            }
            catch (InvalidNextPageTokenRequestException)
            {
                return(BadRequest(new { Message = "The provided Next Page Token is invalid." }));
            }
        }
Exemple #2
0
        public void ReadFolders_NextPageTokenIsInvalid_ThrowsInvalidNextPageTokenRequestException()
        {
            var query        = new ReadFoldersQuery(100, Guid.NewGuid().ToString());
            var queryHandler = ReadFoldersQueryHandlerFactory.CreateForInvalidNextPageTokenRepositoryException();

            Should.Throw <InvalidNextPageTokenRequestException>(
                async() => await queryHandler.Handle(query, CancellationToken.None));
        }
Exemple #3
0
        public async Task ReadFolders_NoFoldersExist_EmptyPageIsReturned()
        {
            var foldersPagedSeed = new PaginatedResult <FolderDto>(new List <FolderDto>(), null);

            var query        = new ReadFoldersQuery();
            var queryHandler = ReadFoldersQueryHandlerFactory.Create(foldersPagedSeed);

            var response = await queryHandler.Handle(query, CancellationToken.None);

            response.Items.Count.ShouldBe(0);
            response.NextPageToken.ShouldBeNull();
        }
Exemple #4
0
        public async Task ReadFolders_ThreeFoldersExist_ThreeFoldersAreRetrieved()
        {
            var foldersPagedSeed = GetFoldersSeed();

            var query        = new ReadFoldersQuery();
            var queryHandler = ReadFoldersQueryHandlerFactory.Create(foldersPagedSeed);

            var response = await queryHandler.Handle(query, CancellationToken.None);

            response.Items.Count.ShouldBe(foldersPagedSeed.Items.Count);
            response.NextPageToken.ShouldBe(foldersPagedSeed.NextPageToken);

            foreach (var item in response.Items)
            {
                foldersPagedSeed.Items.ShouldContain(
                    x => x.Id == item.Id &&
                    x.CreationDate == item.CreationDate &&
                    x.Name == item.Name &&
                    x.ParentId == item.ParentId);
            }
        }