cannot mock TableQuerySegment
See original GitHub issueI’m writing unit tests for my codes where I need to fake Azure storage. Inside my test codes, I need to mock cloudTable.ExecuteQuerySegmentedAsync(query, continuationToken, cancellationToken)
which returns TableQuerySegment<TElement>
. However TableQuerySegment
has no public contructors so I’m unable to mock it or consturct its instance. What can be done so that I don’t have to call azure actually but get a fake data to continue my tests?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:10 (1 by maintainers)
Top Results From Across the Web
Mocking CloudStorageAccount and CloudTable for Azure ...
My goal is to mock it, but since it is virtual and doesn't implement any interface, I can't come over with a simple...
Read more >Developers - cannot mock TableQuerySegment -
I'm writing unit tests for my codes where I need to fake Azure storage. Inside my test codes, I need to mock cloudTable....
Read more >TableQuerySegment<TElement> Class
Represents a segment of results and contains continuation token information.
Read more >Unit testing and mocking with Azure SDK .NET
We'll illustrate this set of examples using a popular .NET mocking framework, Moq. To create a test client instance using Moq: Mock< ...
Read more >Doing async the right way
The problem with the methods above is that although they return control to the caller ... AddRange(await FetchRecords(table, query, segment.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve worked around this issue by using reflection to create a mock (well actually a real) instance of TableQuerySegment like so:-
If like me you also need to use the ContinuationToken in your tests you can expand @pdl5p 's code like so:
This can be used to test when ExecuteQuerySegmentedAsync returns a continuation token meaning more results are available from the table