Exemple #1
0
        public async Task Count1()
        {
            var value = await AsyncObservable.Return(1).FirstAsync();

            value
            .Should().Be(1);
        }
        public async Task Return1()
        {
            string result = "";

            await AsyncObservable.Return(1)
            .SubscribeAsync(i => result += i, ex => result += "E", () => result += "C");

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

            await AsyncObservable.Return(Unit.Default)
            .SelectMany(_ => Enumerable.Range(0, 10))
            .SubscribeAsync(i => result += i, onCompleted: () => result += "C");

            result
            .Should().Be("0123456789C");
        }
Exemple #4
0
        public async Task Finally4()
        {
            string result = "";

            await AsyncObservable.Return(1)
            .Finally(() => result       += "1")
            .Finally(() => result       += "2")
            .SubscribeAsync(i => result += "N", ex => result += "E", () => result += "C");

            result
            .Should().Be("N12C");
        }
Exemple #5
0
        public void AsyncWithoutSubscription()
        {
            var called = 0;

            AsyncObservable.Defer(() =>
            {
                Interlocked.Increment(ref called);
                return(new ValueTask <IAsyncObservable <int> >(AsyncObservable.Return(1)));
            });

            called
            .Should().Be(0);
        }
Exemple #6
0
        public async Task WithException2()
        {
            var result = default(Exception);

            await AsyncObservable.Defer(delegate()
            {
                throw new NotImplementedException();
                return(AsyncObservable.Return(1));
            })
            .SubscribeAsync(onError: ex => result = ex);

            result
            .Should().BeOfType <NotImplementedException>();
        }
Exemple #7
0
        public async Task Single()
        {
            string result = "";

            var range = AsyncObservable.Range(0, 3);

            await AsyncObservable.Return(range.Finally(() => result += "f"))
            .LazyConcat()
            .Finally(() => result       += "F")
            .SubscribeAsync(i => result += i, ex => result += "E", () => result += "C");

            result
            .Should().Be("012fFC");
        }
Exemple #8
0
        public async Task WithSubscription()
        {
            var result = "";
            var called = 0;

            await AsyncObservable.Defer(() =>
            {
                Interlocked.Increment(ref called);
                return(AsyncObservable.Return(1));
            })
            .SubscribeAsync(o => result += o, ex => result += "E", () => result += "C");

            called
            .Should().Be(1);

            result
            .Should().Be("1C");
        }
Exemple #9
0
        public async Task WithException()
        {
            var result = "";
            var called = 0;

            await AsyncObservable.Defer(delegate()
            {
                Interlocked.Increment(ref called);
                throw new NotImplementedException();
                return(AsyncObservable.Return(1));
            })
            .SubscribeAsync(o => result += o, ex => result += "E", () => result += "C");

            called
            .Should().Be(1);

            result
            .Should().Be("E");
        }
Exemple #10
0
 static async Task ReturnAsync()
 {
     await AsyncObservable.Return(42).SubscribeAsync(Print <int>());
 }
        public async Task Using1()
        {
            var result = "";
            await AsyncObservable.Using(() => Disposable.Create(() => result += "3"),
                                        _ => AsyncObservable.Using(() => Disposable.Create(() => result += "2"),
                                                                   __ => AsyncObservable.Using(() => Disposable.Create(() => result += "1"),
                                                                                               ___ => AsyncObservable.Return(Unit.Default))))
            .Finally(() => result       += "4")
            .SubscribeAsync(i => result += "N", ex => result += "E", () => result += "C");

            result
            .Should().Be("NC1234");
        }