Skip to content

Commit f6fc58c

Browse files
committed
Added option to set default HttpConfiguration (closes #178)
1 parent c23cd1d commit f6fc58c

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ Basically you can create a test case by using the fluent API the library provide
2525
```c#
2626
namespace MyApp.Tests.Controllers
2727
{
28-
using MyApp.Controllers;
2928
using My.WebApi;
29+
30+
using MyApp.Controllers;
3031
using NUnit.Framework;
3132

3233
[TestFixture]

documentation/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,20 @@
4949

5050
### Using custom HttpConfiguration
5151

52-
You have the option to configure global HttpConfiguration to be used across all test cases:
52+
You have the option to configure global HttpConfiguration to be used across all test cases. These call are not necessary but can be helpful for route tests for example where all registered routes are the same throughout the whole application:
5353

5454
```c#
55-
// providing instance of HttpConfiguration
55+
// register configuration by providing instance of HttpConfiguration
5656
MyWebApi.IsUsing(httpConfiguration);
5757

58-
// or provide registration action
58+
// or by providing registration action
5959
MyWebApi.IsRegisteredWith(WebApiConfig.Register);
60+
61+
// or by setting the default HttpConfiguration
62+
// * this call is not necessary for tests to run
63+
// * it is useful if you want to reset the global
64+
// * configuration used in other tests
65+
MyWebApi.IsUsingDefaultHttpConfiguration();
6066
```
6167

6268
[To top](#table-of-contents)

src/MyWebApi.Tests/MyWebApiTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,16 @@ public void IsRegisteredWithShouldWorkCorrectly()
117117

118118
MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
119119
}
120+
121+
[Test]
122+
public void IsUsingDefaultConfigurationShouldWorkCorrectly()
123+
{
124+
MyWebApi.IsUsingDefaultHttpConfiguration();
125+
126+
Assert.IsNotNull(MyWebApi.Configuration);
127+
Assert.AreEqual(0, MyWebApi.Configuration.Routes.Count);
128+
129+
MyWebApi.IsUsing(TestObjectFactory.GetHttpConfigurationWithRoutes());
130+
}
120131
}
121132
}

src/MyWebApi/MyWebApi.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public static class MyWebApi
3131
/// <value>Instance of HttpConfiguration.</value>
3232
public static HttpConfiguration Configuration { get; private set; }
3333

34+
/// <summary>
35+
/// Sets the default HttpConfiguration which will be used in all tests.
36+
/// </summary>
37+
/// <returns>HTTP configuration builder.</returns>
38+
public static IHttpConfigurationBuilder IsUsingDefaultHttpConfiguration()
39+
{
40+
return IsUsing(new HttpConfiguration());
41+
}
42+
3443
/// <summary>
3544
/// Sets the HttpConfiguration which will be used in all tests.
3645
/// </summary>

0 commit comments

Comments
 (0)