Add UpdatedAt property to Mapping (#859)

* Add UpdatedAt property to Mapping

* .
This commit is contained in:
Stef Heyenrath
2022-12-09 14:18:50 +01:00
committed by GitHub
parent 080efe4fcb
commit e2f3ffd33a
15 changed files with 383 additions and 277 deletions

View File

@@ -3,6 +3,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using log4net; using log4net;
using log4net.Config; using log4net.Config;
using log4net.Repository; using log4net.Repository;
@@ -10,10 +11,9 @@ using WireMock.RequestBuilders;
using WireMock.ResponseBuilders; using WireMock.ResponseBuilders;
using WireMock.Server; using WireMock.Server;
using WireMock.Settings; using WireMock.Settings;
using WireMock.Util;
namespace WireMock.Net.StandAlone.NETCoreApp namespace WireMock.Net.StandAlone.NETCoreApp;
{
static class Program static class Program
{ {
private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly()); private static readonly ILoggerRepository LogRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
@@ -22,8 +22,11 @@ namespace WireMock.Net.StandAlone.NETCoreApp
private static int sleepTime = 30000; private static int sleepTime = 30000;
private static WireMockServer _server; private static WireMockServer _server;
static void Main(string[] args) static async Task Main(string[] args)
{ {
await TestAsync().ConfigureAwait(false);
return;
XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config")); XmlConfigurator.Configure(LogRepository, new FileInfo("log4net.config"));
if (!WireMockServerSettingsParser.TryParseArguments(args, out var settings, new WireMockLog4NetLogger())) if (!WireMockServerSettingsParser.TryParseArguments(args, out var settings, new WireMockLog4NetLogger()))
@@ -76,5 +79,44 @@ namespace WireMock.Net.StandAlone.NETCoreApp
_server.Stop(); _server.Stop();
Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped"); Console.WriteLine($"{DateTime.UtcNow} WireMock.Net server stopped");
} }
private static async Task TestAsync()
{
for (var i = 0; i < 20; i++)
{
var server = WireMockServer.Start();
server
.Given(
Request.Create().WithPath("/some/thing").UsingGet()
)
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "text/plain")
.WithBody("Hello world! : " + i)
);
server
.Given(
Request.Create().WithPath("/some/thing").UsingGet()
)
.RespondWith(
Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "text/plain")
.WithBody("Hello world duplicate! : " + i)
);
var client = server.CreateClient();
var response = await client.GetAsync($"{server.Url}/some/thing").ConfigureAwait(false);
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
Console.WriteLine($"counter {i} value:{content}");
server.Reset();
server.Dispose();
server.Stop();
}
} }
} }

View File

@@ -14,6 +14,11 @@ public class MappingModel
/// </summary> /// </summary>
public Guid? Guid { get; set; } public Guid? Guid { get; set; }
/// <summary>
/// The datetime when this mapping was created or updated.
/// </summary>
public DateTime? UpdatedAt { get; set; }
/// <summary> /// <summary>
/// Gets or sets the TimeSettings when which this mapping should be used. /// Gets or sets the TimeSettings when which this mapping should be used.
/// </summary> /// </summary>

View File

@@ -17,6 +17,11 @@ public interface IMapping
/// </summary> /// </summary>
Guid Guid { get; } Guid Guid { get; }
/// <summary>
/// The datetime when this mapping was created or updated.
/// </summary>
public DateTime? UpdatedAt { get; set; }
/// <summary> /// <summary>
/// Gets the TimeSettings (Start, End and TTL). /// Gets the TimeSettings (Start, End and TTL).
/// </summary> /// </summary>

View File

@@ -15,6 +15,9 @@ public class Mapping : IMapping
/// <inheritdoc /> /// <inheritdoc />
public Guid Guid { get; } public Guid Guid { get; }
/// <inheritdoc />
public DateTime? UpdatedAt { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public string? Title { get; } public string? Title { get; }
@@ -73,6 +76,7 @@ public class Mapping : IMapping
/// Initializes a new instance of the <see cref="Mapping"/> class. /// Initializes a new instance of the <see cref="Mapping"/> class.
/// </summary> /// </summary>
/// <param name="guid">The unique identifier.</param> /// <param name="guid">The unique identifier.</param>
/// <param name="updatedAt">The datetime when this mapping was created.</param>
/// <param name="title">The unique title (can be null).</param> /// <param name="title">The unique title (can be null).</param>
/// <param name="description">The description (can be null).</param> /// <param name="description">The description (can be null).</param>
/// <param name="path">The full file path from this mapping title (can be null).</param> /// <param name="path">The full file path from this mapping title (can be null).</param>
@@ -89,6 +93,7 @@ public class Mapping : IMapping
/// <param name="timeSettings">The TimeSettings. [Optional]</param> /// <param name="timeSettings">The TimeSettings. [Optional]</param>
public Mapping( public Mapping(
Guid guid, Guid guid,
DateTime updatedAt,
string? title, string? title,
string? description, string? description,
string? path, string? path,
@@ -105,6 +110,7 @@ public class Mapping : IMapping
ITimeSettings? timeSettings) ITimeSettings? timeSettings)
{ {
Guid = guid; Guid = guid;
UpdatedAt = updatedAt;
Title = title; Title = title;
Description = description; Description = description;
Path = path; Path = path;

View File

@@ -12,13 +12,13 @@ internal class MappingMatcher : IMappingMatcher
public MappingMatcher(IWireMockMiddlewareOptions options) public MappingMatcher(IWireMockMiddlewareOptions options)
{ {
Guard.NotNull(options, nameof(options)); _options = Guard.NotNull(options);
_options = options;
} }
public (MappingMatcherResult? Match, MappingMatcherResult? Partial) FindBestMatch(RequestMessage request) public (MappingMatcherResult? Match, MappingMatcherResult? Partial) FindBestMatch(RequestMessage request)
{ {
Guard.NotNull(request);
var possibleMappings = new List<MappingMatcherResult>(); var possibleMappings = new List<MappingMatcherResult>();
foreach (var mapping in _options.Mappings.Values.Where(m => m.TimeSettings.IsValid())) foreach (var mapping in _options.Mappings.Values.Where(m => m.TimeSettings.IsValid()))
@@ -41,8 +41,7 @@ internal class MappingMatcher : IMappingMatcher
var partialMappings = possibleMappings var partialMappings = possibleMappings
.Where(pm => (pm.Mapping.IsAdminInterface && pm.RequestMatchResult.IsPerfectMatch) || !pm.Mapping.IsAdminInterface) .Where(pm => (pm.Mapping.IsAdminInterface && pm.RequestMatchResult.IsPerfectMatch) || !pm.Mapping.IsAdminInterface)
.OrderBy(m => m.RequestMatchResult) .OrderBy(m => m.RequestMatchResult).ThenBy(m => m.Mapping.Priority).ThenByDescending(m => m.Mapping.UpdatedAt)
.ThenBy(m => m.Mapping.Priority)
.ToList(); .ToList();
var partialMatch = partialMappings.FirstOrDefault(pm => pm.RequestMatchResult.AverageTotalScore > 0.0); var partialMatch = partialMappings.FirstOrDefault(pm => pm.RequestMatchResult.AverageTotalScore > 0.0);
@@ -53,7 +52,7 @@ internal class MappingMatcher : IMappingMatcher
var match = possibleMappings var match = possibleMappings
.Where(m => m.RequestMatchResult.IsPerfectMatch) .Where(m => m.RequestMatchResult.IsPerfectMatch)
.OrderBy(m => m.Mapping.Priority).ThenBy(m => m.RequestMatchResult) .OrderBy(m => m.Mapping.Priority).ThenBy(m => m.RequestMatchResult).ThenByDescending(m => m.Mapping.UpdatedAt)
.FirstOrDefault(); .FirstOrDefault();
return (match, partialMatch); return (match, partialMatch);

View File

@@ -17,7 +17,7 @@ internal class ProxyHelper
public ProxyHelper(WireMockServerSettings settings) public ProxyHelper(WireMockServerSettings settings)
{ {
_settings = Guard.NotNull(settings); _settings = Guard.NotNull(settings);
_proxyMappingConverter = new ProxyMappingConverter(settings, new GuidUtils()); _proxyMappingConverter = new ProxyMappingConverter(settings, new GuidUtils(), new DateTimeUtils());
} }
public async Task<(IResponseMessage Message, IMapping? Mapping)> SendAsync( public async Task<(IResponseMessage Message, IMapping? Mapping)> SendAsync(

View File

@@ -40,6 +40,7 @@ internal class MappingConverter
var mappingModel = new MappingModel var mappingModel = new MappingModel
{ {
Guid = mapping.Guid, Guid = mapping.Guid,
UpdatedAt = mapping.UpdatedAt,
TimeSettings = TimeSettingsMapper.Map(mapping.TimeSettings), TimeSettings = TimeSettingsMapper.Map(mapping.TimeSettings),
Title = mapping.Title, Title = mapping.Title,
Description = mapping.Description, Description = mapping.Description,

View File

@@ -1,7 +1,7 @@
using Stef.Validation;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Stef.Validation;
using WireMock.Constants; using WireMock.Constants;
using WireMock.Matchers; using WireMock.Matchers;
using WireMock.Matchers.Request; using WireMock.Matchers.Request;
@@ -17,11 +17,13 @@ internal class ProxyMappingConverter
{ {
private readonly WireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
private readonly IGuidUtils _guidUtils; private readonly IGuidUtils _guidUtils;
private readonly IDateTimeUtils _dateTimeUtils;
public ProxyMappingConverter(WireMockServerSettings settings, IGuidUtils guidUtils) public ProxyMappingConverter(WireMockServerSettings settings, IGuidUtils guidUtils, IDateTimeUtils dateTimeUtils)
{ {
_settings = Guard.NotNull(settings); _settings = Guard.NotNull(settings);
_guidUtils = Guard.NotNull(guidUtils); _guidUtils = Guard.NotNull(guidUtils);
_dateTimeUtils = Guard.NotNull(dateTimeUtils);
} }
public IMapping ToMapping(IMapping? mapping, ProxyAndRecordSettings proxyAndRecordSettings, IRequestMessage requestMessage, ResponseMessage responseMessage) public IMapping ToMapping(IMapping? mapping, ProxyAndRecordSettings proxyAndRecordSettings, IRequestMessage requestMessage, ResponseMessage responseMessage)
@@ -162,6 +164,7 @@ internal class ProxyMappingConverter
return new Mapping return new Mapping
( (
guid: _guidUtils.NewGuid(), guid: _guidUtils.NewGuid(),
updatedAt: _dateTimeUtils.UtcNow,
title: title, title: title,
description: description, description: description,
path: null, path: null,

View File

@@ -29,10 +29,12 @@ internal class RespondWithAProvider : IRespondWithAProvider
private readonly IRequestMatcher _requestMatcher; private readonly IRequestMatcher _requestMatcher;
private readonly WireMockServerSettings _settings; private readonly WireMockServerSettings _settings;
private readonly bool _saveToFile; private readonly bool _saveToFile;
private readonly IGuidUtils _guidUtils = new GuidUtils();
private readonly IDateTimeUtils _dateTimeUtils = new DateTimeUtils();
private bool _useWebhookFireAndForget; private bool _useWebhookFireAndForget;
public Guid Guid { get; private set; } = Guid.NewGuid(); public Guid Guid { get; private set; }
public IWebhook[]? Webhooks { get; private set; } public IWebhook[]? Webhooks { get; private set; }
@@ -45,12 +47,19 @@ internal class RespondWithAProvider : IRespondWithAProvider
/// <param name="requestMatcher">The request matcher.</param> /// <param name="requestMatcher">The request matcher.</param>
/// <param name="settings">The WireMockServerSettings.</param> /// <param name="settings">The WireMockServerSettings.</param>
/// <param name="saveToFile">Optional boolean to indicate if this mapping should be saved as static mapping file.</param> /// <param name="saveToFile">Optional boolean to indicate if this mapping should be saved as static mapping file.</param>
public RespondWithAProvider(RegistrationCallback registrationCallback, IRequestMatcher requestMatcher, WireMockServerSettings settings, bool saveToFile = false) public RespondWithAProvider(
RegistrationCallback registrationCallback,
IRequestMatcher requestMatcher,
WireMockServerSettings settings,
bool saveToFile = false
)
{ {
_registrationCallback = registrationCallback; _registrationCallback = Guard.NotNull(registrationCallback);
_requestMatcher = requestMatcher; _requestMatcher = Guard.NotNull(requestMatcher);
_settings = settings; _settings = Guard.NotNull(settings);
_saveToFile = saveToFile; _saveToFile = Guard.NotNull(saveToFile);
Guid = _guidUtils.NewGuid();
} }
/// <summary> /// <summary>
@@ -59,7 +68,24 @@ internal class RespondWithAProvider : IRespondWithAProvider
/// <param name="provider">The provider.</param> /// <param name="provider">The provider.</param>
public void RespondWith(IResponseProvider provider) public void RespondWith(IResponseProvider provider)
{ {
_registrationCallback(new Mapping(Guid, _title, _description, _path, _settings, _requestMatcher, provider, _priority, _scenario, _executionConditionState, _nextState, _timesInSameState, Webhooks, _useWebhookFireAndForget, TimeSettings), _saveToFile); var mapping = new Mapping(
Guid,
_dateTimeUtils.UtcNow,
_title,
_description,
_path,
_settings,
_requestMatcher,
provider,
_priority,
_scenario,
_executionConditionState,
_nextState,
_timesInSameState,
Webhooks,
_useWebhookFireAndForget,
TimeSettings);
_registrationCallback(mapping, _saveToFile);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -524,9 +524,10 @@ public partial class WireMockServer : IWireMockServer
private void RegisterMapping(IMapping mapping, bool saveToFile) private void RegisterMapping(IMapping mapping, bool saveToFile)
{ {
// Check a mapping exists with the same Guid, if so, replace it. // Check a mapping exists with the same Guid. If so, update the datetime and replace it.
if (_options.Mappings.ContainsKey(mapping.Guid)) if (_options.Mappings.ContainsKey(mapping.Guid))
{ {
mapping.UpdatedAt = DateTime.UtcNow;
_options.Mappings[mapping.Guid] = mapping; _options.Mappings[mapping.Guid] = mapping;
} }
else else

View File

@@ -0,0 +1,13 @@
using System;
namespace WireMock.Util;
internal interface IDateTimeUtils
{
DateTime UtcNow { get; }
}
internal class DateTimeUtils : IDateTimeUtils
{
public DateTime UtcNow => DateTime.UtcNow;
}

View File

@@ -30,11 +30,12 @@ using IRequest = Microsoft.AspNetCore.Http.HttpRequest;
using IResponse = Microsoft.AspNetCore.Http.HttpResponse; using IResponse = Microsoft.AspNetCore.Http.HttpResponse;
#endif #endif
namespace WireMock.Net.Tests.Owin namespace WireMock.Net.Tests.Owin;
{
public class WireMockMiddlewareTests public class WireMockMiddlewareTests
{ {
private readonly WireMockMiddleware _sut; private readonly DateTime _updatedAt = new(2022, 12, 4);
private readonly ConcurrentDictionary<Guid, IMapping> _mappings = new();
private readonly Mock<IWireMockMiddlewareOptions> _optionsMock; private readonly Mock<IWireMockMiddlewareOptions> _optionsMock;
private readonly Mock<IOwinRequestMapper> _requestMapperMock; private readonly Mock<IOwinRequestMapper> _requestMapperMock;
@@ -43,7 +44,7 @@ namespace WireMock.Net.Tests.Owin
private readonly Mock<IMapping> _mappingMock; private readonly Mock<IMapping> _mappingMock;
private readonly Mock<IContext> _contextMock; private readonly Mock<IContext> _contextMock;
private readonly ConcurrentDictionary<Guid, IMapping> _mappings = new ConcurrentDictionary<Guid, IMapping>(); private readonly WireMockMiddleware _sut;
public WireMockMiddlewareTests() public WireMockMiddlewareTests()
{ {
@@ -176,7 +177,7 @@ namespace WireMock.Net.Tests.Owin
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder); _mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
_mappingMock.SetupGet(m => m.Settings).Returns(settings); _mappingMock.SetupGet(m => m.Settings).Returns(settings);
var newMappingFromProxy = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, false, null); var newMappingFromProxy = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, false, null);
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy)); _mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
var requestBuilder = Request.Create().UsingAnyMethod(); var requestBuilder = Request.Create().UsingAnyMethod();
@@ -230,7 +231,7 @@ namespace WireMock.Net.Tests.Owin
_mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder); _mappingMock.SetupGet(m => m.Provider).Returns(responseBuilder);
_mappingMock.SetupGet(m => m.Settings).Returns(settings); _mappingMock.SetupGet(m => m.Settings).Returns(settings);
var newMappingFromProxy = new Mapping(Guid.NewGuid(), "my-title", "my-description", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, false, null); var newMappingFromProxy = new Mapping(Guid.NewGuid(), _updatedAt, "my-title", "my-description", null, settings, Request.Create(), Response.Create(), 0, null, null, null, null, null, false, null);
_mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy)); _mappingMock.Setup(m => m.ProvideResponseAsync(It.IsAny<RequestMessage>())).ReturnsAsync((new ResponseMessage(), newMappingFromProxy));
var requestBuilder = Request.Create().UsingAnyMethod(); var requestBuilder = Request.Create().UsingAnyMethod();
@@ -248,4 +249,3 @@ namespace WireMock.Net.Tests.Owin
_mappings.Count.Should().Be(1); _mappings.Count.Should().Be(1);
} }
} }
}

View File

@@ -15,6 +15,7 @@ namespace WireMock.Net.Tests.Serialization;
public class MappingConverterTests public class MappingConverterTests
{ {
private readonly DateTime _updatedAt = new(2022, 12, 4);
private readonly WireMockServerSettings _settings = new(); private readonly WireMockServerSettings _settings = new();
private readonly MappingConverter _sut; private readonly MappingConverter _sut;
@@ -52,7 +53,7 @@ public class MappingConverterTests
} }
} }
}; };
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -122,7 +123,7 @@ public class MappingConverterTests
} }
} }
}; };
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, true, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 0, null, null, null, null, webhooks, true, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -157,7 +158,7 @@ public class MappingConverterTests
var description = "my-description"; var description = "my-description";
var request = Request.Create(); var request = Request.Create();
var response = Response.Create(); var response = Response.Create();
var mapping = new Mapping(Guid.NewGuid(), title, description, null, _settings, request, response, 0, null, null, null, null, null, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, title, description, null, _settings, request, response, 0, null, null, null, null, null, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -174,7 +175,7 @@ public class MappingConverterTests
// Assign // Assign
var request = Request.Create(); var request = Request.Create();
var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer(); var response = Response.Create().WithBodyAsJson(new { x = "x" }).WithTransformer();
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -200,7 +201,7 @@ public class MappingConverterTests
End = end, End = end,
TTL = ttl TTL = ttl
}; };
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, timeSettings); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, timeSettings);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -228,7 +229,7 @@ public class MappingConverterTests
{ {
var request = Request.Create(); var request = Request.Create();
var response = Response.Create().WithDelay(test.Delay); var response = Response.Create().WithDelay(test.Delay);
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, string.Empty, _settings, request, response, 42, null, null, null, null, null, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, string.Empty, _settings, request, response, 42, null, null, null, null, null, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -246,7 +247,7 @@ public class MappingConverterTests
var delay = 1000; var delay = 1000;
var request = Request.Create(); var request = Request.Create();
var response = Response.Create().WithDelay(delay); var response = Response.Create().WithDelay(delay);
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -263,7 +264,7 @@ public class MappingConverterTests
int minimumDelay = 1000; int minimumDelay = 1000;
var request = Request.Create(); var request = Request.Create();
var response = Response.Create().WithRandomDelay(minimumDelay); var response = Response.Create().WithRandomDelay(minimumDelay);
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);
@@ -283,7 +284,7 @@ public class MappingConverterTests
int maximumDelay = 2000; int maximumDelay = 2000;
var request = Request.Create(); var request = Request.Create();
var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay); var response = Response.Create().WithRandomDelay(minimumDelay, maximumDelay);
var mapping = new Mapping(Guid.NewGuid(), string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null); var mapping = new Mapping(Guid.NewGuid(), _updatedAt, string.Empty, string.Empty, null, _settings, request, response, 42, null, null, null, null, null, false, null);
// Act // Act
var model = _sut.ToMappingModel(mapping); var model = _sut.ToMappingModel(mapping);

View File

@@ -25,9 +25,12 @@ public class ProxyMappingConverterTests
var guidUtilsMock = new Mock<IGuidUtils>(); var guidUtilsMock = new Mock<IGuidUtils>();
guidUtilsMock.Setup(g => g.NewGuid()).Returns(Guid.Parse("ff55ac0a-fea9-4d7b-be74-5e483a2c1305")); guidUtilsMock.Setup(g => g.NewGuid()).Returns(Guid.Parse("ff55ac0a-fea9-4d7b-be74-5e483a2c1305"));
var dateTimeUtilsMock = new Mock<IDateTimeUtils>();
dateTimeUtilsMock.SetupGet(d => d.UtcNow).Returns(new DateTime(2022, 12, 4));
_mappingConverter = new MappingConverter(new MatcherMapper(_settings)); _mappingConverter = new MappingConverter(new MatcherMapper(_settings));
_sut = new ProxyMappingConverter(_settings, guidUtilsMock.Object); _sut = new ProxyMappingConverter(_settings, guidUtilsMock.Object, dateTimeUtilsMock.Object);
} }
[Fact] [Fact]

View File

@@ -1,5 +1,6 @@
{ {
"Guid": "ff55ac0a-fea9-4d7b-be74-5e483a2c1305", "Guid": "ff55ac0a-fea9-4d7b-be74-5e483a2c1305",
"UpdatedAt": "2022-12-04T00:00:00",
"Title": "my title", "Title": "my title",
"Description": "my description", "Description": "my description",
"Priority": -2000000, "Priority": -2000000,