Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an Azure.AsyncPageable for mocking?

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?

like image 599
Claus Appel Avatar asked Nov 27 '25 14:11

Claus Appel


1 Answers

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 });
like image 145
Peter Bons Avatar answered Nov 30 '25 02:11

Peter Bons



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!