How to mock Microsoft Graph APIs GraphServiceClient using moq

Newbie Dev 151 Reputation points


My project is using GraphServiceClient to get the user Group Names using the below code.

var group = await graphClient.Me.TransitiveMemberOf

The group variable is then used to get the DisplayName of the group.

I want to unit test the above code using Moq.

var mockAuthProvider = new Mock<IAuthenticationProvider>();
            var mockHttpProvider = new Mock<IHttpProvider>();
           var mockGraphClient = new Mock<GraphServiceClient>(mockAuthProvider.Object, mockHttpProvider.Object);

mockGraphClient.Setup(c => c.Me.TransitiveMemberOf.Request().GetAsync(CancellationToken.None)).ReturnsAsync(???);

The ReturnAsync will return IUserTransitiveMemberOfCollectionWithReferencesPage, but how can I give a default value for it so I can test the rest of the method which actually gets the displayName

Thanks in advance.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,071 questions
0 comments No comments
{count} votes