I am using graph to retrieve a list of filenames from a folder, however I am not able to mock the calls correctly in the unit test

Thomas, Sam 5 Reputation points
2025-04-28T20:00:03.4533333+00:00

here is my code:

var uploadSession = await graphServiceClient.Drives[driveId]        
.Items["root"]
.ItemWithPath(fileName)
.CreateUploadSession
.PostAsync(uploadSessionRequestBody);  

the above code works, but I am not able to mock the call properly to make my tests pass. 
when calling ItemWithPath I get an Exception:

Invalid URI: The hostname could not be parsed. 

this exception happens deep in the graph code and I have no clue how to mock these tests.    rootRequestBuilder.ToGetRequestInformation().URI.OriginalString is not a valid parameter for newUriBuilder(parameter) in the test environment.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,563 questions
0 comments No comments
{count} vote

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.