Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Testcontainers/Containers/DockerContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ await _configuration.StartupCallback(this, ct)

Logger.CompleteReadinessCheck(_container.ID);

StartedTime = DateTime.TryParse(_container.State.StartedAt, null, DateTimeStyles.AdjustToUniversal, out var startedTime) ? startedTime : DateTime.UtcNow;
StartedTime = DateTime.TryParse(_container.State.StartedAt, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var startedTime) ? startedTime : DateTime.UtcNow;
Started?.Invoke(this, EventArgs.Empty);
}

Expand Down Expand Up @@ -556,7 +556,7 @@ await _client.StopAsync(_container.ID, ct)
_container = new ContainerInspectResponse();
}

StoppedTime = DateTime.TryParse(_container.State.FinishedAt, null, DateTimeStyles.AdjustToUniversal, out var stoppedTime) ? stoppedTime : DateTime.UtcNow;
StoppedTime = DateTime.TryParse(_container.State.FinishedAt, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out var stoppedTime) ? stoppedTime : DateTime.UtcNow;
Stopped?.Invoke(this, EventArgs.Empty);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,91 @@ namespace Testcontainers.Tests;

public sealed class ExecFailedExceptionTest
{
public static readonly List<TheoryDataRow<ExecResult, string>> ExecResultTestData
= new List<TheoryDataRow<ExecResult, string>>
public static TheoryData<ExecResultSerializable, string> ExecResultTestData { get; }
= new TheoryData<ExecResultSerializable, string>
{
new TheoryDataRow<ExecResult, string>
(
new ExecResult("Stdout\nStdout", "Stderr\nStderr", 1),
{
new ExecResultSerializable("Stdout\nStdout", "Stderr\nStderr", 1),
"Process exited with code 1." + Environment.NewLine +
" Stdout: " + Environment.NewLine +
" Stdout" + Environment.NewLine +
" Stdout" + Environment.NewLine +
" Stderr: " + Environment.NewLine +
" Stderr" + Environment.NewLine +
" Stderr"
),
new TheoryDataRow<ExecResult, string>
(
new ExecResult("Stdout\nStdout", string.Empty, 1),
},
{
new ExecResultSerializable("Stdout\nStdout", string.Empty, 1),
"Process exited with code 1." + Environment.NewLine +
" Stdout: " + Environment.NewLine +
" Stdout" + Environment.NewLine +
" Stdout"
),
new TheoryDataRow<ExecResult, string>
(
new ExecResult(string.Empty, "Stderr\nStderr", 1),
},
{
new ExecResultSerializable(string.Empty, "Stderr\nStderr", 1),
"Process exited with code 1." + Environment.NewLine +
" Stderr: " + Environment.NewLine +
" Stderr" + Environment.NewLine +
" Stderr"
),
new TheoryDataRow<ExecResult, string>
(
new ExecResult(string.Empty, string.Empty, 1),
},
{
new ExecResultSerializable(string.Empty, string.Empty, 1),
"Process exited with code 1."
),
},
};

[Theory]
[MemberData(nameof(ExecResultTestData))]
public void ExecFailedExceptionCreatesExpectedMessage(ExecResult execResult, string message)
public void ExecFailedExceptionCreatesExpectedMessage(ExecResultSerializable serializable, string message)
{
// Given
var execResult = serializable.ToExecResult();

// When
var exception = new ExecFailedException(execResult);

// Then
Assert.Equal(execResult, exception.ExecResult);
Assert.Equal(message, exception.Message);
}

[PublicAPI]
public sealed class ExecResultSerializable : IXunitSerializable
{
private string _stdout;

private string _stderr;

private int _exitCode;

public ExecResultSerializable()
{
}

public ExecResultSerializable(string stdout, string stderr, int exitCode)
{
_stdout = stdout;
_stderr = stderr;
_exitCode = exitCode;
}

public ExecResult ToExecResult()
{
return new ExecResult(_stdout, _stderr, _exitCode);
}

public void Deserialize(IXunitSerializationInfo info)
{
_stdout = info.GetValue<string>(nameof(_stdout));
_stderr = info.GetValue<string>(nameof(_stderr));
_exitCode = info.GetValue<int>(nameof(_exitCode));
}

public void Serialize(IXunitSerializationInfo info)
{
info.AddValue(nameof(_stdout), _stdout);
info.AddValue(nameof(_stderr), _stderr);
info.AddValue(nameof(_exitCode), _exitCode);
}
}
}
3 changes: 2 additions & 1 deletion tests/Testcontainers.Platform.Linux.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
global using Microsoft.Extensions.Logging.Abstractions;
global using Microsoft.Extensions.Logging.Testing;
global using ReflectionMagic;
global using Xunit;
global using Xunit;
global using Xunit.Sdk;