Summary

Class:WireMock.Util.ConcurentObservableCollection`1
Assembly:WireMock.Net
File(s):C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Util\ConcurentObservableCollection.cs
Covered lines:20
Uncovered lines:14
Coverable lines:34
Total lines:77
Line coverage:58.8%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
.ctor()10100100
.ctor(...)1000
.ctor(...)1000
ClearItems()20100100
RemoveItem(...)20100100
InsertItem(...)20100100
SetItem(...)2000
MoveItem(...)2000

File(s)

C:\Users\azureuser\Documents\Github\WireMock.Net\src\WireMock.Net\Util\ConcurentObservableCollection.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Collections.ObjectModel;
 3
 4namespace WireMock.Util
 5{
 6    /// <summary>
 7    /// A special Collection that overrides methods of <see cref="ObservableCollection{T}"/> to make them thread safe
 8    /// </summary>
 9    /// <typeparam name="T">The type of elements in the collection.</typeparam>
 10    /// <inheritdoc cref="ObservableCollection{T}" />
 11    public class ConcurentObservableCollection<T> : ObservableCollection<T>
 12    {
 4713        private readonly object _lockObject = new object();
 14
 15        /// <summary>
 16        /// Initializes a new instance of the <see cref="T:WireMock.Util.ConcurentObservableCollection`1" /> class.
 17        /// </summary>
 14118        public ConcurentObservableCollection() { }
 19
 20        /// <summary>
 21        /// Initializes a new instance of the <see cref="ConcurentObservableCollection{T}"/> class that contains element
 22        /// </summary>
 23        /// <param name="list">The list from which the elements are copied.</param>
 024        public ConcurentObservableCollection(List<T> list) : base(list) { }
 25
 26        /// <summary>
 27        /// Initializes a new instance of the <see cref="ConcurentObservableCollection{T}"/> class that contains element
 28        /// </summary>
 29        /// <param name="collection">The collection from which the elements are copied.</param>
 030        public ConcurentObservableCollection(IEnumerable<T> collection) : base(collection) { }
 31
 32        /// <inheritdoc cref="ObservableCollection{T}.ClearItems"/>
 33        protected override void ClearItems()
 134        {
 135            lock (_lockObject)
 136            {
 137                base.ClearItems();
 138            }
 139        }
 40
 41        /// <inheritdoc cref="ObservableCollection{T}.RemoveItem"/>
 42        protected override void RemoveItem(int index)
 143        {
 144            lock (_lockObject)
 145            {
 146                base.RemoveItem(index);
 147            }
 148        }
 49
 50        /// <inheritdoc cref="ObservableCollection{T}.InsertItem"/>
 51        protected override void InsertItem(int index, T item)
 5352        {
 5353            lock (_lockObject)
 5354            {
 5355                base.InsertItem(index, item);
 5356            }
 5357        }
 58
 59        /// <inheritdoc cref="ObservableCollection{T}.SetItem"/>
 60        protected override void SetItem(int index, T item)
 061        {
 062            lock (_lockObject)
 063            {
 064                base.SetItem(index, item);
 065            }
 066        }
 67
 68        /// <inheritdoc cref="ObservableCollection{T}.MoveItem"/>
 69        protected override void MoveItem(int oldIndex, int newIndex)
 070        {
 071            lock (_lockObject)
 072            {
 073                base.MoveItem(oldIndex, newIndex);
 074            }
 075        }
 76    }
 77}