Skip to content

Commit

Permalink
refactor(#493): Replace module extension methods with module API (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Jan 20, 2023
1 parent 9614bb7 commit b709f99
Show file tree
Hide file tree
Showing 157 changed files with 3,143 additions and 2,659 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
"settings": {
"omnisharp.path": "latest" // https://github.com/OmniSharp/omnisharp-vscode/issues/5410#issuecomment-1284531542.
},
"postCreateCommand": "git lfs pull",
"postStartCommand": "dotnet build"
"postCreateCommand": ["git", "lfs", "pull"],
"postStartCommand": ["dotnet", "build"]
}
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup>
<NoWarn>CA1716,CS1591,SA0001,SA1600,SA1633</NoWarn>
<NoWarn>CA1716,CS1591,SA0001,SA1402,SA1600,SA1633,SA1649,CS0618</NoWarn>
</PropertyGroup>
<ItemGroup>
<None Include="$(SolutionDir)docs/banner.png" Visible="false" Pack="true" PackagePath="docs/" />
Expand Down
1 change: 1 addition & 0 deletions Testcontainers.dic
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ sqlplus
testcontainer
testcontainers
tlsverify
vstest
1 change: 1 addition & 0 deletions Testcontainers.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=testcontainer/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=testcontainers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tlsverify/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=vstest/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertToUsingDeclaration/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UseAwaitUsing/@EntryIndexedValue">DO_NOT_SHOW</s:String>
Expand Down
3 changes: 1 addition & 2 deletions docs/api/create_docker_container.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ Assert.Equal(MagicNumber, magicNumber);
| `WithCleanUp` | Will remove the container automatically after all tests have been run. |
| `WithLabel` | Applies metadata to the container e.g. `-l`, `--label "testcontainers=awesome"`. |
| `WithResourceReaperSessionId` | Assigns a Resource Reaper session id to the container. The assigned Resource Reaper takes care of the cleanup. |
| `WithRegistryAuthentication` | Sets the basic authentication credentials for accessing a private Docker registry. |
| `WithImage` | Specifies an image for which to create the container. |
| `WithImagePullPolicy` | Specifies an image pull policy to determine when an image is pulled e.g. <code>--pull "always" &vert; "missing" &vert; "never"</code>. |
| `WithName` | Sets the container name e.g. `--name "testcontainers"`. |
Expand All @@ -120,10 +119,10 @@ Assert.Equal(MagicNumber, magicNumber);
| `WithNetwork` | Assigns a network to the container e.g. `--network "bridge"`. |
| `WithNetworkAliases` | Assigns a network-scoped aliases to the container e.g. `--network-alias "alias"`. |
| `WithPrivileged` | Sets the `--privileged` flag. |
| `WithCreateContainerParametersModifier` | Allows low level modifications of the Docker container create parameter. |
| `WithOutputConsumer` | Redirects `stdout` and `stderr` to capture the container output. |
| `WithWaitStrategy` | Sets the wait strategy to complete the container start and indicates when it is ready. |
| `WithStartupCallback` | Sets the startup callback to invoke after the container start. |
| `WithCreateContainerParametersModifier` | Allows low level modifications of the Docker container create parameter. |

!!!tip

Expand Down
197 changes: 197 additions & 0 deletions src/Testcontainers/BackwardCompatibility/BackwardsCompatibility.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#pragma warning disable SA1403

namespace DotNet.Testcontainers
{
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

namespace Containers
{
[PublicAPI]
[Obsolete("Use the IContainer interface instead.")]
public interface ITestcontainersContainer : IDockerContainer
{
}

[PublicAPI]
[Obsolete("Use the IContainer interface instead.")]
public interface IDockerContainer : IAsyncDisposable
{
[NotNull]
ILogger Logger { get; }

[NotNull]
string Id { get; }

[NotNull]
string Name { get; }

[NotNull]
string IpAddress { get; }

[NotNull]
string MacAddress { get; }

[NotNull]
string Hostname { get; }

[NotNull]
IImage Image { get; }

TestcontainersStates State { get; }

TestcontainersHealthStatus Health { get; }

long HealthCheckFailingStreak { get; }

ushort GetMappedPublicPort(int containerPort);

ushort GetMappedPublicPort(string containerPort);

Task<long> GetExitCode(CancellationToken ct = default);

Task<(string Stdout, string Stderr)> GetLogs(DateTime since = default, DateTime until = default, CancellationToken ct = default);

Task StartAsync(CancellationToken ct = default);

Task StopAsync(CancellationToken ct = default);

Task CopyFileAsync(string filePath, byte[] fileContent, int accessMode = 384, int userId = 0, int groupId = 0, CancellationToken ct = default);

Task<byte[]> ReadFileAsync(string filePath, CancellationToken ct = default);

Task<ExecResult> ExecAsync(IList<string> command, CancellationToken ct = default);
}

[PublicAPI]
[Obsolete("Use the DockerContainer class instead.")]
public sealed class TestcontainersContainer : DockerContainer
{
internal TestcontainersContainer(IContainerConfiguration configuration, ILogger logger)
: base(configuration, logger)
{
}
}
}

namespace Images
{
[PublicAPI]
[Obsolete("Use the IImage interface instead.")]
public interface IDockerImage
{
[NotNull]
string Repository { get; }

[NotNull]
string Name { get; }

[NotNull]
string Tag { get; }

[NotNull]
string FullName { get; }

[CanBeNull]
string GetHostname();
}

/// <summary>
/// Maps the old to the new interface to provide backwards compatibility.
/// </summary>
public sealed partial class DockerImage
{
public DockerImage(IDockerImage image)
: this(image.Repository, image.Name, image.Tag)
{
}
}
}

namespace Networks
{
[PublicAPI]
[Obsolete("Use the INetwork interface instead.")]
public interface IDockerNetwork
{
[NotNull]
string Id { get; }

[NotNull]
string Name { get; }

Task CreateAsync(CancellationToken ct = default);

Task DeleteAsync(CancellationToken ct = default);
}

/// <summary>
/// Maps the old to the new interface to provide backwards compatibility.
/// </summary>
internal sealed partial class DockerNetwork
{
public DockerNetwork(IDockerNetwork network)
{
this.network.ID = network.Id;
this.network.Name = network.Name;
}
}
}

namespace Volumes
{
[PublicAPI]
[Obsolete("Use the IVolume interface instead.")]
public interface IDockerVolume
{
[NotNull]
string Name { get; }

Task CreateAsync(CancellationToken ct = default);

Task DeleteAsync(CancellationToken ct = default);
}

/// <summary>
/// Maps the old to the new interface to provide backwards compatibility.
/// </summary>
internal sealed partial class DockerVolume
{
public DockerVolume(IDockerVolume volume)
{
this.volume.Name = volume.Name;
}
}
}

namespace Builders
{
[PublicAPI]
[Obsolete("Use the ContainerBuilder class instead.")]
public sealed class TestcontainersBuilder<TContainerEntity> : ContainerBuilder<TContainerEntity>
where TContainerEntity : DockerContainer
{
}

[PublicAPI]
[Obsolete("Use the NetworkBuilder class instead.")]
public sealed class TestcontainersNetworkBuilder : NetworkBuilder
{
}

[PublicAPI]
[Obsolete("Use the VolumeBuilder class instead.")]
public sealed class TestcontainersVolumeBuilder : VolumeBuilder
{
}
}
}

#pragma warning restore SA1403
76 changes: 0 additions & 76 deletions src/Testcontainers/Builders/AbstractBuilder.cs

This file was deleted.

Loading

0 comments on commit b709f99

Please sign in to comment.