Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mapping"/> class.
 /// </summary>
 /// <param name="guid">The unique identifier.</param>
 /// <param name="title">The unique title (can be null).</param>
 /// <param name="path">The full file path from this mapping title (can be null).</param>
 /// <param name="settings">The WireMockServerSettings.</param>
 /// <param name="requestMatcher">The request matcher.</param>
 /// <param name="provider">The provider.</param>
 /// <param name="priority">The priority for this mapping.</param>
 /// <param name="scenario">The scenario. [Optional]</param>
 /// <param name="executionConditionState">State in which the current mapping can occur. [Optional]</param>
 /// <param name="nextState">The next state which will occur after the current mapping execution. [Optional]</param>
 /// <param name="stateTimes">Only when the current state is executed this number, the next state which will occur. [Optional]</param>
 /// <param name="webhooks">The Webhooks. [Optional]</param>
 /// <param name="timeSettings">The TimeSettings. [Optional]</param>
 public Mapping(
     Guid guid,
     [CanBeNull] string title,
     [CanBeNull] string path,
     [NotNull] IWireMockServerSettings settings,
     [NotNull] IRequestMatcher requestMatcher,
     [NotNull] IResponseProvider provider,
     int priority,
     [CanBeNull] string scenario,
     [CanBeNull] string executionConditionState,
     [CanBeNull] string nextState,
     [CanBeNull] int?stateTimes,
     [CanBeNull] IWebhook[] webhooks,
     [CanBeNull] ITimeSettings timeSettings)
 {
     Guid                    = guid;
     Title                   = title;
     Path                    = path;
     Settings                = settings;
     RequestMatcher          = requestMatcher;
     Provider                = provider;
     Priority                = priority;
     Scenario                = scenario;
     ExecutionConditionState = executionConditionState;
     NextState               = nextState;
     StateTimes              = stateTimes;
     Webhooks                = webhooks;
     TimeSettings            = timeSettings;
 }
        public static bool IsValid([CanBeNull] this ITimeSettings settings)
        {
            if (settings == null)
            {
                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;
            }

            return(now >= start && now <= end);
        }
        /// <inheritdoc />
        public IRespondWithAProvider WithTimeSettings(ITimeSettings timeSettings)
        {
            Check.NotNull(timeSettings, nameof(timeSettings));

            TimeSettings = timeSettings;

            return(this);
        }
Ejemplo n.º 4
0
 public static TimeSettingsModel Map(ITimeSettings settings)
 {
     return(settings != null ? new TimeSettingsModel
     {
         Start = settings.Start,
         End = settings.End,
         TTL = settings.TTL
     } : null);
 }