diff --git a/Ductus.FluentDocker.Tests/FluentApiTests/FluentContainerBasicTests.cs b/Ductus.FluentDocker.Tests/FluentApiTests/FluentContainerBasicTests.cs index 5aae447..8ad94a2 100644 --- a/Ductus.FluentDocker.Tests/FluentApiTests/FluentContainerBasicTests.cs +++ b/Ductus.FluentDocker.Tests/FluentApiTests/FluentContainerBasicTests.cs @@ -191,6 +191,40 @@ public void ImplicitPortMappingShouldWork() } } + [TestMethod] + [TestCategory("CI")] + public void FullImplicitPortMappingShouldWork() + { + using ( + var container = + Fd.UseContainer() + .UseImage("postgres:9.6-alpine") + .ExposeAllPorts() + .WithEnvironment("POSTGRES_PASSWORD=mysecretpassword") + .Build() + .Start()) + { + var endpoint = container.ToHostExposedEndpoint("5432/tcp"); + AreNotEqual(0, endpoint.Port); + } + } + + [TestMethod] + [TestCategory("CI")] + public void ExposeAllPortsIsMutuallyExclusiveWithExposePort() + { + var exception = ThrowsException(() => Fd.UseContainer().ExposePort(5432).ExposeAllPorts()); + AreEqual("ExposeAllPorts is mutually exclusive with ExposePort methods. Do not call ExposePort if you want to expose all ports.", exception.Message); + } + + [TestMethod] + [TestCategory("CI")] + public void ExposePortIsMutuallyExclusiveWithExposeAllPorts() + { + var exception = ThrowsException(() => Fd.UseContainer().ExposeAllPorts().ExposePort(5432)); + AreEqual("ExposePort is mutually exclusive with ExposeAllPorts methods. Do not call ExposeAllPorts if you want to explicitly expose ports.", exception.Message); + } + [TestMethod] [TestCategory("CI")] public void WaitForPortShallWork() diff --git a/Ductus.FluentDocker/Builders/ContainerBuilder.cs b/Ductus.FluentDocker/Builders/ContainerBuilder.cs index 1b4c024..917312f 100644 --- a/Ductus.FluentDocker/Builders/ContainerBuilder.cs +++ b/Ductus.FluentDocker/Builders/ContainerBuilder.cs @@ -358,7 +358,7 @@ private void EnsurePublishAllPortsIsFalse() private void EnsurePortMappingsIsEmpty() { - if (_config.CreateParams.PortMappings.Any()) + if (_config.CreateParams.PortMappings?.Any() == true) { throw new FluentDockerNotSupportedException($"{nameof(ExposeAllPorts)} is mutually exclusive with {nameof(ExposePort)} methods. " + $"Do not call {nameof(ExposePort)} if you want to expose all ports.");