msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
What is the best way to mock Batch request?
Batch cannot be mocked as easy as other methods. What is the recommended way to mock Batch request so that I can write unit test?
Hey @kenakamu,
For starters you could always checkout the tests here.
You could also use checkout the tests for BatchResponseContent and BatchRequestContent here
Thanks. I am having following code in my project and want to create uint test around it.
graphServiceClient.Batch.Request().PostAsync(batchRequestContent)
I can easily mock normal ones, but not Batch. I do mock like below for other request.
mockedGraphServiceClient.Setup(x => x.Users[It.IsAny<string>()]
.Request()
.Select(It.IsAny<Expression<Func<Microsoft.Graph.User, object>>>())
.GetAsync(It.IsAny<CancellationToken>()))
.ReturnsAsync(new Microsoft.Graph.User() { Id = userId.ToString(), BusinessPhones = new List<string>() });
So ideally, if I can simply mock Batch request same as above, that would be ideal. At the moment, I cannot setup Batch itself as it's not virtual method.
By the way, this is what I am doing at the moment. https://dev.to/kenakamu/c-how-to-unit-test-graph-sdk-batch-request-38j2