File tree Expand file tree Collapse file tree 4 files changed +57
-0
lines changed
MyWebApi.Tests/BuildersTests Expand file tree Collapse file tree 4 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,13 @@ MyWebApi.IsRegisteredWith(WebApiConfig.Register);
63
63
// * it is useful if you want to reset the global
64
64
// * configuration used in other tests
65
65
MyWebApi .IsUsingDefaultHttpConfiguration ();
66
+
67
+ // the three options provide a way to set
68
+ // the error detail policy for the testing
69
+ // * default is 'Always' for easier debugging
70
+ MyWebApi
71
+ .IsRegisteredWith (WebApiConfig .Register )
72
+ .WithErrorDetailPolicy (IncludeErrorDetailPolicy .LocalOnly );
66
73
```
67
74
68
75
[ To top] ( #table-of-contents )
Original file line number Diff line number Diff line change 4
4
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
5
5
namespace MyTested . WebApi . Tests . BuildersTests
6
6
{
7
+ using System . Web . Http ;
7
8
using Common . Servers ;
8
9
using NUnit . Framework ;
9
10
using Setups ;
@@ -26,5 +27,25 @@ public void AndStartsServerShouldStartServerCorrectly()
26
27
Assert . IsNull ( HttpTestServer . GlobalClient ) ;
27
28
Assert . IsFalse ( HttpTestServer . GlobalIsStarted ) ;
28
29
}
30
+
31
+ [ Test ]
32
+ public void DefaultErrorDetailPolicyShouldBeAlways ( )
33
+ {
34
+ MyWebApi . IsUsingDefaultHttpConfiguration ( ) ;
35
+
36
+ Assert . AreEqual ( IncludeErrorDetailPolicy . Always , MyWebApi . Configuration . IncludeErrorDetailPolicy ) ;
37
+
38
+ MyWebApi . IsUsing ( TestObjectFactory . GetHttpConfigurationWithRoutes ( ) ) ;
39
+ }
40
+
41
+ [ Test ]
42
+ public void WithErrorDetailPolicyShouldSetCorrectErrorDetailPolicy ( )
43
+ {
44
+ MyWebApi . IsUsingDefaultHttpConfiguration ( ) . WithErrorDetailPolicy ( IncludeErrorDetailPolicy . LocalOnly ) ;
45
+
46
+ Assert . AreEqual ( IncludeErrorDetailPolicy . LocalOnly , MyWebApi . Configuration . IncludeErrorDetailPolicy ) ;
47
+
48
+ MyWebApi . IsUsing ( TestObjectFactory . GetHttpConfigurationWithRoutes ( ) ) ;
49
+ }
29
50
}
30
51
}
Original file line number Diff line number Diff line change 4
4
// Dual-licensed under the Apache License, Version 2.0, and the Microsoft Public License (Ms-PL).
5
5
namespace MyTested . WebApi . Builders . Contracts
6
6
{
7
+ using System . Web . Http ;
8
+
7
9
/// <summary>
8
10
/// HTTP configuration builder.
9
11
/// </summary>
@@ -14,5 +16,12 @@ public interface IHttpConfigurationBuilder
14
16
/// </summary>
15
17
/// <returns>Server builder.</returns>
16
18
IServerBuilder AndStartsServer ( ) ;
19
+
20
+ /// <summary>
21
+ /// Sets the error detail policy used in the testing. Default is 'Always'.
22
+ /// </summary>
23
+ /// <param name="errorDetailPolicy">Error details policy to use.</param>
24
+ /// <returns>The same HTTP configuration builder.</returns>
25
+ IHttpConfigurationBuilder WithErrorDetailPolicy ( IncludeErrorDetailPolicy errorDetailPolicy ) ;
17
26
}
18
27
}
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ public class HttpConfigurationBuilder : IHttpConfigurationBuilder
22
22
public HttpConfigurationBuilder ( HttpConfiguration httpConfiguration )
23
23
{
24
24
this . httpConfiguration = httpConfiguration ;
25
+ this . SetErrorDetailPolicy ( IncludeErrorDetailPolicy . Always ) ;
25
26
}
26
27
27
28
/// <summary>
@@ -32,5 +33,24 @@ public IServerBuilder AndStartsServer()
32
33
{
33
34
return new Server ( ) . Starts ( this . httpConfiguration ) ;
34
35
}
36
+
37
+ /// <summary>
38
+ /// Sets the error detail policy used in the testing. Default is 'Always'.
39
+ /// </summary>
40
+ /// <param name="errorDetailPolicy">Error details policy to use.</param>
41
+ /// <returns>The same HTTP configuration builder.</returns>
42
+ public IHttpConfigurationBuilder WithErrorDetailPolicy ( IncludeErrorDetailPolicy errorDetailPolicy )
43
+ {
44
+ this . SetErrorDetailPolicy ( errorDetailPolicy ) ;
45
+ return this ;
46
+ }
47
+
48
+ private void SetErrorDetailPolicy ( IncludeErrorDetailPolicy errorDetailPolicy )
49
+ {
50
+ if ( this . httpConfiguration != null )
51
+ {
52
+ this . httpConfiguration . IncludeErrorDetailPolicy = errorDetailPolicy ;
53
+ }
54
+ }
35
55
}
36
56
}
You can’t perform that action at this time.
0 commit comments