Skip to content

Commit 8f287e1

Browse files
committed
Fixed init order for Flurl config settings
The special handler configured by HttpTest was being overwritten causing the unit tests to hit the real endpoint instead of returning mock results.
1 parent 712d34d commit 8f287e1

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/corelib/OpenStackNet.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ public static void Configure(Action<FlurlHttpConfigurationOptions> configureFlur
6060

6161
FlurlHttp.Configure(c =>
6262
{
63+
// Apply our default settings
64+
c.HttpClientFactory = new AuthenticatedHttpClientFactory();
65+
6366
// Apply the application's default settings
6467
if (configureFlurl != null)
6568
configureFlurl(c);
6669

67-
// Apply our default settings
68-
c.HttpClientFactory = new AuthenticatedHttpClientFactory();
69-
70+
// Apply our event handling without clobbering any application level handlers
7071
var applicationBeforeCall = c.BeforeCall;
7172
c.BeforeCall = call =>
7273
{

src/testing/unit/AuthenticationTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public async void When401AuthenticationFailsMultipleTimes_ThrowException()
2727
{
2828
using (var httpTest = new HttpTest())
2929
{
30-
var x = FlurlHttp.Configuration.HttpClientFactory.CreateClient(null, FlurlHttp.Configuration.HttpClientFactory.CreateMessageHandler());
3130
httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");
3231
httpTest.RespondWith((int)HttpStatusCode.Unauthorized, "Your token has expired");
3332

src/testing/unit/Stubs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static Mock<IAuthenticationProvider> CreateAuthenticationProvider()
2727
.Returns(Task.FromResult("mock-token"));
2828

2929
stub.Setup(provider => provider.GetEndpoint(It.IsAny<IServiceType>(), It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()))
30-
.Returns(Task.FromResult("http://api.com"));
30+
.Returns(Task.FromResult("http://example.com/api"));
3131

3232
return stub;
3333
}

0 commit comments

Comments
 (0)