Exemplo n.º 1
0
        public async Task AddCompleteTakeTake()
        {               //****************************************
            var MyCollection = new AsyncCollection <int>();
            //****************************************

            await MyCollection.AddComplete(42);

            var Result = await MyCollection.Take();

            try
            {
                _ = await MyCollection.Take();

                Assert.Fail("Should not reach here");
            }
            catch (InvalidOperationException)
            {
            }

            //****************************************

            Assert.AreEqual(0, MyCollection.Count, "Count not as expected");
            Assert.AreEqual(42, Result, "Result not as expected");

            Assert.IsTrue(MyCollection.IsCompleted, "Not completed");
        }
Exemplo n.º 2
0
        public async Task AddCompleteAdd()
        {               //****************************************
            var MyCollection = new AsyncCollection <int>();
            //****************************************

            await MyCollection.AddComplete(42);

            Assert.IsFalse(await MyCollection.Add(84));

            //****************************************

            Assert.AreEqual(1, MyCollection.Count, "Count not as expected");

            Assert.IsTrue(MyCollection.IsAddingCompleted, "Not completed");
        }
Exemplo n.º 3
0
        public void AddComplete()
        {               //****************************************
            var MyCollection = new AsyncCollection <int>();
            //****************************************

            var MyTask = MyCollection.AddComplete(42);

            //****************************************

            Assert.IsTrue(MyTask.IsCompleted, "Still waiting to add");

            Assert.AreEqual(1, MyCollection.Count, "Count not as expected");

            Assert.IsTrue(MyCollection.IsAddingCompleted, "Not completed");
        }
Exemplo n.º 4
0
        private async Task ProducerWithAddComplete <TItem>(AsyncCollection <TItem> collection, int count, Func <int, TItem> producer)
        {
            for (var Index = 0; Index < count; Index++)
            {
                if (Index == count - 1)
                {
                    await collection.AddComplete(producer(Index));
                }
                else
                {
                    await collection.Add(producer(Index));
                }

                await Task.Yield();
            }
        }
Exemplo n.º 5
0
        public async Task AddCompleteTake()
        {               //****************************************
            var MyCollection = new AsyncCollection <int>();
            //****************************************

            await MyCollection.AddComplete(42);

            var MyTask = MyCollection.Take();

            //****************************************

            Assert.IsTrue(MyTask.IsCompleted, "Still waiting to take");

            Assert.AreEqual(0, MyCollection.Count, "Count not as expected");

            Assert.IsTrue(MyCollection.IsCompleted, "Not completed");
        }
Exemplo n.º 6
0
        public async Task AddMaximumAddCompleteTake()
        {               //****************************************
            var MyCollection = new AsyncCollection <int>(1);
            //****************************************

            await MyCollection.Add(42);

            var MyTask = MyCollection.AddComplete(84);

            var MyResult = await MyCollection.Take();

            await MyTask;

            //****************************************

            Assert.AreEqual(42, MyResult, "Result was not as expected");

            Assert.AreEqual(1, MyCollection.Count, "Count not as expected");
            Assert.AreEqual(0, MyCollection.WaitingToAdd, "Waiting adders not as expected");

            Assert.IsTrue(MyCollection.IsAddingCompleted, "Adding is not completed");
        }