Unit Testing Help

Can someone please tell me how to mock Invoke-RestMethod and Get-AzureADUser. Thanks in Advance.
$userprincipalName = (Get-AzureADUser -Filter "DisplayName eq '$($Owner)' and UserType eq 'Member'").UserPrincipalName
$samAccountName = Invoke-RestMethod -Method Get -Headers @{
Authorization=$token.CreateAuthorizationHeader()
'Content-Type'="application/json"
} -Uri ("https://graph.microsoft.com/v1.0/users/$($userprincipalName)/mailNickname") |
select -expand Value

This is what Pester is for.

Get started with Pester (PowerShell unit testing framework)
https://devblogs.microsoft.com/scripting/what-is-pester-and-why-should-i-care
https://www.powershellmagazine.com/2014/03/12/get-started-with-pester-powershell-unit-testing-framework
https://github.com/pester/Pester

Are you saying, you’ve tried to use the above tool and not proven successful for your use case / needs?
Or that you could not derive a way you felt prudent with it?

Ensure you are doing some error handling as well.

Example:

Error Handling for Invoke-RestMethod - PowerShell
https://stackoverflow.com/questions/29613572/error-handling-for-invoke-restmethod-powershell