Ejemplo n.º 1
0
        public void CompleteAddingAnEmptyQueue()
        {
            using var q = new ConcurrentBufferedQueue <int, string>();

            q.CompleteAdding();
            q.IsAddingCompleted.Should().BeTrue();
            q.IsCompleted.Should().BeTrue();
        }
Ejemplo n.º 2
0
        public void AddAfterCompletionThrowsException()
        {
            using var q = new ConcurrentBufferedQueue <int, string>();

            q.CompleteAdding();

            var addAction = new Action(() => q.Add(1, "Hallo 1"));

            addAction.Should().Throw <InvalidOperationException>();
        }
Ejemplo n.º 3
0
        public void CallTakeAfterCompletingThrowsAnException()
        {
            using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source))
            {
                var takeAction = new Action(() =>
                {
                    var result = q.Take();
                });

                q.CompleteAdding();
                takeAction.Should().Throw <InvalidOperationException>();
            }
        }
Ejemplo n.º 4
0
        public void CallTakeAfterCompletingThrowsAnException()
        {
            using var q = new ConcurrentBufferedQueue <int, string>();

            bool?success    = null;
            var  takeAction = new Action(() => (success, _, _) = q.Take());

            q.CompleteAdding();
            takeAction();

            success.HasValue.Should().BeTrue();
            success.Value.Should().BeFalse();
        }
Ejemplo n.º 5
0
        public void CompletingTheBufferWhileTakeIsWaitingThrowsAnException()
        {
            using var q = new ConcurrentBufferedQueue <int, string>();

            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(50);  // Make sure Take is called before the next line is executed
                q.CompleteAdding();
            });

            var(success, _, _) = q.Take();
            success.Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void AddAfterCompletionThrowsException()
        {
            using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source))
            {
                q.CompleteAdding();

                var addAction = new Action(() =>
                {
                    q.Add(1, "Hallo 1");
                });

                addAction.ShouldThrow <InvalidOperationException>();
            }
        }
Ejemplo n.º 7
0
        public void CompleteAddingPropertiesWorkAsExpected()
        {
            using var q = new ConcurrentBufferedQueue <int, string>();

            q.Add(1, "Hallo 1");
            q.Add(2, "Hallo 2");

            q.CompleteAdding();
            q.IsAddingCompleted.Should().BeTrue();
            q.IsCompleted.Should().BeFalse();

            _ = q.Take();
            _ = q.Take();

            q.IsCompleted.Should().BeTrue();
        }
Ejemplo n.º 8
0
        public void CompletingTheBufferWhileTakeIsWaitingThrowsAnException()
        {
            using (var q = new ConcurrentBufferedQueue <int, string>(NullTime.Source))
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(50);  //Make sure Take is called before the next line is executed
                    q.CompleteAdding();
                });

                var takeAction = new Action(() =>
                {
                    var result = q.Take();
                });

                takeAction.Should().Throw <InvalidOperationException>();
            }
        }