-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
159 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace FluentRest.Tests.GitHub; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Xunit; | ||
|
||
namespace FluentRest.Tests; | ||
|
||
[CollectionDefinition(CollectionName)] | ||
public class HostCollection : ICollectionFixture<HostFixture> | ||
{ | ||
public const string CollectionName = nameof(HostCollection); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
using DotNet.Testcontainers.Builders; | ||
|
||
using FluentRest.Tests.GitHub; | ||
|
||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
using Xunit; | ||
|
||
using XUnit.Hosting; | ||
|
||
using IContainer = DotNet.Testcontainers.Containers.IContainer; | ||
|
||
namespace FluentRest.Tests; | ||
|
||
public class HostFixture : TestApplicationFixture, IAsyncLifetime | ||
{ | ||
private readonly IContainer _container = new ContainerBuilder() | ||
.WithImage("kennethreitz/httpbin:latest") | ||
.WithPortBinding(80, true) | ||
.Build(); | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
await _container.StartAsync(); | ||
|
||
// get container url | ||
HttpBinUrl = $"http://{_container.Hostname}:{_container.GetMappedPublicPort(80)}"; | ||
} | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
await _container.DisposeAsync(); | ||
} | ||
|
||
public string HttpBinUrl { get; private set; } = "https://httpbin.org/"; | ||
|
||
protected override void ConfigureApplication(HostApplicationBuilder builder) | ||
{ | ||
base.ConfigureApplication(builder); | ||
|
||
builder.Services | ||
.TryAddSingleton<IContentSerializer, JsonContentSerializer>(); | ||
|
||
builder.Services | ||
.AddHttpClient<GithubClient>(c => | ||
{ | ||
c.BaseAddress = new Uri("https://api.github.com/"); | ||
|
||
c.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json"); | ||
c.DefaultRequestHeaders.Add("User-Agent", "GitHubClient"); | ||
}) | ||
.AddHttpMessageHandler(() => new RetryHandler()); | ||
|
||
builder.Services | ||
.AddHttpClient("GoogleMaps", client => client.BaseAddress = new Uri("https://maps.googleapis.com/maps/api/", UriKind.Absolute)); | ||
|
||
builder.Services | ||
.AddHttpClient("HttpBin", client => client.BaseAddress = new Uri(HttpBinUrl, UriKind.Absolute)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
using XUnit.Hosting; | ||
|
||
namespace FluentRest.Tests; | ||
|
||
[Collection(HostCollection.CollectionName)] | ||
public abstract class HostTestBase : TestHostBase<HostFixture> | ||
{ | ||
protected HostTestBase(ITestOutputHelper output, HostFixture fixture) | ||
: base(output, fixture) | ||
{ | ||
} | ||
} |
Oops, something went wrong.