From 90a300675660f6109e68ab61ea48de4b232936a7 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Fri, 28 Apr 2023 13:13:31 +0200 Subject: [PATCH] chore: Remove minor Sonar findings --- .../Builders/AbstractBuilder`4.cs | 3 +- .../Containers/PortForwarding.cs | 33 +------------------ .../PortForwardingTest.cs | 4 +-- 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/Testcontainers/Builders/AbstractBuilder`4.cs b/src/Testcontainers/Builders/AbstractBuilder`4.cs index 30df84c4b..27d5828db 100644 --- a/src/Testcontainers/Builders/AbstractBuilder`4.cs +++ b/src/Testcontainers/Builders/AbstractBuilder`4.cs @@ -26,13 +26,12 @@ public abstract class AbstractBuilder /// Gets the Docker resource configuration. /// - protected virtual TConfigurationEntity DockerResourceConfiguration { get; } + protected abstract TConfigurationEntity DockerResourceConfiguration { get; } /// public TBuilderEntity WithDockerEndpoint(string endpoint) diff --git a/src/Testcontainers/Containers/PortForwarding.cs b/src/Testcontainers/Containers/PortForwarding.cs index 3c8005a5f..16d8a169a 100644 --- a/src/Testcontainers/Containers/PortForwarding.cs +++ b/src/Testcontainers/Containers/PortForwarding.cs @@ -1,7 +1,5 @@ namespace DotNet.Testcontainers.Containers { - using System.Collections.Generic; - using System.Globalization; using System.Linq; using System.Net; using System.Threading.Tasks; @@ -97,26 +95,6 @@ private PortForwardingBuilder(PortForwardingConfiguration resourceConfiguration) /// protected override PortForwardingConfiguration DockerResourceConfiguration { get; } - /// - /// Exposes the host ports using SSH port forwarding. - /// - /// The host ports to forward. - /// A configured instance of . - public PortForwardingBuilder WithExposedHostPort(params int[] ports) - { - return WithExposedHostPort(ports.Select(port => port.ToString(CultureInfo.InvariantCulture)).ToArray()); - } - - /// - /// Exposes the host ports to containers in the same network. - /// - /// The host ports. - /// A configured instance of . - public PortForwardingBuilder WithExposedHostPort(params string[] exposedHostPorts) - { - return Merge(DockerResourceConfiguration, new PortForwardingConfiguration(exposedHostPorts: exposedHostPorts)); - } - /// public override PortForwardingContainer Build() { @@ -187,15 +165,12 @@ public sealed class PortForwardingConfiguration : ContainerConfiguration /// /// The OpenSSH daemon username. /// The OpenSSH daemon password. - /// A list of exposed host ports. public PortForwardingConfiguration( string username = null, - string password = null, - IEnumerable exposedHostPorts = null) + string password = null) { Username = username; Password = password; - ExposedHostPorts = exposedHostPorts; } /// @@ -238,7 +213,6 @@ public PortForwardingConfiguration(PortForwardingConfiguration oldValue, PortFor { Username = BuildConfiguration.Combine(oldValue.Username, newValue.Username); Password = BuildConfiguration.Combine(oldValue.Password, newValue.Password); - ExposedHostPorts = BuildConfiguration.Combine(oldValue.ExposedHostPorts, newValue.ExposedHostPorts); } /// @@ -250,11 +224,6 @@ public PortForwardingConfiguration(PortForwardingConfiguration oldValue, PortFor /// Gets the OpenSSH daemon password. /// public string Password { get; } - - /// - /// Gets a list of exposed host ports. - /// - public IEnumerable ExposedHostPorts { get; } } } } diff --git a/tests/Testcontainers.Platform.Linux.Tests/PortForwardingTest.cs b/tests/Testcontainers.Platform.Linux.Tests/PortForwardingTest.cs index e87bf559e..cd9db73e2 100644 --- a/tests/Testcontainers.Platform.Linux.Tests/PortForwardingTest.cs +++ b/tests/Testcontainers.Platform.Linux.Tests/PortForwardingTest.cs @@ -67,9 +67,9 @@ public PortForwardingNetworkConfiguration(HostedService fixture) [UsedImplicitly] public sealed class HostedService : IAsyncLifetime { - private readonly CancellationTokenSource _cancellationTokenSource = new(); + private readonly CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource(); - private readonly TcpListener _tcpListener = new(new IPEndPoint(IPAddress.Any, 0)); + private readonly TcpListener _tcpListener = new TcpListener(new IPEndPoint(IPAddress.Any, 0)); public HostedService() {