mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-03-23 01:29:05 +01:00
Fix unit-tests
This commit is contained in:
@@ -6,7 +6,7 @@ namespace WireMock.Http
|
||||
/// <summary>
|
||||
/// The ports.
|
||||
/// </summary>
|
||||
public static class Ports
|
||||
public static class PortUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// The find free TCP port.
|
||||
@@ -1,7 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Validation;
|
||||
|
||||
namespace WireMock.Http
|
||||
{
|
||||
@@ -24,20 +27,43 @@ namespace WireMock.Http
|
||||
/// </value>
|
||||
public bool IsStarted { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The urls.
|
||||
/// </value>
|
||||
public List<Uri> Urls { get; } = new List<Uri>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ports.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The ports.
|
||||
/// </value>
|
||||
public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TinyHttpServer"/> class.
|
||||
/// </summary>
|
||||
/// <param name="urls">The urls.</param>
|
||||
/// <param name="uriPrefixes">The uriPrefixes.</param>
|
||||
/// <param name="httpHandler">The http handler.</param>
|
||||
public TinyHttpServer(string[] urls, Action<HttpListenerContext> httpHandler)
|
||||
public TinyHttpServer([NotNull] Action<HttpListenerContext> httpHandler, [NotNull] params string[] uriPrefixes)
|
||||
{
|
||||
Check.NotNull(httpHandler, nameof(httpHandler));
|
||||
Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
_httpHandler = httpHandler;
|
||||
|
||||
// Create a listener.
|
||||
_listener = new HttpListener();
|
||||
foreach (string urlPrefix in urls)
|
||||
foreach (string uriPrefix in uriPrefixes)
|
||||
{
|
||||
_listener.Prefixes.Add(urlPrefix);
|
||||
var uri = new Uri(uriPrefix);
|
||||
Urls.Add(uri);
|
||||
Ports.Add(uri.Port);
|
||||
|
||||
_listener.Prefixes.Add(uriPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
{
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace WireMock.ResponseBuilders
|
||||
|
||||
@@ -32,6 +32,14 @@ namespace WireMock.Server
|
||||
|
||||
private TimeSpan _requestProcessingDelay = TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the ports.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The ports.
|
||||
/// </value>
|
||||
public List<int> Ports { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the urls.
|
||||
/// </summary>
|
||||
@@ -77,7 +85,7 @@ namespace WireMock.Server
|
||||
Check.Condition(port, p => p >= 0, nameof(port));
|
||||
|
||||
if (port == 0)
|
||||
port = Ports.FindFreeTcpPort();
|
||||
port = PortUtil.FindFreeTcpPort();
|
||||
|
||||
return new FluentMockServer(false, port, ssl);
|
||||
}
|
||||
@@ -107,7 +115,7 @@ namespace WireMock.Server
|
||||
Check.Condition(port, p => p >= 0, nameof(port));
|
||||
|
||||
if (port == 0)
|
||||
port = Ports.FindFreeTcpPort();
|
||||
port = PortUtil.FindFreeTcpPort();
|
||||
|
||||
return new FluentMockServer(true, port, ssl);
|
||||
}
|
||||
@@ -133,7 +141,9 @@ namespace WireMock.Server
|
||||
{
|
||||
Urls = urls;
|
||||
|
||||
_httpServer = new TinyHttpServer(urls, HandleRequestAsync);
|
||||
_httpServer = new TinyHttpServer(HandleRequestAsync, urls);
|
||||
Ports = _httpServer.Ports;
|
||||
|
||||
_httpServer.Start();
|
||||
|
||||
if (startAdminInterface)
|
||||
@@ -142,7 +152,6 @@ namespace WireMock.Server
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Stop this server.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.0.0.0",
|
||||
"version": "1.0.1.0",
|
||||
"title": "WireMock.Net",
|
||||
"description": "Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.",
|
||||
"authors": [ "Alexandre Victoor", "Stef Heyenrath" ],
|
||||
@@ -15,7 +15,7 @@
|
||||
"projectUrl": "https://github.com/StefH/WireMock.Net",
|
||||
"iconUrl": "https://raw.githubusercontent.com/StefH/WireMock.Net/master/WireMock.Net-Logo.png",
|
||||
"licenseUrl": "https://raw.githubusercontent.com/StefH/WireMock.Net/master/LICENSE",
|
||||
"releaseNotes": "First version"
|
||||
"releaseNotes": "Added Admin-Interface"
|
||||
},
|
||||
|
||||
"buildOptions": {
|
||||
|
||||
Reference in New Issue
Block a user