mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-02-25 10:15:04 +01:00
Cleanup some files
This commit is contained in:
@@ -1,65 +0,0 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.IO;
|
||||
//using System.Linq;
|
||||
//using System.Net;
|
||||
//using System.Text;
|
||||
//#if NET45
|
||||
|
||||
//#else
|
||||
//using System.Net.Http;
|
||||
//#endif
|
||||
|
||||
//namespace WireMock.Http
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// The http listener request mapper.
|
||||
// /// </summary>
|
||||
// public class HttpListenerRequestMapperOld
|
||||
// {
|
||||
// /// <summary>
|
||||
// /// The map.
|
||||
// /// </summary>
|
||||
// /// <param name="listenerRequest">The listener request.</param>
|
||||
// /// <returns>The <see cref="RequestMessage"/>.</returns>
|
||||
// public RequestMessage MapAsync(HttpListenerRequest listenerRequest)
|
||||
// {
|
||||
// Uri url = listenerRequest.Url;
|
||||
// string verb = listenerRequest.HttpMethod;
|
||||
// byte[] body = GetRequestBody(listenerRequest);
|
||||
// Encoding bodyEncoding = body != null ? listenerRequest.ContentEncoding : null;
|
||||
// string bodyAsString = bodyEncoding?.GetString(body);
|
||||
// var listenerHeaders = listenerRequest.Headers;
|
||||
// var headers = listenerHeaders.AllKeys.ToDictionary(k => k, k => listenerHeaders[k]);
|
||||
// var cookies = new Dictionary<string, string>();
|
||||
|
||||
// foreach (Cookie cookie in listenerRequest.Cookies)
|
||||
// cookies.Add(cookie.Name, cookie.Value);
|
||||
|
||||
// return new RequestMessage(url, verb, body, bodyAsString, bodyEncoding, headers, cookies) { DateTime = DateTime.Now };
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// The get request body.
|
||||
// /// </summary>
|
||||
// /// <param name="request">The request.</param>
|
||||
// /// <returns>The <see cref="string"/>.</returns>
|
||||
// private byte[] GetRequestBody(HttpListenerRequest request)
|
||||
// {
|
||||
// if (!request.HasEntityBody)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
// using (var bodyStream = request.InputStream)
|
||||
// {
|
||||
// using (var memoryStream = new MemoryStream())
|
||||
// {
|
||||
// bodyStream.CopyTo(memoryStream);
|
||||
|
||||
// return memoryStream.ToArray();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -1,44 +0,0 @@
|
||||
//using System.Linq;
|
||||
//using System.Net;
|
||||
//using System.Text;
|
||||
//#if NET45
|
||||
|
||||
//#else
|
||||
//using System.Net.Http;
|
||||
//#endif
|
||||
|
||||
//namespace WireMock.Http
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// The http listener response mapper.
|
||||
// /// </summary>
|
||||
// public class HttpListenerResponseMapperOld
|
||||
// {
|
||||
// private readonly Encoding _utf8NoBom = new UTF8Encoding(false);
|
||||
|
||||
// /// <summary>
|
||||
// /// The map.
|
||||
// /// </summary>
|
||||
// /// <param name="responseMessage">
|
||||
// /// The response.
|
||||
// /// </param>
|
||||
// /// <param name="listenerResponse">The listenerResponse.</param>
|
||||
// public void MapAsync(ResponseMessage responseMessage, HttpListenerResponse listenerResponse)
|
||||
// {
|
||||
// listenerResponse.StatusCode = responseMessage.StatusCode;
|
||||
|
||||
// responseMessage.Headers.ToList().ForEach(pair => listenerResponse.AddHeader(pair.Key, pair.Value));
|
||||
|
||||
// if (responseMessage.Body == null)
|
||||
// return;
|
||||
|
||||
// var encoding = responseMessage.BodyEncoding ?? _utf8NoBom;
|
||||
// byte[] buffer = encoding.GetBytes(responseMessage.Body);
|
||||
|
||||
// listenerResponse.ContentEncoding = encoding;
|
||||
// listenerResponse.ContentLength64 = buffer.Length;
|
||||
// listenerResponse.OutputStream.Write(buffer, 0, buffer.Length);
|
||||
// listenerResponse.OutputStream.Flush();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -1,117 +0,0 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//#if NET45
|
||||
//using System.Net;
|
||||
//#else
|
||||
//using System.Net.Http;
|
||||
//#endif
|
||||
//using System.Threading;
|
||||
//using System.Threading.Tasks;
|
||||
//using JetBrains.Annotations;
|
||||
//using WireMock.Validation;
|
||||
|
||||
//namespace WireMock.Http
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// The tiny http server.
|
||||
// /// </summary>
|
||||
// public class TinyHttpServerOld
|
||||
// {
|
||||
// private readonly Action<HttpListenerContext, CancellationToken> _httpHandler;
|
||||
|
||||
// private readonly HttpListener _listener;
|
||||
|
||||
// private readonly CancellationTokenSource _cts;
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets a value indicating whether this server is started.
|
||||
// /// </summary>
|
||||
// /// <value>
|
||||
// /// <c>true</c> if this server is started; otherwise, <c>false</c>.
|
||||
// /// </value>
|
||||
// public bool IsStarted { get; private set; }
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets the url.
|
||||
// /// </summary>
|
||||
// /// <value>
|
||||
// /// The urls.
|
||||
// /// </value>
|
||||
// [PublicAPI]
|
||||
// public List<Uri> Urls { get; } = new List<Uri>();
|
||||
|
||||
// /// <summary>
|
||||
// /// Gets the ports.
|
||||
// /// </summary>
|
||||
// /// <value>
|
||||
// /// The ports.
|
||||
// /// </value>
|
||||
// [PublicAPI]
|
||||
// public List<int> Ports { get; } = new List<int>();
|
||||
|
||||
// /// <summary>
|
||||
// /// Initializes a new instance of the <see cref="TinyHttpServer"/> class.
|
||||
// /// </summary>
|
||||
// /// <param name="uriPrefixes">The uriPrefixes.</param>
|
||||
// /// <param name="httpHandler">The http handler.</param>
|
||||
// public TinyHttpServerOld([NotNull] Action<HttpListenerContext, CancellationToken> httpHandler, [NotNull] params string[] uriPrefixes)
|
||||
// {
|
||||
// Check.NotNull(httpHandler, nameof(httpHandler));
|
||||
// Check.NotEmpty(uriPrefixes, nameof(uriPrefixes));
|
||||
|
||||
// _cts = new CancellationTokenSource();
|
||||
|
||||
// _httpHandler = httpHandler;
|
||||
|
||||
// // Create a listener.
|
||||
// _listener = new HttpListener();
|
||||
// foreach (string uriPrefix in uriPrefixes)
|
||||
// {
|
||||
// var uri = new Uri(uriPrefix);
|
||||
// Urls.Add(uri);
|
||||
// Ports.Add(uri.Port);
|
||||
|
||||
// _listener.Prefixes.Add(uriPrefix);
|
||||
// }
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Start the server.
|
||||
// /// </summary>
|
||||
// [PublicAPI]
|
||||
// public void Start()
|
||||
// {
|
||||
// _listener.Start();
|
||||
|
||||
// IsStarted = true;
|
||||
|
||||
// Task.Run(
|
||||
// async () =>
|
||||
// {
|
||||
// //using (_listener)
|
||||
// {
|
||||
// while (!_cts.Token.IsCancellationRequested)
|
||||
// {
|
||||
// HttpListenerContext context = await _listener.GetContextAsync();
|
||||
// _httpHandler(context, _cts.Token);
|
||||
// }
|
||||
|
||||
// _listener.Stop();
|
||||
// IsStarted = false;
|
||||
// }
|
||||
// },
|
||||
// _cts.Token);
|
||||
// }
|
||||
|
||||
// /// <summary>
|
||||
// /// Stop the server.
|
||||
// /// </summary>
|
||||
// [PublicAPI]
|
||||
// public void Stop()
|
||||
// {
|
||||
// _listener?.Stop();
|
||||
|
||||
// _cts.Cancel();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -3,8 +3,6 @@
|
||||
/// <summary>
|
||||
/// The registration callback.
|
||||
/// </summary>
|
||||
/// <param name="mapping">
|
||||
/// The route.
|
||||
/// </param>
|
||||
/// <param name="mapping">The mapping.</param>
|
||||
public delegate void RegistrationCallback(Mapping mapping);
|
||||
}
|
||||
90
src/WireMock.Net/Server/FluentMockServer.LogEntries.cs
Normal file
90
src/WireMock.Net/Server/FluentMockServer.LogEntries.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using JetBrains.Annotations;
|
||||
using WireMock.Logging;
|
||||
using WireMock.Matchers.Request;
|
||||
using System.Linq;
|
||||
|
||||
namespace WireMock.Server
|
||||
{
|
||||
public partial class FluentMockServer
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the request logs.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> LogEntries
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
return new ReadOnlyCollection<LogEntry>(_options.LogEntries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The search log-entries based on matchers.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IEnumerable"/>.</returns>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
var results = new Dictionary<LogEntry, RequestMatchResult>();
|
||||
|
||||
foreach (var log in _options.LogEntries)
|
||||
{
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
foreach (var matcher in matchers)
|
||||
{
|
||||
matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
|
||||
}
|
||||
|
||||
if (requestMatchResult.AverageTotalScore > 0.99)
|
||||
results.Add(log, requestMatchResult);
|
||||
}
|
||||
|
||||
return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the LogEntries.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public void ResetLogEntries()
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
_options.LogEntries.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the mapping.
|
||||
/// </summary>
|
||||
/// <param name="guid">The unique identifier.</param>
|
||||
[PublicAPI]
|
||||
public bool DeleteLogEntry(Guid guid)
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
// Check a logentry exists with the same GUID, if so, remove it.
|
||||
var existing = _options.LogEntries.FirstOrDefault(m => m.Guid == guid);
|
||||
if (existing != null)
|
||||
{
|
||||
_options.LogEntries.Remove(existing);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,49 +41,6 @@ namespace WireMock.Server
|
||||
[PublicAPI]
|
||||
public string[] Urls { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request logs.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> LogEntries
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
return new ReadOnlyCollection<LogEntry>(_options.LogEntries);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The search log-entries based on matchers.
|
||||
/// </summary>
|
||||
/// <param name="matchers">The matchers.</param>
|
||||
/// <returns>The <see cref="IEnumerable"/>.</returns>
|
||||
[PublicAPI]
|
||||
public IEnumerable<LogEntry> FindLogEntries([NotNull] params IRequestMatcher[] matchers)
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
var results = new Dictionary<LogEntry, RequestMatchResult>();
|
||||
|
||||
foreach (var log in _options.LogEntries)
|
||||
{
|
||||
var requestMatchResult = new RequestMatchResult();
|
||||
foreach (var matcher in matchers)
|
||||
{
|
||||
matcher.GetMatchingScore(log.RequestMessage, requestMatchResult);
|
||||
}
|
||||
|
||||
if (requestMatchResult.AverageTotalScore > 0.99)
|
||||
results.Add(log, requestMatchResult);
|
||||
}
|
||||
|
||||
return new ReadOnlyCollection<LogEntry>(results.OrderBy(x => x.Value).Select(x => x.Key).ToList());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the mappings.
|
||||
/// </summary>
|
||||
@@ -271,39 +228,6 @@ namespace WireMock.Server
|
||||
ResetMappings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the LogEntries.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public void ResetLogEntries()
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
_options.LogEntries.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the mapping.
|
||||
/// </summary>
|
||||
/// <param name="guid">The unique identifier.</param>
|
||||
[PublicAPI]
|
||||
public bool DeleteLogEntry(Guid guid)
|
||||
{
|
||||
lock (((ICollection)_options.LogEntries).SyncRoot)
|
||||
{
|
||||
// Check a logentry exists with the same GUID, if so, remove it.
|
||||
var existing = _options.LogEntries.FirstOrDefault(m => m.Guid == guid);
|
||||
if (existing != null)
|
||||
{
|
||||
_options.LogEntries.Remove(existing);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the Mappings.
|
||||
/// </summary>
|
||||
@@ -406,91 +330,5 @@ namespace WireMock.Server
|
||||
_options.Mappings.Add(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
//private async void HandleRequestOld(IOwinContext ctx)
|
||||
//{
|
||||
// if (_requestProcessingDelay > TimeSpan.Zero)
|
||||
// {
|
||||
// lock (_syncRoot)
|
||||
// {
|
||||
// Task.Delay(_requestProcessingDelay.Value).Wait();
|
||||
// }
|
||||
// }
|
||||
|
||||
// var request = _requestMapper.MapAsync(ctx.Request);
|
||||
|
||||
// ResponseMessage response = null;
|
||||
// Mapping targetMapping = null;
|
||||
// RequestMatchResult requestMatchResult = null;
|
||||
// try
|
||||
// {
|
||||
// var mappings = _mappings
|
||||
// .Select(m => new { Mapping = m, MatchResult = m.IsRequestHandled(request) })
|
||||
// .ToList();
|
||||
|
||||
// if (_allowPartialMapping)
|
||||
// {
|
||||
// var partialMappings = mappings
|
||||
// .Where(pm => pm.Mapping.IsAdminInterface && pm.MatchResult.IsPerfectMatch || !pm.Mapping.IsAdminInterface)
|
||||
// .OrderBy(m => m.MatchResult)
|
||||
// .ThenBy(m => m.Mapping.Priority)
|
||||
// .ToList();
|
||||
|
||||
// var bestPartialMatch = partialMappings.FirstOrDefault(pm => pm.MatchResult.AverageTotalScore > 0.0);
|
||||
|
||||
// targetMapping = bestPartialMatch?.Mapping;
|
||||
// requestMatchResult = bestPartialMatch?.MatchResult;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// var perfectMatch = mappings
|
||||
// .OrderBy(m => m.Mapping.Priority)
|
||||
// .FirstOrDefault(m => m.MatchResult.IsPerfectMatch);
|
||||
|
||||
// targetMapping = perfectMatch?.Mapping;
|
||||
// requestMatchResult = perfectMatch?.MatchResult;
|
||||
// }
|
||||
|
||||
// if (targetMapping == null)
|
||||
// {
|
||||
// response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" };
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (targetMapping.IsAdminInterface && _authorizationMatcher != null)
|
||||
// {
|
||||
// string authorization;
|
||||
// bool present = request.Headers.TryGetValue("Authorization", out authorization);
|
||||
// if (!present || _authorizationMatcher.IsMatch(authorization) < 1.0)
|
||||
// {
|
||||
// response = new ResponseMessage { StatusCode = 401 };
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
// response = await targetMapping.ResponseTo(request);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// response = new ResponseMessage { StatusCode = 500, Body = ex.ToString() };
|
||||
// }
|
||||
// finally
|
||||
// {
|
||||
// var log = new LogEntry
|
||||
// {
|
||||
// Guid = Guid.NewGuid(),
|
||||
// RequestMessage = request,
|
||||
// ResponseMessage = response,
|
||||
// MappingGuid = targetMapping?.Guid,
|
||||
// MappingTitle = targetMapping?.Title,
|
||||
// RequestMatchResult = requestMatchResult
|
||||
// };
|
||||
|
||||
// LogRequest(log);
|
||||
|
||||
// _responseMapper.MapAsync(response, ctx.Response);
|
||||
// ctx.Response.Close();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,10 @@
|
||||
<DefineConstants>NETSTANDARD</DefineConstants>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="Server\FluentMockServer.LogEntries.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="JetBrains.Annotations" Version="10.4.0">
|
||||
<PrivateAssets>All</PrivateAssets>
|
||||
|
||||
Reference in New Issue
Block a user