Files
WireMock.Net/test/WireMock.Net.Tests/Util/PortUtilsTests.cs
Stef Heyenrath d2a1d0f069 Fix WithBody when using Pact and added more nullable annotations (#783)
* More nullable annotations

* .

* .

* FIX

* pact

* .

* p

* xxx

* ...

* auth

* array

* ...
2022-08-11 10:57:33 +02:00

94 lines
2.5 KiB
C#

using FluentAssertions;
using NFluent;
using WireMock.Util;
using Xunit;
namespace WireMock.Net.Tests.Util;
public class PortUtilsTests
{
[Fact]
public void PortUtils_TryExtract_InvalidUrl_Returns_False()
{
// Assign
string url = "test";
// Act
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
// Assert
result.Should().BeFalse();
isHttps.Should().BeFalse();
proto.Should().BeNull();
host.Should().BeNull();
port.Should().Be(default(int));
}
[Fact]
public void PortUtils_TryExtract_UrlIsMissingPort_Returns_False()
{
// Assign
string url = "http://0.0.0.0";
// Act
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
// Assert
result.Should().BeFalse();
isHttps.Should().BeFalse();
proto.Should().BeNull();
host.Should().BeNull();
port.Should().Be(default(int));
}
[Fact]
public void PortUtils_TryExtract_Http_Returns_True()
{
// Assign
string url = "http://wiremock.net:1234";
// Act
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
// Assert
result.Should().BeTrue();
isHttps.Should().BeFalse();
proto.Should().Be("http");
host.Should().Be("wiremock.net");
port.Should().Be(1234);
}
[Fact]
public void PortUtils_TryExtract_Https_Returns_True()
{
// Assign
string url = "https://wiremock.net:5000";
// Act
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
// Assert
result.Should().BeTrue();
isHttps.Should().BeTrue();
proto.Should().Be("https");
host.Should().Be("wiremock.net");
port.Should().Be(5000);
}
[Fact]
public void PortUtils_TryExtract_Https0_0_0_0_Returns_True()
{
// Assign
string url = "https://0.0.0.0:5000";
// Act
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
// Assert
result.Should().BeTrue();
isHttps.Should().BeTrue();
proto.Should().Be("https");
host.Should().Be("0.0.0.0");
port.Should().Be(5000);
}
}