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

f2calv / CasCap.Common / 16933690265

13 Aug 2025 09:48AM UTC coverage: 0.32%. Remained the same
16933690265

push

github

web-flow
F2calv/2025 08 updates2 (#220)

* NoWarn updates

* re-added netstandard2.0 target

0 of 352 branches covered (0.0%)

Branch coverage included in aggregate %.

0 of 7 new or added lines in 4 files covered. (0.0%)

3 existing lines in 2 files now uncovered.

3 of 585 relevant lines covered (0.51%)

0.01 hits per line

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

0.0
/src/CasCap.Common.Extensions/Models/FixedSizeQueue.cs
1
namespace CasCap.Models;
2

3
//https://stackoverflow.com/questions/5852863/fixed-size-queue-which-automatically-dequeues-old-values-upon-new-enques
4
[Serializable]
5
[DebuggerDisplay("Count = {" + nameof(Count) + "}, Limit = {" + nameof(Limit) + "}")]
6
public class FixedSizedQueue<T> : IReadOnlyCollection<T>
7
{
8
    private readonly Queue<T> _queue = new();
×
9
    private readonly object _lock = new();
×
10

11
    public int Count { get { lock (_lock) { return _queue.Count; } } }
×
12
    public int Limit { get; }
×
13

14
    public FixedSizedQueue(int limit)
×
15
    {
16
#if NET8_0_OR_GREATER
UNCOV
17
        ArgumentOutOfRangeException.ThrowIfLessThan(limit, 1);
×
18
#endif
19
        Limit = limit;
×
20
    }
×
21

22
    public FixedSizedQueue(int limit, IEnumerable<T> collection)//own addition
×
23
    {
24
#if NET8_0_OR_GREATER
UNCOV
25
        ArgumentOutOfRangeException.ThrowIfLessThan(limit, 1);
×
26
#endif
27
        if (collection is null || !collection.Any())
×
28
            throw new ArgumentException("Can not initialize the Queue with a null or empty collection", nameof(collection));
×
29

30
        _queue = new Queue<T>(collection);
×
31
        Limit = limit;
×
32
    }
×
33

34
    public FixedSizedQueue(IEnumerable<T> collection)
×
35
    {
36
        if (collection is null || !collection.Any())
×
37
            throw new ArgumentException("Can not initialize the Queue with a null or empty collection", nameof(collection));
×
38

39
        _queue = new Queue<T>(collection);
×
40
        Limit = _queue.Count;
×
41
    }
×
42

43
    public void Enqueue(T obj)
44
    {
45
        lock (_lock)
×
46
        {
47
            _queue.Enqueue(obj);
×
48

49
            while (_queue.Count > Limit)
×
50
                _queue.Dequeue();
×
51
        }
×
52
    }
×
53

54
    public void Clear()
55
    {
56
        lock (_lock)
×
57
            _queue.Clear();
×
58
    }
×
59

60
    public IEnumerator<T> GetEnumerator()
61
    {
62
        lock (_lock)
×
63
            return new List<T>(_queue).GetEnumerator();
×
64
    }
×
65

66
    IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
×
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc