Пример #1
0
        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");
        }
Пример #2
0
        public async Task Using2()
        {
            var cts    = new CancellationTokenSource();
            var result = "";
            var t      = AsyncObservable.Using(() => Disposable.Create(() => result += "3"),
                                               _ => AsyncObservable.Using(() => Disposable.Create(() => result += "2"),
                                                                          __ => AsyncObservable.Using(() => Disposable.Create(() => result += "1"),
                                                                                                      ___ => AsyncObservable.Never <Unit>())))
                         .Finally(() => result       += "4")
                         .SubscribeAsync(i => result += "N", ex => result += "E", () => result += "C", ca: cts.Token);

            cts.Cancel();

            await t;

            result
            .Should().Be("1234");
        }
Пример #3
0
        public void ArgumentExceptions()
        {
            Func <IDisposable> funcR = null;
            Func <IDisposable, IAsyncObservable <int> > funcO = null;

            Action action;

            action = () => AsyncObservable.Using(funcR, _ => AsyncObservable.Empty <int>());
            action
            .Should().Throw <ArgumentNullException>();

            action = () => AsyncObservable.Using(() => new BooleanDisposable(), funcO);
            action
            .Should().Throw <ArgumentNullException>();

            action = () => AsyncObservable.Using(funcR, funcO);
            action
            .Should().Throw <ArgumentNullException>();
        }