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
Copy file name to clipboardExpand all lines: README.md
+85-51Lines changed: 85 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@
6
6
7
7
# HttpWebRequestWrapper
8
8
9
-
**HttpWebRequestWrapper** is a testing layer for Microsoft's `HttpWebRequest` and `WebClient` classes. It overcomes restrictions that would normally prevent mocking a `HttpWebRequest` and allows testing your application with faked HTTP requests in Unit and BDD tests.
9
+
**HttpWebRequestWrapper** is a testing layer for Microsoft's `HttpClient`, `HttpWebRequest` and `WebClient` classes. It overcomes restrictions that would normally prevent mocking a `HttpWebRequest` and allows testing your application with faked HTTP requests in Unit and BDD tests.
10
10
11
-
Ideal for testing application code that relies on http api calls either directly or through 3rd party libraries!
11
+
`HttpWebRequestWrapper` is built with some serious secret sauce allowing you to intercept nearlly all http traffic, including calls made in 3rd party code and code that doesn't support dependency injection! It's the ideal testing tool for testing application code that relies on http api calls either directly or through 3rd party libraries!
12
12
13
13
## NuGet
14
14
@@ -18,6 +18,29 @@ HttpWebRequestWrapper has no 3rd Party dependencies!
18
18
19
19
## Usage
20
20
21
+
```csharp
22
+
// Asserts we can use a HttpWebRequestWrapperSession to
23
+
// intercept and replace the Response to
24
+
// new HttpClient().GetStringAsync("https://www.github.com")
Itwouldbeidealifthiscodeusedseperationofconcernsanddependencyinjectiontobemoretestable. Butperhapsit's in a 3rd party library, or it'llbetooexpensivetorefacotr.
**HttpWebRequestWrapper**can*not*supportconcurrenttestexecution. Becuase `HttpWebRequestWrapperSession` worksbysettingaglobalstaticvariableit's not possible to have two Sessions in use at one time. Code inside the Session'susingblockisfreetoexecuteconcurrently, youjustcan't try and use two or more Sessions at once.
`HttpClient` isnotsupportedby**HttpWebRequestWrapper** becausewhileitdoesuse `HttpWebRequest` underthehood, itdoesnothonorthe `WebRequest.PrefixList` fordeterminingwhich `IWebRequestCreate` tousetocreatethe`HttpWebRequest` ituses. So `HttpWebRequestWrapperSession` can't hook into it.
337
+
**HttpWebRequestWrapper**can*not*supportconcurrenttestexecution. Becuase `HttpWebRequestWrapperSession` worksbysettingaglobalstaticvariableit's not possible to have two Sessions in use at one time. Code inside the Session'susingblockisfreetoexecuteconcurrently, youjustcan't try and use two or more Sessions at once.
306
338
307
-
Ifyou're looking for testing tools specifically for `HttpClient`, try [MockHttp](https://github.com/richardszalay/mockhttp).
<description>Test/mock (3rd party) code reliant on HttpClient, WebClient, HttpWebRequest and WebRequest.Create() </description>
13
13
<summary>Test/mock (3rd party) code reliant on HttpClient, WebClient, HttpWebRequest and WebRequest.Create()</summary>
14
-
<releaseNotes>Test/mock (3rd party) code reliant on HttpWebRequest and WebRequest.Create()!
14
+
<releaseNotes>
15
+
Test/mock (3rd party) code reliant on HttpClient, HttpWebRequest, WebClient and WebRequest.Create()!
15
16
16
17
Includes mockable MockHttpWebRequest, HttpWebRequestWrapperSession, HttpWebRequestWrapperRecorder, HttpWebRequestWrapperInterceptor and Playback controls
0 commit comments