-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
4 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Ductus.FluentDocker.XUnit/Ductus.FluentDocker.XUnit.csproj
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,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard1.6;net461</TargetFrameworks> | ||
<Version>1.0.0</Version> | ||
<AssemblyVersion>1.0.0.0</AssemblyVersion> | ||
<FileVersion>1.0.0.0</FileVersion> | ||
<VersionSuffix>$(VersionSuffix)</VersionSuffix> | ||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> | ||
<AssemblyTitle>Ductus.FluentDocker.XUnit</AssemblyTitle> | ||
<Authors>Mario Toffia</Authors> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<PackageProjectUrl>https://github.com/mariotoffia/FluentDocker</PackageProjectUrl> | ||
<PackageIconUrl>https://pbs.twimg.com/profile_images/378800000124779041/fbbb494a7eef5f9278c6967b6072ca3e.png</PackageIconUrl> | ||
<PackageId>Ductus.FluentDocker.XUnit</PackageId> | ||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance> | ||
<PackageTags>Docker;Docker-Compose;Docker Compose;Docker-Machine;Docker Machine;Linux;Windows;Mac;Test;NET Core</PackageTags> | ||
<RepositoryType>git</RepositoryType> | ||
<RepositoryUrl>https://github.com/mariotoffia/FluentDocker</RepositoryUrl> | ||
<Description> | ||
XUnit Support to allow for create, run one or more docker images while testing using docker, compose, machine (Linux, Windows, Mac) using netcore or full framework. | ||
Documentation: https://github.com/mariotoffia/FluentDocker | ||
</Description> | ||
<Copyright>© 2016 - 2021 Mario Toffia</Copyright> | ||
<AssemblyOriginatorKeyFile>..\keypair.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Ductus.FluentDocker\Ductus.FluentDocker.csproj" /> | ||
</ItemGroup> | ||
</Project> |
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,59 @@ | ||
using System; | ||
using Ductus.FluentDocker.Builders; | ||
using Ductus.FluentDocker.Services; | ||
|
||
namespace Ductus.FluentDocker.XUnit | ||
{ | ||
public abstract class FluentDockerTestBase : IDisposable | ||
{ | ||
protected IContainerService Container; | ||
|
||
protected abstract ContainerBuilder Build(); | ||
|
||
public FluentDockerTestBase() | ||
{ | ||
Container = Build().Build(); | ||
try | ||
{ | ||
Container.Start(); | ||
} | ||
catch | ||
{ | ||
Container.Dispose(); | ||
throw; | ||
} | ||
|
||
OnContainerInitialized(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
OnContainerTearDown(); | ||
|
||
var c = Container; | ||
Container = null; | ||
try | ||
{ | ||
c?.Dispose(); | ||
} | ||
catch | ||
{ | ||
// Ignore | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Invoked just before the container is teared down. | ||
/// </summary> | ||
protected virtual void OnContainerTearDown() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Invoked after a container has been created and started. | ||
/// </summary> | ||
protected virtual void OnContainerInitialized() | ||
{ | ||
} | ||
} | ||
} |
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,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Ductus.FluentDocker.Builders; | ||
using Ductus.FluentDocker.Services.Extensions; | ||
|
||
namespace Ductus.FluentDocker.XUnit | ||
{ | ||
public abstract class PostgresTestBase : FluentDockerTestBase | ||
{ | ||
protected const string PostgresConnectionString = | ||
"Server={0};Port={1};Userid={2};Password={3};" + | ||
"Pooling=false;MinPoolSize=1;MaxPoolSize=20;" + | ||
"Timeout=15;SslMode=Disable;Database={4}"; | ||
|
||
protected const string PostgresUser = "postgres"; | ||
protected const string PostgresDb = "postgres"; | ||
protected readonly string DockerImage; | ||
protected readonly string PostgresPassword; | ||
|
||
protected string ConnectionString; | ||
|
||
protected PostgresTestBase(string password = "mysecretpassword", string image = "kiasaki/alpine-postgres") | ||
{ | ||
PostgresPassword = password; | ||
DockerImage = image; | ||
} | ||
|
||
protected override ContainerBuilder Build() | ||
{ | ||
return new Builder().UseContainer() | ||
.UseImage("kiasaki/alpine-postgres") | ||
.WithEnvironment($"POSTGRES_PASSWORD={PostgresPassword}") | ||
.ExposePort(5432) | ||
.WaitForPort("5432/tcp", 30000 /*30s*/); | ||
} | ||
|
||
protected override void OnContainerInitialized() | ||
{ | ||
var ep = Container.ToHostExposedEndpoint("5432/tcp"); | ||
ConnectionString = string.Format(PostgresConnectionString, ep.Address, ep.Port, PostgresUser, | ||
PostgresPassword, PostgresDb); | ||
} | ||
} | ||
} |
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