6

I would like to mock a C# method that returns an Azure.AsyncPageable.

This class has only protected constructors, so I cannot instantiate it directly. Is there any way to create an instance of this class from some other collection, such as an IAsyncEnumerable or just a List?

Claus Appel
  • 1,015
  • 10
  • 28

1 Answers1

12

You can create Page objects using Page<T>.FromValues. Then, create a AsyncPageable<T> using AsyncPageable<T>.FromPages.

Example:

        var page = Page<TableEntity>.FromValues(new List<TableEntity>
        {
            new TableEntity("1a", "2a"),
            new TableEntity("1", "2b")
        }, continuationToken: null, new Mock<Response>().Object);
        var pages = AsyncPageable<TableEntity>.FromPages(new[] { page });
Alex AIT
  • 17,361
  • 3
  • 36
  • 73
Peter Bons
  • 26,826
  • 4
  • 50
  • 74