-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
97 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
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"; | ||
string proto = "x"; | ||
string host = "h"; | ||
int port = 1; | ||
|
||
// Act | ||
var result = PortUtils.TryExtract(url, out proto, out host, out port); | ||
|
||
// Assert | ||
Check.That(result).IsFalse(); | ||
Check.That(proto).IsNull(); | ||
Check.That(host).IsNull(); | ||
Check.That(port).IsEqualTo(default(int)); | ||
} | ||
|
||
[Fact] | ||
public void PortUtils_TryExtract_UrlIsMissingPort_Returns_False() | ||
{ | ||
// Assign | ||
string url = "http://0.0.0.0"; | ||
string proto = "x"; | ||
string host = "h"; | ||
int port = 1; | ||
|
||
// Act | ||
var result = PortUtils.TryExtract(url, out proto, out host, out port); | ||
|
||
// Assert | ||
Check.That(result).IsFalse(); | ||
Check.That(proto).IsNull(); | ||
Check.That(host).IsNull(); | ||
Check.That(port).IsEqualTo(default(int)); | ||
} | ||
|
||
[Fact] | ||
public void PortUtils_TryExtract_ValidUrl1_Returns_True() | ||
{ | ||
// Assign | ||
string url = "https://wiremock.net:5000"; | ||
string proto = "x"; | ||
string host = "h"; | ||
int port = 1; | ||
|
||
// Act | ||
var result = PortUtils.TryExtract(url, out proto, out host, out port); | ||
|
||
// Assert | ||
Check.That(result).IsTrue(); | ||
Check.That(proto).IsEqualTo("https"); | ||
Check.That(host).IsEqualTo("wiremock.net"); | ||
Check.That(port).IsEqualTo(5000); | ||
} | ||
|
||
[Fact] | ||
public void PortUtils_TryExtract_ValidUrl2_Returns_True() | ||
{ | ||
// Assign | ||
string url = "https://0.0.0.0:5000"; | ||
string proto = "x"; | ||
string host = "h"; | ||
int port = 1; | ||
|
||
// Act | ||
var result = PortUtils.TryExtract(url, out proto, out host, out port); | ||
|
||
// Assert | ||
Check.That(result).IsTrue(); | ||
Check.That(proto).IsEqualTo("https"); | ||
Check.That(host).IsEqualTo("0.0.0.0"); | ||
Check.That(port).IsEqualTo(5000); | ||
} | ||
} | ||
} |