Пример #1
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);
        }
Пример #2
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>();
        }
Пример #3
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");
        }
Пример #4
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");
        }