This commit is contained in:
Stef Heyenrath
2018-06-27 20:19:27 +02:00
parent 3df8bd2fdc
commit 768cc621ad
5 changed files with 21 additions and 13 deletions

View File

@@ -43,11 +43,11 @@ namespace WireMock.Net.Client
var request = api.GetRequestsAsync().Result;
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
string deleteRequestsAsync = api.DeleteRequestsAsync().Result;
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync}");
var deleteRequestsAsync = api.DeleteRequestsAsync().Result;
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync.Status}");
string resetRequestsAsync = api.ResetRequestsAsync().Result;
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync}");
var resetRequestsAsync = api.ResetRequestsAsync().Result;
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync.Status}");
Console.WriteLine("Press any key to quit");
Console.ReadKey();

View File

@@ -379,8 +379,7 @@ namespace WireMock.Server
try
{
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
guid = mappingModel.Guid;
DeserializeAndAddOrUpdateMapping(mappingModel);
guid = DeserializeAndAddOrUpdateMapping(mappingModel);
}
catch (ArgumentException a)
{
@@ -396,7 +395,7 @@ namespace WireMock.Server
return CreateResponseMessage("Mapping added", 201, guid);
}
private void DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)
private Guid DeserializeAndAddOrUpdateMapping(MappingModel mappingModel, Guid? guid = null, string path = null)
{
Check.NotNull(mappingModel, nameof(mappingModel));
Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
@@ -405,7 +404,7 @@ namespace WireMock.Server
var requestBuilder = InitRequestBuilder(mappingModel.Request);
var responseBuilder = InitResponseBuilder(mappingModel.Response);
IRespondWithAProvider respondProvider = Given(requestBuilder);
var respondProvider = Given(requestBuilder);
if (guid != null)
{
@@ -439,6 +438,8 @@ namespace WireMock.Server
}
respondProvider.RespondWith(responseBuilder);
return respondProvider.Guid;
}
private ResponseMessage MappingsDelete(RequestMessage requestMessage)

View File

@@ -8,6 +8,11 @@ namespace WireMock.Server
/// </summary>
public interface IRespondWithAProvider
{
/// <summary>
/// Gets the unique identifier for this mapping.
/// </summary>
Guid Guid { get; }
/// <summary>
/// Define a unique identifier for this mapping.
/// </summary>

View File

@@ -10,7 +10,6 @@ namespace WireMock.Server
internal class RespondWithAProvider : IRespondWithAProvider
{
private int _priority;
private Guid? _guid;
private string _title;
private string _path;
private object _executionConditionState;
@@ -19,6 +18,8 @@ namespace WireMock.Server
private readonly RegistrationCallback _registrationCallback;
private readonly IRequestMatcher _requestMatcher;
public Guid Guid { get; private set; } = Guid.NewGuid();
/// <summary>
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
/// </summary>
@@ -36,8 +37,7 @@ namespace WireMock.Server
/// <param name="provider">The provider.</param>
public void RespondWith(IResponseProvider provider)
{
var mappingGuid = _guid ?? Guid.NewGuid();
_registrationCallback(new Mapping(mappingGuid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
_registrationCallback(new Mapping(Guid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
}
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
@@ -49,7 +49,7 @@ namespace WireMock.Server
/// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
public IRespondWithAProvider WithGuid(Guid guid)
{
_guid = guid;
Guid = guid;
return this;
}

View File

@@ -33,10 +33,12 @@ namespace WireMock.Net.Tests
Priority = 500,
Title = "test"
};
string result = await api.PostMappingAsync(model);
var result = await api.PostMappingAsync(model);
// Assert
Check.That(result).IsNotNull();
Check.That(result.Status).IsNotNull();
Check.That(result.Guid).IsNotNull();
var mapping = server.Mappings.Single(m => m.Priority == 500);
Check.That(mapping).IsNotNull();