Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a straightforward way to mock CallHttpAsync? #2846

Open
clrockwell opened this issue Jun 5, 2024 · 0 comments
Open

Is there a straightforward way to mock CallHttpAsync? #2846

clrockwell opened this issue Jun 5, 2024 · 0 comments
Labels
P3 Priority 3

Comments

@clrockwell
Copy link

What version of .NET does your existing project use?

.NET 6

What version of .NET are you attempting to target?

.NET 8

Description

In the in process I could do something like this:

durableOrchestrationContextMock
    .Setup(x => x.CallHttpAsync(HttpMethod.Get, new Uri(uri), null, null))
    .ReturnsAsync(new DurableHttpResponse(System.Net.HttpStatusCode.OK) { Content = peString });

Now I am trying to do something like this

var mockContext = new Mock<TaskOrchestrationContext>();
mockContext
	.Setup(x => x.CallHttpAsync(HttpMethod.Get, new Uri("https://learn.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide?tabs=linux"), null, null))
	.ReturnsAsync(new DurableHttpResponse(System.Net.HttpStatusCode.OK));

But I get the error

System.NotSupportedException : Unsupported expression: x => x.CallHttpAsync(HttpMethod.Get, ltiUserGetUrl, null, null) Extension methods (here: TaskOrchestrationContextExtensionMethods.CallHttpAsync) may not be used in setup / verification expressions.

I see some posts online about creating a wrapper for mocking extension methods; however, with CallHttpAsync being the recommended way to make http calls in Functions I feel like I'm missing an easier way to mock and hoping someone can shed some light on this for me.

Project configuration and dependencies

No response

Link to a repository that reproduces the issue

No response

@jviau jviau transferred this issue from Azure/azure-functions-dotnet-worker Jun 12, 2024
@bachuv bachuv added P3 Priority 3 and removed Needs: Triage 🔍 labels Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Priority 3
Projects
None yet
Development

No branches or pull requests

2 participants