예제 #1
0
        public void AgentCanHandleMultipleDisposeCalls()
        {
            Exception exception = null;

            var tcs   = new TaskCompletionSource <bool>();
            var agent = new ReactiveAsyncAgent <int, int>(
                initialState: 0,
                messageHandler: (state, msg, ct) =>
            {
                return(Task.FromResult(state + 1));
            },
                errorHandler: (ex, ct) => Task.FromResult(true));

            try
            {
                agent.Dispose();
                agent.Dispose();
                agent.Send(1);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.Null(exception);
        }
예제 #2
0
        public async Task AgentSignalsCompleted()
        {
            var tcs = new TaskCompletionSource <bool>();

            var agent = new ReactiveAsyncAgent <string, string>(
                initialState: string.Empty,
                messageHandler: (state, msg, ct) =>
            {
                return(Task.FromResult(msg));
            },
                errorHandler: (ex, ct) => Task.FromResult(true));

            agent.State.Subscribe(_ => { }, () => tcs.SetResult(true));
            agent.Dispose();
            var isCompleted = await tcs.Task;

            Assert.True(isCompleted);
        }