Skip to content

Commit

Permalink
ProxyHelper fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StefH committed Jul 29, 2022
1 parent be4b0ad commit e7754d1
Show file tree
Hide file tree
Showing 13 changed files with 903 additions and 855 deletions.
1 change: 1 addition & 0 deletions WireMock.Net Solution.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SSL/@EntryIndexedValue">SSL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TE/@EntryIndexedValue">TE</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TSV/@EntryIndexedValue">TSV</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TTL/@EntryIndexedValue">TTL</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=WWW/@EntryIndexedValue">WWW</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XMS/@EntryIndexedValue">XMS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=XUA/@EntryIndexedValue">XUA</s:String>
Expand Down
33 changes: 16 additions & 17 deletions src/WireMock.Net.Abstractions/Models/ITimeSettings.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using System;

namespace WireMock.Models
namespace WireMock.Models;

/// <summary>
/// TimeSettings: Start, End and TTL
/// </summary>
public interface ITimeSettings
{
/// <summary>
/// TimeSettings: Start, End and TTL
/// Gets or sets the DateTime from which this mapping should be used. In case this is not defined, it's used (default behavior).
/// </summary>
public interface ITimeSettings
{
/// <summary>
/// Gets or sets the DateTime from which this mapping should be used. In case this is not defined, it's used (default behavior).
/// </summary>
DateTime? Start { get; set; }
DateTime? Start { get; set; }

/// <summary>
/// Gets or sets the DateTime from until this mapping should be used. In case this is not defined, it's used forever (default behavior).
/// </summary>
DateTime? End { get; set; }
/// <summary>
/// Gets or sets the DateTime from until this mapping should be used. In case this is not defined, it's used forever (default behavior).
/// </summary>
DateTime? End { get; set; }

/// <summary>
/// Gets or sets the TTL (Time To Live) in seconds for this mapping. In case this is not defined, it's used (default behavior).
/// </summary>
int? TTL { get; set; }
}
/// <summary>
/// Gets or sets the TTL (Time To Live) in seconds for this mapping. In case this is not defined, it's used (default behavior).
/// </summary>
int? TTL { get; set; }
}
47 changes: 23 additions & 24 deletions src/WireMock.Net/Extensions/TimeSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
using System;
using JetBrains.Annotations;
using WireMock.Models;

namespace WireMock.Extensions
namespace WireMock.Extensions;

internal static class TimeSettingsExtensions
{
internal static class TimeSettingsExtensions
public static bool IsValid(this ITimeSettings? settings)
{
public static bool IsValid([CanBeNull] this ITimeSettings settings)
if (settings == null)
{
if (settings == null)
{
return true;
}
return true;
}

var now = DateTime.Now;
var start = settings.Start != null ? settings.Start.Value : now;
DateTime end;
if (settings.End != null)
{
end = settings.End.Value;
}
else if (settings.TTL != null)
{
end = start.AddSeconds(settings.TTL.Value);
}
else
{
end = DateTime.MaxValue;
}
var now = DateTime.Now;
var start = settings.Start ?? now;
DateTime end;

return now >= start && now <= end;
if (settings.End != null)
{
end = settings.End.Value;
}
else if (settings.TTL != null)
{
end = start.AddSeconds(settings.TTL.Value);
}
else
{
end = DateTime.MaxValue;
}

return now >= start && now <= end;
}
}
8 changes: 4 additions & 4 deletions src/WireMock.Net/IMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ public interface IMapping
/// <summary>
/// Gets the TimeSettings (Start, End and TTL).
/// </summary>
ITimeSettings TimeSettings { get; }
ITimeSettings? TimeSettings { get; }

/// <summary>
/// Gets the unique title.
/// </summary>
string Title { get; }
string? Title { get; }

/// <summary>
/// Gets the description.
/// </summary>
string Description { get; }
string? Description { get; }

/// <summary>
/// The full filename path for this mapping (only defined for static mappings).
/// </summary>
string Path { get; set; }
string? Path { get; set; }

/// <summary>
/// Gets the priority. (A low value means higher priority.)
Expand Down
Loading

0 comments on commit e7754d1

Please sign in to comment.