Reputation: 2189
I am trying to mock the Query
method of Azure.Data.Tables.TableClient
but cannot get my head around the syntax.
The concrete query I am trying to mock is:
var query = tableClient.Query<MyPoco>(filter: mp => mp.PartitionKey == "abc");
My attempts to Setup
the mock are:
Mock<TableClient> mockTableClient = new Mock<TableClient>();
MyPoco[] mp = new MyPoco[] { new MyPoco() };
var page = Page<MyPoco>.FromValues(mp, default, new Mock<Response>().Object);
var pageable = Pageable<MyPoco>.FromPages(new[] { page });
// attempt 1
mockTableClient.Setup(c => c.Query<MyPoco>(It.Is<Func<MyPoco, bool>>(
It.IsAny<MyPoco> => true)))
.Returns(pageable);
// attempt 2
mockTableClient.Setup(c => c.Query<MyPoco>(It.Is<Expression<Func<MyPoco, bool>>>(
It.IsAny<MyPoco> => true)))
.Returns(pageable);
Upvotes: 0
Views: 725
Reputation: 2189
My attempts were close but they were also masking the fact that you have to supply optional arguments too.
mockTableClient.Setup(c => c.Query<MyPoco>(It.Is<Expression<Func<MyPoco, bool>>>(mp => true),
It.IsAny<Nullable<int>>(),
It.IsAny<IEnumerable<string>>(),
It.IsAny<CancellationToken>()))
.Returns(pageable);
Upvotes: 0