You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to create integration tests. The real application is an ASP.NET API, but within the context of integration testing, I don't have access to the client registration goodness that is provided via Refit.HttpClientFactory.
So, I came up with this:
public class IntegrationTests
{
public Task Test()
{
var sut = CreateSut();
await sut.SomeMethod();
// Rest of the test
}
private IMyApi CreateSut()
{
return RestService.For<IMyApi>(
RestService.CreateHttpClient("http:/someserver.com/api",
new RefitSettings()
{
AuthorizationHeaderValueGetter = () => GetToken(config.Authorization)
}));
}
private async Task<string> GetToken(AuthorizationOptions authorizationOptions)
{
var client = RestService.CreateHttpClient(authorizationOptions.TokenUri.ToString(), new RefitSettings());
var passwordTokenRequest = AuthorizationMixin.ToPasswordTokenRequest(authorizationOptions);
var response = await client.RequestPasswordTokenAsync(passwordTokenRequest);
var token = response.AccessToken;
if (token is null)
{
throw new InvalidOperationException("Response token is null");
}
return token;
}
}
So, what's the problem I see? The problem is that, in order to get the authorization token in `GetToken', I need to instantiate an a secondary HttpClient.
I guess if there's a better method to do this.
Thanks in advance!
The text was updated successfully, but these errors were encountered:
I would like to create integration tests. The real application is an ASP.NET API, but within the context of integration testing, I don't have access to the client registration goodness that is provided via Refit.HttpClientFactory.
So, I came up with this:
So, what's the problem I see? The problem is that, in order to get the authorization token in `GetToken', I need to instantiate an a secondary HttpClient.
I guess if there's a better method to do this.
Thanks in advance!
The text was updated successfully, but these errors were encountered: