mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-07-07 05:15:17 +02:00
Fix WithBody when using Pact and added more nullable annotations (#783)
* More nullable annotations * . * . * FIX * pact * . * p * xxx * ... * auth * array * ...
This commit is contained in:
@@ -13,7 +13,7 @@ namespace WireMock.Net.Tests.Util;
|
||||
public class JsonUtilsTests
|
||||
{
|
||||
[Fact]
|
||||
public void JsonUtils_ParseJTokenToObject()
|
||||
public void JsonUtils_ParseJTokenToObject_For_String()
|
||||
{
|
||||
// Assign
|
||||
object value = "test";
|
||||
@@ -22,7 +22,33 @@ public class JsonUtilsTests
|
||||
string result = JsonUtils.ParseJTokenToObject<string>(value);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsEqualTo(default(string));
|
||||
result.Should().Be("test");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonUtils_ParseJTokenToObject_For_Int()
|
||||
{
|
||||
// Assign
|
||||
object value = 123;
|
||||
|
||||
// Act
|
||||
var result = JsonUtils.ParseJTokenToObject<int>(value);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(123);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonUtils_ParseJTokenToObject_For_Invalid_Throws()
|
||||
{
|
||||
// Assign
|
||||
object value = "{ }";
|
||||
|
||||
// Act
|
||||
Action action = () => JsonUtils.ParseJTokenToObject<int>(value);
|
||||
|
||||
// Assert
|
||||
action.Should().Throw<NotSupportedException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,44 +1,43 @@
|
||||
using NFluent;
|
||||
using NFluent;
|
||||
using System.IO;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class PathUtilsTests
|
||||
{
|
||||
public class PathUtilsTests
|
||||
[Theory]
|
||||
[InlineData(@"subdirectory/MyXmlResponse.xml")]
|
||||
[InlineData(@"subdirectory\MyXmlResponse.xml")]
|
||||
public void PathUtils_CleanPath(string path)
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(@"subdirectory/MyXmlResponse.xml")]
|
||||
[InlineData(@"subdirectory\MyXmlResponse.xml")]
|
||||
public void PathUtils_CleanPath(string path)
|
||||
{
|
||||
// Act
|
||||
var cleanPath = PathUtils.CleanPath(path);
|
||||
// Act
|
||||
var cleanPath = PathUtils.CleanPath(path);
|
||||
|
||||
// Assert
|
||||
Check.That(cleanPath).Equals("subdirectory" + Path.DirectorySeparatorChar + "MyXmlResponse.xml");
|
||||
}
|
||||
// Assert
|
||||
Check.That(cleanPath).Equals("subdirectory" + Path.DirectorySeparatorChar + "MyXmlResponse.xml");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("", "")]
|
||||
[InlineData("a", "a")]
|
||||
[InlineData(@"/", "")]
|
||||
[InlineData(@"//", "")]
|
||||
[InlineData(@"//a", "a")]
|
||||
[InlineData(@"\", "")]
|
||||
[InlineData(@"\\", "")]
|
||||
[InlineData(@"\\a", "a")]
|
||||
public void PathUtils_CleanPath_RemoveLeadingDirectorySeparators(string path, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var cleanPath = PathUtils.CleanPath(path);
|
||||
[Theory]
|
||||
[InlineData(null, null)]
|
||||
[InlineData("", "")]
|
||||
[InlineData("a", "a")]
|
||||
[InlineData(@"/", "")]
|
||||
[InlineData(@"//", "")]
|
||||
[InlineData(@"//a", "a")]
|
||||
[InlineData(@"\", "")]
|
||||
[InlineData(@"\\", "")]
|
||||
[InlineData(@"\\a", "a")]
|
||||
public void PathUtils_CleanPath_RemoveLeadingDirectorySeparators(string path, string expected)
|
||||
{
|
||||
// Arrange
|
||||
var cleanPath = PathUtils.CleanPath(path);
|
||||
|
||||
// Act
|
||||
var withoutDirectorySeparators = PathUtils.RemoveLeadingDirectorySeparators(cleanPath);
|
||||
// Act
|
||||
var withoutDirectorySeparators = PathUtils.RemoveLeadingDirectorySeparators(cleanPath);
|
||||
|
||||
// Assert
|
||||
Check.That(withoutDirectorySeparators).Equals(expected);
|
||||
}
|
||||
// Assert
|
||||
Check.That(withoutDirectorySeparators).Equals(expected);
|
||||
}
|
||||
}
|
||||
@@ -3,92 +3,92 @@ using NFluent;
|
||||
using WireMock.Util;
|
||||
using Xunit;
|
||||
|
||||
namespace WireMock.Net.Tests.Util
|
||||
namespace WireMock.Net.Tests.Util;
|
||||
|
||||
public class PortUtilsTests
|
||||
{
|
||||
public class PortUtilsTests
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_InvalidUrl_Returns_False()
|
||||
{
|
||||
[Fact]
|
||||
public void PortUtils_TryExtract_InvalidUrl_Returns_False()
|
||||
{
|
||||
// Assign
|
||||
string url = "test";
|
||||
// Assign
|
||||
string url = "test";
|
||||
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
// 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));
|
||||
}
|
||||
// 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";
|
||||
[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);
|
||||
// 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));
|
||||
}
|
||||
// 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";
|
||||
[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);
|
||||
// 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);
|
||||
}
|
||||
// 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";
|
||||
[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);
|
||||
// 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);
|
||||
}
|
||||
// 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";
|
||||
[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);
|
||||
// Act
|
||||
bool result = PortUtils.TryExtract(url, out bool isHttps, out string proto, out string host, out int port);
|
||||
|
||||
// Assert
|
||||
Check.That(result).IsTrue();
|
||||
Check.That(proto).IsEqualTo("https");
|
||||
Check.That(host).IsEqualTo("0.0.0.0");
|
||||
Check.That(port).IsEqualTo(5000);
|
||||
}
|
||||
// Assert
|
||||
result.Should().BeTrue();
|
||||
isHttps.Should().BeTrue();
|
||||
proto.Should().Be("https");
|
||||
host.Should().Be("0.0.0.0");
|
||||
port.Should().Be(5000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user