Skip to content

Commit 2a014ac

Browse files
Merge pull request #22 from martincostello/Update-README
Update examples
2 parents ab741bf + 60c84d0 commit 2a014ac

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<RepositoryType>git</RepositoryType>
2525
<RepositoryUrl>$(PackageProjectUrl).git</RepositoryUrl>
2626
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
27-
<VersionPrefix>1.2.0</VersionPrefix>
27+
<VersionPrefix>1.2.1</VersionPrefix>
2828
<VersionSuffix></VersionSuffix>
2929
</PropertyGroup>
3030
</Project>

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ Below is a minimal example of intercepting a request to an HTTP API for a JSON r
3636
```csharp
3737
// using JustEat.HttpClientInterception;
3838
39+
var options = new HttpClientInterceptorOptions();
40+
3941
var builder = new HttpRequestInterceptionBuilder()
42+
.Requests()
4043
.ForHost("public.je-apis.com")
4144
.ForPath("terms")
42-
.WithJsonContent(new { Id = 1, Link = "https://www.just-eat.co.uk/privacy-policy" });
43-
44-
var options = new HttpClientInterceptorOptions()
45-
.Register(builder);
45+
.Responds()
46+
.WithJsonContent(new { Id = 1, Link = "https://www.just-eat.co.uk/privacy-policy" })
47+
.RegisterWith(options);
4648

4749
var client = options.CreateHttpClient();
4850

@@ -59,12 +61,13 @@ Below is a minimal example of intercepting a request to inject an HTTP fault:
5961
```csharp
6062
// using JustEat.HttpClientInterception;
6163
64+
var options = new HttpClientInterceptorOptions();
65+
6266
var builder = new HttpRequestInterceptionBuilder()
67+
.Requests()
6368
.ForHost("public.je-apis.com")
64-
.WithStatus(HttpStatusCode.InternalServerError);
65-
66-
var options = new HttpClientInterceptorOptions()
67-
.Register(builder);
69+
.WithStatus(HttpStatusCode.InternalServerError)
70+
.RegisterWith(options);
6871

6972
var client = options.CreateHttpClient();
7073

@@ -119,7 +122,8 @@ var options = new HttpClientInterceptorOptions();
119122

120123
var server = new WebHostBuilder()
121124
.UseStartup<Startup>()
122-
.ConfigureServices((services) => services.AddTransient((_) => options.CreateHttpMessageHandler()))
125+
.ConfigureServices(
126+
(services) => services.AddTransient((_) => options.CreateHttpMessageHandler()))
123127
.Build();
124128

125129
server.Start();

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
os: Visual Studio 2017
2-
version: 1.2.0.{build}
2+
version: 1.2.1.{build}
33

44
environment:
55
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

samples/SampleApp.Tests/ReposTests.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,19 @@ public async Task Can_Get_Organization_Repositories()
3939
{
4040
// Setup an expected response from the GitHub API
4141
var builder = new HttpRequestInterceptionBuilder()
42+
.Requests()
4243
.ForHttps()
4344
.ForHost("api.github.com")
4445
.ForPath("orgs/weyland-yutani/repos")
4546
.ForQuery("per_page=2")
47+
.Responds()
4648
.WithJsonContent(
4749
new[]
4850
{
4951
new { id = 1, name = "foo" },
5052
new { id = 2, name = "bar" },
51-
});
52-
53-
// Add a callback for when a request is intercepted
54-
builder.WithInterceptionCallback(
55-
(request) => _outputHelper.WriteLine($"Intercepted HTTP {request.Method} {request.RequestUri}"));
56-
57-
_fixture.Interceptor.Register(builder);
53+
})
54+
.RegisterWith(_fixture.Interceptor);
5855

5956
string[] actual;
6057

tests/HttpClientInterception.Tests/Examples.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public static class Examples
2525
public static async Task Intercept_Http_Get_For_Json_Object()
2626
{
2727
// Arrange
28+
var options = new HttpClientInterceptorOptions();
29+
2830
var builder = new HttpRequestInterceptionBuilder()
2931
.Requests().ForGet().ForHttps().ForHost("public.je-apis.com").ForPath("terms")
30-
.Responds().WithJsonContent(new { Id = 1, Link = "https://www.just-eat.co.uk/privacy-policy" });
31-
32-
var options = new HttpClientInterceptorOptions()
33-
.Register(builder);
32+
.Responds().WithJsonContent(new { Id = 1, Link = "https://www.just-eat.co.uk/privacy-policy" })
33+
.RegisterWith(options);
3434

3535
string json;
3636

0 commit comments

Comments
 (0)