public void Ctor_Throws_Error_When_Heap_Instance_Is_Null(AbstractSizableBinaryHeap <int> heap)
        {
            var ex = Assert.Throws <DdnDfException>(() =>
            {
                var _ = new LockBasedConcurrentHeap <int>(heap);
            });

            Assert.NotNull(ex);
            Assert.IsTrue(ex.ErrorCode.Equals(DdnDfErrorCode.NullObject));
            Assert.True(new LockBasedConcurrentHeap <int>(new ConcurrentMinHeap <int>(0)).IsEmpty);
        }
        public void IEnumerable_Is_Well_Implemented()
        {
            var instance = new LockBasedConcurrentHeap <int>(new MinHeap <int>(3))
            {
                1,
                2,
                3
            };

            Assert.IsFalse(instance.TryAdd(4));
            var results = new HashSet <int> {
                1, 2, 3
            };

            ((IEnumerable)instance).ForEach(x => results.Remove((int)x));
            Assert.IsTrue(results.Count == 0);
        }
        public void Properties_Are_Accessed_Inside_Lock()
        {
            var syncRoot = new object();
            var heap     = Substitute.For <IResizableHeap <int> >();

            heap.IsEmpty.Returns(x =>
            {
                Assert.IsTrue(Monitor.IsEntered(syncRoot));
                return(true);
            });
            heap.IsFull.Returns(x =>
            {
                Assert.IsTrue(Monitor.IsEntered(syncRoot));
                return(true);
            });
            heap.Count.Returns(x =>
            {
                Assert.IsTrue(Monitor.IsEntered(syncRoot));
                return(1);
            });
            heap.CanResize.Returns(x =>
            {
                Assert.IsTrue(Monitor.IsEntered(syncRoot));
                return(true);
            });
            heap.Capacity.Returns(x =>
            {
                Assert.IsTrue(Monitor.IsEntered(syncRoot));
                return(1);
            });
            var instance = new LockBasedConcurrentHeap <int>(heap, syncRoot);

            Assert.True(instance.IsEmpty);
            Assert.True(instance.CanResize);
            Assert.True(instance.IsFull);
            Assert.IsTrue(instance.Count == 1);
            Assert.IsTrue(instance.Capacity == 1);
            var _ = heap.Received(1).IsFull;

            _ = heap.Received(1).IsEmpty;
            _ = heap.Received(1).CanResize;
            var __ = heap.Received(1).Count;

            __ = heap.Received(1).Capacity;
        }