Exemple #1
0
        public async Task DispatchAsyncActionCreatorThatThrowsExcepitionHandleExceptionTest()
        {
            AppState Reducer(AppState state, IAction action)
            {
                return(state ?? new AppState());
            }

            var asyncActionCreator = new AsyncActionCreator <AppState>(async(_, __, callback) =>
            {
                await Task.Yield();
                throw new NotSupportedException();
            });

            var store = new Store <AppState>(Reducer, new AppState());

            Exception actual   = null;
            var       observer = new ActionObserver <AppState>()
            {
                Error = (error) =>
                {
                    actual = error;
                }
            };

            store.Subscribe(observer);

            await store.Dispatch(asyncActionCreator);

            Assert.NotNull(actual);
            Assert.IsType <NotSupportedException>(actual);
        }
Exemple #2
0
        public void DispatchActionCreatorThatThrowsExcepitionHandleExceptionTest()
        {
            AppState Reducer(AppState state, IAction action)
            {
                return(state ?? new AppState());
            }

            var store = new Store <AppState>(Reducer, new AppState());

            Exception actual   = null;
            var       observer = new ActionObserver <AppState>()
            {
                Error = (error) =>
                {
                    actual = error;
                }
            };

            store.Subscribe(observer);

            store.Dispatch((_, __) =>
            {
                throw new NotSupportedException();
            });

            Assert.NotNull(actual);
            Assert.IsType <NotSupportedException>(actual);
        }
Exemple #3
0
        public async Task DispatchAsyncActionCreatorHandleExceptionTest()
        {
            AppState Reducer(AppState state, IAction action)
            {
                if (action is StandardAction std && std.Type == "test")
                {
                    throw new NotSupportedException();
                }
                return(state ?? new AppState());
            }

            var asyncActionCreator = new AsyncActionCreator <AppState>(async(_, __, callback) =>
            {
                await Task.FromResult(0);
                callback((x, y) => new StandardAction("test"));
            });

            var store = new Store <AppState>(Reducer, new AppState());

            Exception actual   = null;
            var       observer = new ActionObserver <AppState>()
            {
                Error = (error) =>
                {
                    actual = error;
                }
            };

            store.Subscribe(observer);

            await store.Dispatch(asyncActionCreator);

            Assert.NotNull(actual);
            Assert.IsType <NotSupportedException>(actual);
        }
Exemple #4
0
        public void DispatchHandleExceptionTest()
        {
            AppState Reducer(AppState state, IAction action)
            {
                if (action is StandardAction std && std.Type == "test")
                {
                    throw new NotSupportedException();
                }
                return(state ?? new AppState());
            }

            var store = new Store <AppState>(Reducer, new AppState());

            Exception actual   = null;
            var       observer = new ActionObserver <AppState>()
            {
                Error = (error) =>
                {
                    actual = error;
                }
            };

            store.Subscribe(observer);

            store.Dispatch(new StandardAction("test"));

            Assert.NotNull(actual);
            Assert.IsType <NotSupportedException>(actual);
        }