This commit is contained in:
Stef Heyenrath
2018-07-01 11:10:34 +02:00
parent fe9f4902b1
commit 9e9eadf693
10 changed files with 61 additions and 36 deletions

View File

@@ -1,3 +1,10 @@
# 1.0.4.4 (01 July 2018)
- [#156](https://github.com/WireMock-Net/WireMock.Net/issues/156) - Feature: when adding / updating a mapping : return more details
Commits: ...
# 1.0.4.3 (30 June 2018) # 1.0.4.3 (30 June 2018)
- [#159](https://github.com/WireMock-Net/WireMock.Net/issues/159) - Bug: IRequestBuilder.WithParam broken for key-only matching +fix - [#159](https://github.com/WireMock-Net/WireMock.Net/issues/159) - Bug: IRequestBuilder.WithParam broken for key-only matching +fix

View File

@@ -1,5 +1,5 @@
https://github.com/GitTools/GitReleaseNotes https://github.com/GitTools/GitReleaseNotes
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.4.3 GitReleaseNotes.exe . /OutputFile CHANGELOG.md /Version 1.0.4.4
GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags GitReleaseNotes.exe . /OutputFile CHANGELOG.md /allTags

View File

@@ -41,6 +41,7 @@ namespace WireMock.Net.StandAlone
Arguments[currentName] = values.ToArray(); Arguments[currentName] = values.ToArray();
} }
} }
public bool Contains(string name) public bool Contains(string name)
{ {
return Arguments.ContainsKey(name); return Arguments.ContainsKey(name);

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Lightweight StandAlone Http Mocking Server for .Net.</Description> <Description>Lightweight StandAlone Http Mocking Server for .Net.</Description>
<AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle> <AssemblyTitle>WireMock.Net.StandAlone</AssemblyTitle>
<Version>1.0.4.3</Version> <Version>1.0.4.4</Version>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>

View File

@@ -49,7 +49,7 @@ namespace WireMock.Owin
catch (Exception ex) catch (Exception ex)
{ {
_options.Logger.Error("HttpStatusCode set to 500 {0}", ex); _options.Logger.Error("HttpStatusCode set to 500 {0}", ex);
await _responseMapper.MapAsync(new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObject(ex) }, ctx.Response); await _responseMapper.MapAsync(ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500), ctx.Response);
} }
} }
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using WireMock.Logging; using WireMock.Logging;
using WireMock.Matchers.Request; using WireMock.Matchers.Request;
@@ -6,6 +7,7 @@ using System.Linq;
using WireMock.Matchers; using WireMock.Matchers;
using WireMock.Util; using WireMock.Util;
using Newtonsoft.Json; using Newtonsoft.Json;
using WireMock.Admin.Mappings;
using WireMock.Http; using WireMock.Http;
using WireMock.Serialization; using WireMock.Serialization;
#if !NETSTANDARD #if !NETSTANDARD
@@ -22,6 +24,8 @@ namespace WireMock.Owin
internal class WireMockMiddleware internal class WireMockMiddleware
#endif #endif
{ {
private readonly IDictionary<string, WireMockList<string>> _contentTypeJsonHeaders = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string> { "application/json" } } };
private static readonly Task CompletedTask = Task.FromResult(false); private static readonly Task CompletedTask = Task.FromResult(false);
private readonly WireMockMiddlewareOptions _options; private readonly WireMockMiddlewareOptions _options;
@@ -98,7 +102,7 @@ namespace WireMock.Owin
{ {
logRequest = true; logRequest = true;
_options.Logger.Warn("HttpStatusCode set to 404 : No matching mapping found"); _options.Logger.Warn("HttpStatusCode set to 404 : No matching mapping found");
response = new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" }; response = ResponseMessageBuilder.Create("No matching mapping found", 404);
return; return;
} }
@@ -110,7 +114,7 @@ namespace WireMock.Owin
if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect) if (!present || _options.AuthorizationMatcher.IsMatch(authorization.ToString()) < MatchScores.Perfect)
{ {
_options.Logger.Error("HttpStatusCode set to 401"); _options.Logger.Error("HttpStatusCode set to 401");
response = new ResponseMessage { StatusCode = 401 }; response = ResponseMessageBuilder.Create(null, 401);
return; return;
} }
} }
@@ -130,7 +134,7 @@ namespace WireMock.Owin
catch (Exception ex) catch (Exception ex)
{ {
_options.Logger.Error("HttpStatusCode set to 500"); _options.Logger.Error("HttpStatusCode set to 500");
response = new ResponseMessage { StatusCode = 500, Body = JsonConvert.SerializeObject(ex) }; response = ResponseMessageBuilder.Create(JsonConvert.SerializeObject(ex), 500);
} }
finally finally
{ {

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using WireMock.Admin.Mappings;
using WireMock.Http;
using WireMock.Util;
namespace WireMock
{
internal static class ResponseMessageBuilder
{
private static string ContentTypeJson = "application/json";
private static readonly IDictionary<string, WireMockList<string>> ContentTypeJsonHeaders = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string> { ContentTypeJson } } };
internal static ResponseMessage Create(string message, int statusCode = 200, Guid? guid = null)
{
var response = new ResponseMessage
{
StatusCode = statusCode,
Headers = ContentTypeJsonHeaders,
BodyAsJson = message != null ? new StatusModel { Status = message, Guid = guid } : null
};
return response;
}
}
}

View File

@@ -37,7 +37,6 @@ namespace WireMock.Server
private const string AdminScenarios = "/__admin/scenarios"; private const string AdminScenarios = "/__admin/scenarios";
private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$"); private readonly RegexMatcher _adminMappingsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/mappings\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/requests\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$"); private readonly RegexMatcher _adminRequestsGuidPathMatcher = new RegexMatcher(MatchBehaviour.AcceptOnMatch, @"^\/__admin\/requests\/(\{{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}\}{0,1})$");
private readonly IDictionary<string, WireMockList<string>> _contentTypeJsonHeaders = new Dictionary<string, WireMockList<string>> { { HttpKnownHeaderNames.ContentType, new WireMockList<string> { ContentTypeJson } } };
private readonly JsonSerializerSettings _settings = new JsonSerializerSettings private readonly JsonSerializerSettings _settings = new JsonSerializerSettings
{ {
@@ -284,7 +283,7 @@ namespace WireMock.Server
_options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value); _options.RequestProcessingDelay = TimeSpan.FromMilliseconds(settings.GlobalProcessingDelay.Value);
} }
return CreateResponseMessage("Settings updated"); return ResponseMessageBuilder.Create("Settings updated");
} }
#endregion Settings #endregion Settings
@@ -297,7 +296,7 @@ namespace WireMock.Server
if (mapping == null) if (mapping == null)
{ {
_logger.Warn("HttpStatusCode set to 404 : Mapping not found"); _logger.Warn("HttpStatusCode set to 404 : Mapping not found");
return CreateResponseMessage("Mapping not found", 404); return ResponseMessageBuilder.Create("Mapping not found", 404);
} }
var model = MappingConverter.ToMappingModel(mapping); var model = MappingConverter.ToMappingModel(mapping);
@@ -312,7 +311,7 @@ namespace WireMock.Server
var mappingModel = DeserializeObject<MappingModel>(requestMessage); var mappingModel = DeserializeObject<MappingModel>(requestMessage);
DeserializeAndAddOrUpdateMapping(mappingModel, guid); DeserializeAndAddOrUpdateMapping(mappingModel, guid);
return CreateResponseMessage("Mapping added or updated", 200, guid); return ResponseMessageBuilder.Create("Mapping added or updated", 200, guid);
} }
private ResponseMessage MappingDelete(RequestMessage requestMessage) private ResponseMessage MappingDelete(RequestMessage requestMessage)
@@ -321,10 +320,10 @@ namespace WireMock.Server
if (DeleteMapping(guid)) if (DeleteMapping(guid))
{ {
return CreateResponseMessage("Mapping removed", 200, guid); return ResponseMessageBuilder.Create("Mapping removed", 200, guid);
} }
return CreateResponseMessage("Mapping not found", 404); return ResponseMessageBuilder.Create("Mapping not found", 404);
} }
#endregion Mapping/{guid} #endregion Mapping/{guid}
@@ -336,7 +335,7 @@ namespace WireMock.Server
SaveMappingToFile(mapping); SaveMappingToFile(mapping);
} }
return CreateResponseMessage("Mappings saved to disk"); return ResponseMessageBuilder.Create("Mappings saved to disk");
} }
private void SaveMappingToFile(Mapping mapping) private void SaveMappingToFile(Mapping mapping)
@@ -384,15 +383,15 @@ namespace WireMock.Server
catch (ArgumentException a) catch (ArgumentException a)
{ {
_logger.Error("HttpStatusCode set to 400 {0}", a); _logger.Error("HttpStatusCode set to 400 {0}", a);
return CreateResponseMessage(a.Message, 400); return ResponseMessageBuilder.Create(a.Message, 400);
} }
catch (Exception e) catch (Exception e)
{ {
_logger.Error("HttpStatusCode set to 500 {0}", e); _logger.Error("HttpStatusCode set to 500 {0}", e);
return CreateResponseMessage(e.ToString(), 500); return ResponseMessageBuilder.Create(e.ToString(), 500);
} }
return CreateResponseMessage("Mapping added", 201, guid); return ResponseMessageBuilder.Create("Mapping added", 201, guid);
} }
private Guid DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null) private Guid DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)
@@ -448,7 +447,7 @@ namespace WireMock.Server
ResetScenarios(); ResetScenarios();
return CreateResponseMessage("Mappings deleted"); return ResponseMessageBuilder.Create("Mappings deleted");
} }
#endregion Mappings #endregion Mappings
@@ -461,7 +460,7 @@ namespace WireMock.Server
if (entry == null) if (entry == null)
{ {
_logger.Warn("HttpStatusCode set to 404 : Request not found"); _logger.Warn("HttpStatusCode set to 404 : Request not found");
return CreateResponseMessage("Request not found", 404); return ResponseMessageBuilder.Create("Request not found", 404);
} }
var model = LogEntryMapper.Map(entry); var model = LogEntryMapper.Map(entry);
@@ -475,10 +474,10 @@ namespace WireMock.Server
if (DeleteLogEntry(guid)) if (DeleteLogEntry(guid))
{ {
return CreateResponseMessage("Request removed"); return ResponseMessageBuilder.Create("Request removed");
} }
return CreateResponseMessage("Request not found", 404); return ResponseMessageBuilder.Create("Request not found", 404);
} }
#endregion Request/{guid} #endregion Request/{guid}
@@ -496,7 +495,7 @@ namespace WireMock.Server
{ {
ResetLogEntries(); ResetLogEntries();
return CreateResponseMessage("Requests deleted"); return ResponseMessageBuilder.Create("Requests deleted");
} }
#endregion Requests #endregion Requests
@@ -539,7 +538,7 @@ namespace WireMock.Server
{ {
ResetScenarios(); ResetScenarios();
return CreateResponseMessage("Scenarios reset"); return ResponseMessageBuilder.Create("Scenarios reset");
} }
#endregion #endregion
@@ -728,17 +727,5 @@ namespace WireMock.Server
JsonConvert.DeserializeObject<T>(requestMessage.Body) : JsonConvert.DeserializeObject<T>(requestMessage.Body) :
((JObject)requestMessage.BodyAsJson).ToObject<T>(); ((JObject)requestMessage.BodyAsJson).ToObject<T>();
} }
private ResponseMessage CreateResponseMessage(string message, int statusCode = 200, Guid? guid = null)
{
var response = new ResponseMessage
{
StatusCode = statusCode,
Headers = _contentTypeJsonHeaders,
BodyAsJson = new StatusModel { Status = message, Guid = guid }
};
return response;
}
} }
} }

View File

@@ -264,7 +264,7 @@ namespace WireMock.Server
Given(Request.Create().WithPath("/*").UsingAnyMethod()) Given(Request.Create().WithPath("/*").UsingAnyMethod())
.WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05")) .WithGuid(Guid.Parse("90008000-0000-4444-a17e-669cd84f1f05"))
.AtPriority(1000) .AtPriority(1000)
.RespondWith(new DynamicResponseProvider(request => new ResponseMessage { StatusCode = 404, Body = "No matching mapping found" })); .RespondWith(new DynamicResponseProvider(request => ResponseMessageBuilder.Create("No matching mapping found", 404)));
} }
/// <summary> /// <summary>

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description> <Description>Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape.</Description>
<AssemblyTitle>WireMock.Net</AssemblyTitle> <AssemblyTitle>WireMock.Net</AssemblyTitle>
<Version>1.0.4.3</Version> <Version>1.0.4.4</Version>
<Authors>Stef Heyenrath</Authors> <Authors>Stef Heyenrath</Authors>
<TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks> <TargetFrameworks>net452;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>