Esempio n. 1
0
        public async Task ExceptionBefore()
        {
            string result = "";

            var scheduler = new TestAsyncScheduler();

            var catched = false;

            try
            {
                await AsyncObservable.Range(0, 5)
                .Do(i => result += i)
                .Do(i =>
                {
                    if (i == 2)
                    {
                        throw new TestException();
                    }
                })
                .Prefetch()
                .Do(i => result += i)
                .SubscribeAsync()
                .ConfigureAwait(false);
            }
            catch (TestException)
            {
                catched = true;
            }

            catched
            .Should().BeTrue();
            result
            .Should().Be("00112");
        }
Esempio n. 2
0
        public async Task ConsumeSlowlySingle()
        {
            var scheduler = new TestAsyncScheduler();

            var result = await scheduler.RunAsync(async() =>
            {
                var inner = AsyncObservable.Range(0, 5);

                return(await new [] { inner }
                       .ToAsyncObservable()
                       .Merge()
                       .ConsumeSlowly(scheduler,
                                      10.Seconds(),
                                      10.Seconds(),
                                      10.Seconds(),
                                      10.Seconds(),
                                      10.Seconds()));
            });

            result
            .Should().Equal(
                (0, 10.Seconds()),
                (1, 20.Seconds()),
                (2, 30.Seconds()),
                (3, 40.Seconds()),
                (4, 50.Seconds()));
        }
Esempio n. 3
0
        public async Task RangeFalse()
        {
            var value = await AsyncObservable.Range(0, 10).AllAsync(i => i != 0);

            value
            .Should().Be(false);
        }
Esempio n. 4
0
        public async Task Range()
        {
            var value = await AsyncObservable.Range(0, 10).ToListAsync();

            value
            .Should().Equal(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
        }
Esempio n. 5
0
        public async Task Count10()
        {
            var value = await AsyncObservable.Range(0, 10).AnyAsync();

            value
            .Should().Be(true);
        }
Esempio n. 6
0
        public async Task Count10WithPredicate2()
        {
            var value = await AsyncObservable.Range(0, 10).AnyAsync(i => i > 20);

            value
            .Should().Be(false);
        }
Esempio n. 7
0
        public async Task Count10()
        {
            var value = await AsyncObservable.Range(1, 10).FirstAsync();

            value
            .Should().Be(1);
        }
        public async Task IntermediateCancel()
        {
            var result    = "";
            var scheduler = new TestAsyncScheduler();

            await scheduler.RunAsync(async() =>
            {
                using (var cts = new CancellationTokenSource())
                {
                    var t1 = AsyncObservable.Range(0, 10)
                             .Select(async(i, ca) =>
                    {
                        await scheduler.Delay(20.Seconds(), ca);
                        return(i);
                    })
                             .SubscribeAsync(i => result += i, onCompleted: () => result += "C", ca: cts.Token);

                    await scheduler.Delay(50.Seconds(), default);
                    cts.Cancel();
                    await t1;
                }

                return(Unit.Default);
            });

            result
            .Should().Be("01");
        }
Esempio n. 9
0
        public async Task RangeTrue()
        {
            var value = await AsyncObservable.Range(0, 10).AllAsync(i => i < 20);

            value
            .Should().Be(true);
        }
Esempio n. 10
0
        static async Task SelectManyAsync()
        {
            var res = from i in AsyncObservable.Range(0, 10)
                      from j in AsyncObservable.Range(i * 10, 10)
                      select i + " -> " + j;

            await res.SubscribeAsync(Print <string>());
        }
Esempio n. 11
0
        public async Task Cancellation()
        {
            var result = "";
            var value  = await AsyncObservable.Range(1, 10).Do(i => result += i).FirstAsync();

            result
            .Should().Be("1");
        }
Esempio n. 12
0
 public static IAsyncObservable <int> ProduceSlowly(this IAsyncScheduler scheduler, params TimeSpan[] delays)
 {
     return(AsyncObservable.Range(0, delays.Length)
            .Select(async(i, ca) =>
     {
         await scheduler.Delay(delays[i], ca).ConfigureAwait(false);
         return i;
     }));
 }
Esempio n. 13
0
        public async Task Already_Ordered()
        {
            var l = await AsyncObservable.Range(1, 5)
                    .OrderBy(v => v)
                    .ToListAsync();

            l
            .Should().Equal(1, 2, 3, 4, 5);
        }
Esempio n. 14
0
        public async Task Inverse()
        {
            var l = await AsyncObservable.Range(1, 5)
                    .OrderBy(v => - v)
                    .ToListAsync();

            l
            .Should().Equal(5, 4, 3, 2, 1);
        }
Esempio n. 15
0
        public async Task Int_Intermediate_Range()
        {
            var result = await AsyncObservable.Range(0, 3)
                         .Max(intermediateResults: true)
                         .ToListAsync();

            result
            .Should()
            .BeEquivalentTo(0, 1, 2);
        }
Esempio n. 16
0
        public async Task NegativStartPoint()
        {
            string result = "";

            await AsyncObservable.Range(-3, 5)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("-3-2-101C");
        }
Esempio n. 17
0
        public async Task Count0()
        {
            string result = "";

            await AsyncObservable.Range(0, 0)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("C");
        }
Esempio n. 18
0
        public async Task Select1()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .Select(i => 9 - i)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("9876543210C");
        }
Esempio n. 19
0
        public async Task WhereAll()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .Where(_ => true)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("0123456789C");
        }
Esempio n. 20
0
        public async Task WhereNone()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .Where(_ => false)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("C");
        }
Esempio n. 21
0
        public async Task WhereOdd()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .Where(i => i % 2 != 0)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("13579C");
        }
Esempio n. 22
0
 static async Task ConcatAsync()
 {
     await
     AsyncObservable.Concat(
         AsyncObservable.Range(0, 5),
         AsyncObservable.Range(5, 5),
         AsyncObservable.Range(10, 5),
         AsyncObservable.Range(15, 5)
         )
     .SubscribeAsync(Print <int>());    // TODO: Use ForEachAsync.
 }
Esempio n. 23
0
        public async Task Select2()
        {
            string result = "";

            await AsyncObservable.Range(0, 3)
            .SelectMany(i => Enumerable.Range(i * 2, 2))
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("012345C");
        }
        public async Task All()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .DistinctUntilChanged()
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("0123456789C");
        }
Esempio n. 25
0
        public void ThrowingComparer()
        {
            Func <Task> func = async() =>
                               await AsyncObservable.Range(0, 4)
                               .OrderBy(x => x, new IntThrowingComparer())
                               .ToListAsync();

            func
            .Should().Throw <Exception>()
            .WithMessage("test");
        }
Esempio n. 26
0
        public async Task Take1()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .Take(2)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("01C");
        }
Esempio n. 27
0
        public async Task DistinctByMod()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .DistinctBy(v => v % 3)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("012C");
        }
Esempio n. 28
0
        public async Task Skip5()
        {
            string result = "";

            await AsyncObservable.Range(0, 10)
            .Skip(5)
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("56789C");
        }
Esempio n. 29
0
        public async Task Long_Intermediate_Range()
        {
            var result = await AsyncObservable.Range(0, 3)
                         .Select(i => (long)i)
                         .Max(intermediateResults: true)
                         .ToListAsync();

            result
            .Should()
            .BeEquivalentTo(0L, 1L, 2L);
        }
Esempio n. 30
0
        public void ArgumentExceptions()
        {
            var obs1 = AsyncObservable.Range(0, 10);
            var obs2 = (IAsyncObservable <int>)null;

            obs1.Invoking(o => o.Skip(-1))
            .Should().Throw <ArgumentOutOfRangeException>();
            obs2.Invoking(o => o.Skip(2))
            .Should().Throw <ArgumentNullException>();
            obs2.Invoking(o => o.Skip(-1))
            .Should().Throw <ArgumentNullException>();
        }