-
-
Notifications
You must be signed in to change notification settings - Fork 391
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
HttpTest - Mock specific url calls #225
Comments
Not currently, no. Test mode is sort of all or nothing. If it were 2 method calls, you could always fire up an I'll keep this open for consideration. I have thought about enhancing |
Thanks for the response. Actually my scenario is that I'm testing a service of mine which calls a 3rd party web api inside one of its methods. I want to mock that 3rd party web api to control which response it returns. |
I have the some case tests like yours @gregoks and I want to be able to test some complexes scenarios by using Flurl, is it too complicated to add ? |
@felipe-rochac I wouldn't say it's "too complicated", but it is a major enhancement. I definitely want to do it though, and it could be the centerpiece of the next minor version upgrade. Spending most of my available time on overhauling the docs right now, but hopefully this will be the next big thing. |
@tmenier thanks! Any idea when will it be released? |
I was just about to suggest this as a feature ;). I want to test a function that executes several calls concurrently, which is impossible with the current httptest |
As TomBruyneel said, could really use this :) |
I'm actively gathering feedback to help prioritize issues for 3.0. If this one is important to you, please vote for it here! |
I'm just hitting this issue with current testing model. If we have this code, is there a way to test the GetRiskForTicker method with doing a fake call with FlurlStockClient and do a real call with FlurlRiskClient? public class RiskManagementService
{
private FlurlStockClient _stockClient;
private FlurlRiskClient _riskClient;
RiskManagementService(FlurlStockClient stockClient, FlurlRiskClient riskClient)
{
_stockClient = stockClient;
_riskClient = riskClient;
}
public double GetRiskForTicker(string ticker)
{
double tickerPrice = _stockClient.GetTickerPrice(ticker);
return _riskClient.GetRisk(tickerPrice);
}
}
public FlurlStockClient(IFlurlClientFactory flurlClientFac)
{
private readonly IFlurlClient _client;
public FlurlStockClient(IFlurlClientFactory flurlClientFac)
{
_client = flurlClientFac.Get("https://stock-service.com");
}
}
public FlurlRiskClient(IFlurlClientFactory flurlClientFac)
{
private readonly IFlurlClient _client;
public FlurlRiskClient(IFlurlClientFactory flurlClientFac)
{
_client = flurlClientFac.Get("https://risk-service.com");
}
} Thanks |
@juchom I would normally answer no and link to the open issue but I see you already found it. ;) |
Changed my mind about combining this with #481. I'll track it a separate issue. Here's how this will look in 3.0: httpTest
.ForCallsTo("*.api.com*", "*.test-api.com*") // multiple allowed, wildcard supported
.AllowRealHttp(); That's it. By default, all Flurl calls made during the lifetime of an |
Now available to test: https://www.nuget.org/packages/Flurl.Http/3.0.0-pre2 |
Hi,
Is it possible to decide which url calls will be mocked and which wont? For example, if my method that I test has several HTTP calls to different Urls. I only want to mock one of the calls and the other calls should get to the actual API url.
Thanks,
Greg
The text was updated successfully, but these errors were encountered: