public async Task Map_7_Should_Return_Result()
        {
            var record = Substitute.For <IRecord>();

            record[0].Returns(1);
            record[1].Returns(2);
            record[2].Returns(3);
            record[3].Returns(4);
            record[4].Returns(5);
            record[5].Returns(6);
            record[6].Returns(7);

            var mockAsyncEnumerable = new MockAsyncEnumerable(record);

            var result = await mockAsyncEnumerable.Map((int value1, int value2, int value3, int value4, int value5,
                                                        int value6, int value7) => new[]
            {
                value1,
                value2,
                value3,
                value4,
                value5,
                value6,
                value7
            }).SingleAsync().ConfigureAwait(false);

            Assert.AreEqual(1, result[0]);
            Assert.AreEqual(2, result[1]);
            Assert.AreEqual(3, result[2]);
            Assert.AreEqual(4, result[3]);
            Assert.AreEqual(5, result[4]);
            Assert.AreEqual(6, result[5]);
            Assert.AreEqual(7, result[6]);
        }
Beispiel #2
0
        public async Task <IAsyncEnumerable <TKey> > CreateKeyEnumerableAsync(ITransaction tx, EnumerationMode enumerationMode, TimeSpan timeout, CancellationToken cancellationToken)
        {
            var keys = new System.Collections.Generic.List <TKey>();

            try
            {
                BeginTransaction(tx);
                foreach (var key in Dictionary.Keys)
                {
                    await LockManager.AcquireLock(tx.TransactionId, key, LockMode.Default, timeout, cancellationToken);

                    keys.Add(key);
                }

                if (enumerationMode == EnumerationMode.Ordered)
                {
                    keys.Sort();
                }

                IAsyncEnumerable <TKey> result = new MockAsyncEnumerable <TKey>(keys);
                return(result);
            }
            catch
            {
                foreach (var key in keys)
                {
                    LockManager.ReleaseLock(tx.TransactionId, key);
                }

                throw;
            }
        }
        public async Task Map_5_Should_Return_Result()
        {
            var record = Substitute.For <IRecord>();

            record[0].Returns(1);
            record[1].Returns(2);
            record[2].Returns(3);
            record[3].Returns(4);
            record[4].Returns(5);

            var mockAsyncEnumerable = new MockAsyncEnumerable(record);

            var result = await mockAsyncEnumerable.Map((int value1, int value2, int value3, int value4, int value5) => new[]
            {
                value1,
                value2,
                value3,
                value4,
                value5
            }).SingleAsync();

            Assert.AreEqual(1, result[0]);
            Assert.AreEqual(2, result[1]);
            Assert.AreEqual(3, result[2]);
            Assert.AreEqual(4, result[3]);
            Assert.AreEqual(5, result[4]);
        }
        public async Task Map_15_Should_Return_Result()
        {
            var record = Substitute.For <IRecord>();

            record[0].Returns(1);
            record[1].Returns(2);
            record[2].Returns(3);
            record[3].Returns(4);
            record[4].Returns(5);
            record[5].Returns(6);
            record[6].Returns(7);
            record[7].Returns(8);
            record[8].Returns(9);
            record[9].Returns(10);
            record[10].Returns(11);
            record[11].Returns(12);
            record[12].Returns(13);
            record[13].Returns(14);
            record[14].Returns(15);

            var mockAsyncEnumerable = new MockAsyncEnumerable(record);

            var result = await mockAsyncEnumerable.Map((int value1, int value2, int value3, int value4, int value5,
                                                        int value6, int value7, int value8, int value9, int value10, int value11,
                                                        int value12, int value13, int value14, int value15) => new[]
            {
                value1,
                value2,
                value3,
                value4,
                value5,
                value6,
                value7,
                value8,
                value9,
                value10,
                value11,
                value12,
                value13,
                value14,
                value15
            }).SingleAsync().ConfigureAwait(false);

            Assert.AreEqual(1, result[0]);
            Assert.AreEqual(2, result[1]);
            Assert.AreEqual(3, result[2]);
            Assert.AreEqual(4, result[3]);
            Assert.AreEqual(5, result[4]);
            Assert.AreEqual(6, result[5]);
            Assert.AreEqual(7, result[6]);
            Assert.AreEqual(8, result[7]);
            Assert.AreEqual(9, result[8]);
            Assert.AreEqual(10, result[9]);
            Assert.AreEqual(11, result[10]);
            Assert.AreEqual(12, result[11]);
            Assert.AreEqual(13, result[12]);
            Assert.AreEqual(14, result[13]);
            Assert.AreEqual(15, result[14]);
        }
        public async Task Map_Should_Return_Result()
        {
            var record = Substitute.For <IRecord>();

            record[0].Returns(1);

            var mockAsyncEnumerable = new MockAsyncEnumerable(record);
            var result = await mockAsyncEnumerable.Map <int>().SingleAsync().ConfigureAwait(false);

            Assert.AreEqual(1, result);
        }
        public async Task Map_2_Should_Return_Result()
        {
            var record = Substitute.For <IRecord>();

            record[0].Returns(1);
            record[1].Returns(2);

            var mockAsyncEnumerable = new MockAsyncEnumerable(record);

            var result = await mockAsyncEnumerable.Map((int value1, int value2) => new[]
            {
                value1,
                value2
            }).SingleAsync().ConfigureAwait(false);

            Assert.AreEqual(1, result[0]);
            Assert.AreEqual(2, result[1]);
        }
Beispiel #7
0
        public async Task <IAsyncEnumerable <KeyValuePair <TKey, TValue> > > CreateEnumerableAsync(ITransaction tx, Func <TKey, bool> filter, EnumerationMode enumerationMode)
        {
            List <TKey> keys = new List <TKey>();

            try
            {
                BeginTransaction(tx);

                foreach (var key in Dictionary.Keys)
                {
                    if (filter == null || filter(key))
                    {
                        await LockManager.AcquireLock(tx.TransactionId, key, LockMode.Default);

                        keys.Add(key);
                    }
                }

                if (enumerationMode == EnumerationMode.Ordered)
                {
                    keys.Sort();
                }

                IAsyncEnumerable <KeyValuePair <TKey, TValue> > result = new MockAsyncEnumerable <KeyValuePair <TKey, TValue> >(keys.Select(k => new KeyValuePair <TKey, TValue>(k, Dictionary[k])));
                return(result);
            }
            catch
            {
                foreach (var key in keys)
                {
                    LockManager.ReleaseLock(tx.TransactionId, key);
                }

                throw;
            }
        }