mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-24 01:08:28 +02:00
This commit is contained in:
@@ -43,11 +43,11 @@ namespace WireMock.Net.Client
|
|||||||
var request = api.GetRequestsAsync().Result;
|
var request = api.GetRequestsAsync().Result;
|
||||||
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
|
Console.WriteLine($"request = {JsonConvert.SerializeObject(request)}");
|
||||||
|
|
||||||
string deleteRequestsAsync = api.DeleteRequestsAsync().Result;
|
var deleteRequestsAsync = api.DeleteRequestsAsync().Result;
|
||||||
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync}");
|
Console.WriteLine($"deleteRequestsAsync = {deleteRequestsAsync.Status}");
|
||||||
|
|
||||||
string resetRequestsAsync = api.ResetRequestsAsync().Result;
|
var resetRequestsAsync = api.ResetRequestsAsync().Result;
|
||||||
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync}");
|
Console.WriteLine($"resetRequestsAsync = {resetRequestsAsync.Status}");
|
||||||
|
|
||||||
Console.WriteLine("Press any key to quit");
|
Console.WriteLine("Press any key to quit");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|||||||
@@ -379,8 +379,7 @@ namespace WireMock.Server
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
|
var mappingModel = DeserializeObject<MappingModel>(requestMessage);
|
||||||
guid = mappingModel.Guid;
|
guid = DeserializeAndAddOrUpdateMapping(mappingModel);
|
||||||
DeserializeAndAddOrUpdateMapping(mappingModel);
|
|
||||||
}
|
}
|
||||||
catch (ArgumentException a)
|
catch (ArgumentException a)
|
||||||
{
|
{
|
||||||
@@ -396,7 +395,7 @@ namespace WireMock.Server
|
|||||||
return CreateResponseMessage("Mapping added", 201, guid);
|
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, nameof(mappingModel));
|
||||||
Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
|
Check.NotNull(mappingModel.Request, nameof(mappingModel.Request));
|
||||||
@@ -405,7 +404,7 @@ namespace WireMock.Server
|
|||||||
var requestBuilder = InitRequestBuilder(mappingModel.Request);
|
var requestBuilder = InitRequestBuilder(mappingModel.Request);
|
||||||
var responseBuilder = InitResponseBuilder(mappingModel.Response);
|
var responseBuilder = InitResponseBuilder(mappingModel.Response);
|
||||||
|
|
||||||
IRespondWithAProvider respondProvider = Given(requestBuilder);
|
var respondProvider = Given(requestBuilder);
|
||||||
|
|
||||||
if (guid != null)
|
if (guid != null)
|
||||||
{
|
{
|
||||||
@@ -439,6 +438,8 @@ namespace WireMock.Server
|
|||||||
}
|
}
|
||||||
|
|
||||||
respondProvider.RespondWith(responseBuilder);
|
respondProvider.RespondWith(responseBuilder);
|
||||||
|
|
||||||
|
return respondProvider.Guid;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ResponseMessage MappingsDelete(RequestMessage requestMessage)
|
private ResponseMessage MappingsDelete(RequestMessage requestMessage)
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ namespace WireMock.Server
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRespondWithAProvider
|
public interface IRespondWithAProvider
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the unique identifier for this mapping.
|
||||||
|
/// </summary>
|
||||||
|
Guid Guid { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Define a unique identifier for this mapping.
|
/// Define a unique identifier for this mapping.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ namespace WireMock.Server
|
|||||||
internal class RespondWithAProvider : IRespondWithAProvider
|
internal class RespondWithAProvider : IRespondWithAProvider
|
||||||
{
|
{
|
||||||
private int _priority;
|
private int _priority;
|
||||||
private Guid? _guid;
|
|
||||||
private string _title;
|
private string _title;
|
||||||
private string _path;
|
private string _path;
|
||||||
private object _executionConditionState;
|
private object _executionConditionState;
|
||||||
@@ -19,6 +18,8 @@ namespace WireMock.Server
|
|||||||
private readonly RegistrationCallback _registrationCallback;
|
private readonly RegistrationCallback _registrationCallback;
|
||||||
private readonly IRequestMatcher _requestMatcher;
|
private readonly IRequestMatcher _requestMatcher;
|
||||||
|
|
||||||
|
public Guid Guid { get; private set; } = Guid.NewGuid();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
|
/// Initializes a new instance of the <see cref="RespondWithAProvider"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -36,8 +37,7 @@ namespace WireMock.Server
|
|||||||
/// <param name="provider">The provider.</param>
|
/// <param name="provider">The provider.</param>
|
||||||
public void RespondWith(IResponseProvider provider)
|
public void RespondWith(IResponseProvider provider)
|
||||||
{
|
{
|
||||||
var mappingGuid = _guid ?? Guid.NewGuid();
|
_registrationCallback(new Mapping(Guid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
|
||||||
_registrationCallback(new Mapping(mappingGuid, _title, _path, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
/// <see cref="IRespondWithAProvider.WithGuid(string)"/>
|
||||||
@@ -49,7 +49,7 @@ namespace WireMock.Server
|
|||||||
/// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
|
/// <see cref="IRespondWithAProvider.WithGuid(Guid)"/>
|
||||||
public IRespondWithAProvider WithGuid(Guid guid)
|
public IRespondWithAProvider WithGuid(Guid guid)
|
||||||
{
|
{
|
||||||
_guid = guid;
|
Guid = guid;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,12 @@ namespace WireMock.Net.Tests
|
|||||||
Priority = 500,
|
Priority = 500,
|
||||||
Title = "test"
|
Title = "test"
|
||||||
};
|
};
|
||||||
string result = await api.PostMappingAsync(model);
|
var result = await api.PostMappingAsync(model);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Check.That(result).IsNotNull();
|
Check.That(result).IsNotNull();
|
||||||
|
Check.That(result.Status).IsNotNull();
|
||||||
|
Check.That(result.Guid).IsNotNull();
|
||||||
|
|
||||||
var mapping = server.Mappings.Single(m => m.Priority == 500);
|
var mapping = server.Mappings.Single(m => m.Priority == 500);
|
||||||
Check.That(mapping).IsNotNull();
|
Check.That(mapping).IsNotNull();
|
||||||
|
|||||||
Reference in New Issue
Block a user