-
Notifications
You must be signed in to change notification settings - Fork 0
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
2 changed files
with
56 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using DotNet.Testcontainers.Builders; | ||
using Greedy.WebApi.Application; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace Greedy.WebTests; | ||
|
||
public class GameApiWebAppFactory : WebApplicationFactory<GameService> { | ||
protected override void ConfigureWebHost(IWebHostBuilder builder) | ||
{ | ||
var environementVariables = new Dictionary<string, string> | ||
{ | ||
{ "EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP", "true" }, | ||
{ "EVENTSTORE_INSECURE", "true" }, | ||
{ "EVENTSTORE_CLUSTER_SIZE", "1" }, | ||
{ "EVENTSTORE_EXT_TCP_PORT", "1113" }, | ||
{ "EVENTSTORE_HTTP_PORT", "2113" }, | ||
{ "EVENTSTORE_ENABLE_EXTERNAL_TCP", "true" }, | ||
{ "EVENTSTORE_RUN_PROJECTIONS", "all" }, | ||
{ "EVENTSTORE_START_STANDARD_PROJECTIONS", "true" }, | ||
{ "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" }, | ||
{ "ASPNETCORE_URLS", "http://+:80" }, | ||
{ "DOTNET_RUNNING_IN_CONTAINER", "true" } | ||
}; | ||
new ContainerBuilder() | ||
.WithImage("ghcr.io/eventstore/eventstore:21.10.0-alpha-arm64v8") | ||
.WithPortBinding(1113) | ||
.WithPortBinding(2113) | ||
.WithEnvironment(environementVariables) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(2113))) | ||
.WithAutoRemove(false).Build() | ||
.StartAsync() | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
base.ConfigureWebHost(builder); | ||
} | ||
} |
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,18 @@ | ||
using System.Net.Http.Json; | ||
using FluentAssertions; | ||
|
||
namespace Greedy.WebTests; | ||
|
||
public static class HttpClientExtensions { | ||
public static async Task<HttpResponseMessage> PostAndEnsureOkStatusCode(this HttpClient client, string route, | ||
object body) | ||
{ | ||
var result = await client.PostAsJsonAsync(route, body); | ||
string content = await result.Content.ReadAsStringAsync(); | ||
|
||
result.IsSuccessStatusCode.Should(). | ||
BeTrue($"Status code returned was: {result.StatusCode}, with reason: {result.ReasonPhrase} {content}"); | ||
|
||
return result; | ||
} | ||
} |