• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ImmediatePlatform / Immediate.Jobs / 30300691995

27 Jul 2026 08:00PM UTC coverage: 64.845%. First build
30300691995

Pull #20

github

web-flow
Merge a73d5f4ed into e8a73c280
Pull Request #20: Initial draft

1300 of 1892 new or added lines in 29 files covered. (68.71%)

1649 of 2543 relevant lines covered (64.84%)

2.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/src/Immediate.Jobs.Testing/CaptureOnlyJobScheduler.cs
1
namespace Immediate.Jobs.Testing;
2

3
/// <summary>
4
/// A storage-free implementation of <see cref="IJobScheduler{TPayload}"/> that records scheduled calls.
5
/// </summary>
6
public class CaptureOnlyJobScheduler<TPayload>(TimeProvider? timeProvider = null) : IJobScheduler<TPayload>
4✔
7
{
8
        private readonly List<ScheduledJobCapture<TPayload>> _captures = [];
4✔
9
        private readonly TimeProvider _timeProvider = timeProvider ?? TimeProvider.System;
4✔
10

11
        /// <summary>All calls captured in call order.</summary>
12
        public IReadOnlyList<ScheduledJobCapture<TPayload>> Captures => _captures;
4✔
13

14
        /// <summary>The latest captured call, or <see langword="null"/> when none exists.</summary>
NEW
15
        public ScheduledJobCapture<TPayload>? Last => _captures.Count == 0 ? null : _captures[^1];
×
16

17
        /// <inheritdoc />
18
        public virtual ValueTask<string> Enqueue(TPayload payload, CancellationToken cancellationToken = default) =>
19
                Capture(payload, _timeProvider.GetUtcNow(), cancellationToken);
4✔
20

21
        /// <inheritdoc />
22
        public virtual ValueTask<string> Schedule(
23
                TPayload payload,
24
                TimeSpan delay,
25
                CancellationToken cancellationToken = default
26
        )
27
        {
28
                if (delay < TimeSpan.Zero)
4✔
NEW
29
                        throw new ArgumentOutOfRangeException(nameof(delay), "A job delay cannot be negative.");
×
30
                return Capture(payload, _timeProvider.GetUtcNow() + delay, cancellationToken);
4✔
31
        }
32

33
        /// <inheritdoc />
34
        public virtual ValueTask<string> ScheduleAt(
35
                TPayload payload,
36
                DateTimeOffset runAt,
37
                CancellationToken cancellationToken = default
38
        ) => Capture(payload, runAt, cancellationToken);
4✔
39

40
        /// <summary>Clears every captured call.</summary>
NEW
41
        public void Clear() => _captures.Clear();
×
42

43
        /// <summary>Creates invocation identifiers. Override when a test requires predictable identifiers.</summary>
44
        protected virtual string CreateId() => Guid.NewGuid().ToString("N");
4✔
45

46
        private ValueTask<string> Capture(TPayload payload, DateTimeOffset runAt, CancellationToken cancellationToken)
47
        {
48
                cancellationToken.ThrowIfCancellationRequested();
4✔
49
                var id = CreateId();
4✔
50
                _captures.Add(new(id, payload, runAt));
4✔
51
                return ValueTask.FromResult(id);
4✔
52
        }
53
}
54

55
/// <summary>A captured typed scheduler call.</summary>
56
public sealed record ScheduledJobCapture<TPayload>(string Id, TPayload Payload, DateTimeOffset RunAt);
4✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc