예제 #1
0
        public void TestConcurrentDuringContains()
        {
            var src    = TestUtils.EnumerateNothingForever <int>();
            var lookup = AsyncLookup <int, int> .ToLookup(src, x => x / 10, null);

            var t = lookup.ContainsAsync(0);

            Assert.IsFalse(t.IsCompleted);

            try
            {
                lookup.GetAsync(1).AwaitSynchronously();
                Assert.Fail();
            }
            catch (InvalidOperationException)
            { }

            try
            {
                lookup.ContainsAsync(1).AwaitSynchronously();
                Assert.Fail();
            }
            catch (InvalidOperationException)
            { }
        }
예제 #2
0
        public void TestSimple()
        {
            int             n           = 100;
            Func <int, int> keySelector = x => x / 10;

            var src            = Enumerable.Range(0, n);
            var expectedLookup = src.ToLookup(keySelector);
            var lookup         = AsyncLookup <int, int> .ToLookup(src.AsAsyncEnumerable(), keySelector, null);

            foreach (var expected in expectedLookup)
            {
                var actual = lookup.GetAsync(expected.Key).AwaitSynchronously();
                Assert.IsNotNull(actual);
                Assert.IsTrue(expected.SequenceEqual(actual.AsEnumerable()));
                Assert.IsTrue(lookup.ContainsAsync(expected.Key).AwaitSynchronously());
            }

            Assert.AreEqual(expectedLookup.Count, lookup.CountAsync().AwaitSynchronously());
            Assert.IsTrue(expectedLookup.Select(x => x.Key).SequenceEqual(lookup.Select(x => x.Key).AsEnumerable()));

            var emptySeq = lookup.GetAsync(-1).AwaitSynchronously();

            Assert.IsNotNull(emptySeq);
            Assert.AreEqual(0L, emptySeq.CountAsync().AwaitSynchronously());
            Assert.IsFalse(lookup.ContainsAsync(-1).AwaitSynchronously());
        }
예제 #3
0
        public void TestEmpty()
        {
            var lookup = AsyncLookup <int, int> .ToLookup(AsyncEnum.Empty <int>(), x => x, null);

            Assert.IsFalse(lookup.ContainsAsync(1).AwaitSynchronously());

            var seq = lookup.GetAsync(1).AwaitSynchronously();

            Assert.IsNotNull(seq);
            Assert.AreEqual(0L, seq.CountAsync().AwaitSynchronously());
        }
예제 #4
0
        public void TestReverse()
        {
            int             n           = 100;
            Func <int, int> keySelector = x => x / 10;

            var src            = Enumerable.Range(0, n);
            var expectedLookup = src.ToLookup(keySelector);
            var lookup         = AsyncLookup <int, int> .ToLookup(src.AsAsyncEnumerable(), keySelector, null);

            foreach (var expected in expectedLookup.Reverse())
            {
                var actual = lookup.GetAsync(expected.Key).AwaitSynchronously();
                Assert.IsNotNull(actual);
                Assert.IsTrue(expected.SequenceEqual(actual.AsEnumerable()));
                Assert.IsTrue(lookup.ContainsAsync(expected.Key).AwaitSynchronously());
            }
        }
예제 #5
0
 private void Lookup(Meebey.SmartIrc4net.IrcMessageData msg, string word)
 {
     AsyncLookup lookup = new AsyncLookup(this, msg, word);
     System.Threading.ThreadPool.QueueUserWorkItem(AsyncLookup.Run, lookup);
 }