Skip to content

Commit 8c8bea8

Browse files
committed
Cleanup where/when OpenStackNet.Configure is called
It should only be called automatically when the config is accessed, manually by the calling application and by HttpTest.
1 parent b4abbb8 commit 8c8bea8

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

src/corelib/Testing/HttpTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using System;
2+
using System.Net;
23
using System.Net.Http;
34
using Flurl;
5+
using Flurl.Http;
46
using Flurl.Http.Configuration;
7+
using Flurl.Http.Content;
58
using OpenStack.Authentication;
69

710
namespace OpenStack.Testing
@@ -31,6 +34,7 @@ public HttpTest(Action<FlurlHttpSettings> configureFlurl = null, Action<OpenStac
3134
CallLog.Add(call);
3235
};
3336
};
37+
OpenStackNet.ResetDefaults();
3438
OpenStackNet.Configure(setFlurlTestMode, configure);
3539
}
3640

@@ -41,6 +45,23 @@ public HttpTest(Action<FlurlHttpSettings> configureFlurl = null, Action<OpenStac
4145
base.Dispose();
4246
}
4347

48+
/// <inheritdoc />
49+
public new HttpTest RespondWithJson(object data)
50+
{
51+
return RespondWithJson(200, data);
52+
}
53+
54+
/// <inheritdoc />
55+
public new HttpTest RespondWithJson(int status, object data)
56+
{
57+
ResponseQueue.Enqueue(new HttpResponseMessage
58+
{
59+
StatusCode = (HttpStatusCode)status,
60+
Content = new CapturedJsonContent(OpenStackNet.Configuration.FlurlHttpSettings.JsonSerializer.Serialize(data))
61+
});
62+
return this;
63+
}
64+
4465
class TestHttpClientFactory : IHttpClientFactory
4566
{
4667
private readonly Flurl.Http.Testing.TestHttpClientFactory _testMessageHandler;

src/testing/unit/OpenStackNetTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ public OpenStackNetTests(ITestOutputHelper testLog)
1818
{
1919
var testOutput = new XunitTraceListener(testLog);
2020
Trace.Listeners.Add(testOutput);
21-
22-
OpenStackNet.ResetDefaults();
2321
}
2422

2523
public void Dispose()
2624
{
2725
OpenStackNet.ResetDefaults();
28-
OpenStackNet.Configure();
2926
}
3027

3128
[Fact]

src/testing/unit/Serialization/EmptyEnumerableTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public ExampleThing()
2020
[Fact]
2121
public void WhenDeserializingNullCollection_ItShouldUseAnEmptyCollection()
2222
{
23-
OpenStackNet.Configure();
2423
var thing = new ExampleThing{Messages = null};
2524
string json = OpenStackNet.Configuration.FlurlHttpSettings.JsonSerializer.Serialize(thing);
2625
Assert.DoesNotContain("messages", json);
@@ -34,7 +33,6 @@ public void WhenDeserializingNullCollection_ItShouldUseAnEmptyCollection()
3433
[Fact]
3534
public void WhenSerializingEmptyCollection_ItShouldBeIgnored()
3635
{
37-
OpenStackNet.Configure();
3836
var thing = new ExampleThing { Messages = new List<string>() };
3937

4038
string json = OpenStackNet.Configuration.FlurlHttpSettings.JsonSerializer.Serialize(thing);

src/testing/unit/Serialization/RootWrapperConverterTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ class Thing
1919
class ThingCollection : List<Thing>
2020
{
2121
}
22-
23-
public RootWrapperConverterTests()
24-
{
25-
OpenStackNet.Configure();
26-
}
27-
22+
2823
[Fact]
2924
public void Serialize()
3025
{

0 commit comments

Comments
 (0)