Esempio n. 1
0
        public void when_can_handle_requested_for_registered_handler_instance_then_returns_true()
        {
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                        x.GetExtensions <ICanExecute <Command> >() == new[] { Mock.Of <ICanExecute <Command> >() }));

            Assert.True(bus.CanHandle(new Command()));
        }
Esempio n. 2
0
        public void when_can_execute_requested_then_invokes_sync_handler()
        {
            var command = new Command();
            var bus     = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                            x.GetExtensions <ICanExecute <Command> >() == new[] { Mock.Of <ICanExecute <Command> >(c => c.CanExecute(command) == true) }));

            Assert.True(bus.CanExecute(command));
        }
Esempio n. 3
0
        public void when_execute_command_throws_then_rethrows_original_exception()
        {
            var command = new Command();
            var bus     = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                            x.GetExtensions <ICommandHandler <Command> >() == new[] { new ThrowingCommandHandler() }));

            var ex = Assert.Throws <InvalidOperationException>(() => bus.Execute((ICommand)command));

            Assert.Equal("Invalid", ex.Message);
        }
Esempio n. 4
0
        public void when_executing_non_public_command_handler_then_invokes_handler_with_result()
        {
            var handler = new NonPublicCommandHandlerWithResults(new Result());
            var bus     = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                            x.GetExtensions <ICommandHandler <CommandWithResults, IEnumerable <Result> > >() == new[] { handler }));

            var results = bus.Execute(new CommandWithResults());

            Assert.Equal(1, results.Count());
        }
Esempio n. 5
0
        public void when_executing_command_as_explicit_ICommand_then_invokes_handler()
        {
            var handler = new Mock <ICommandHandler <Command> >();
            var command = new Command();
            var bus     = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                            x.GetExtensions <ICommandHandler <Command> >() == new[] { handler.Object }));

            bus.Execute((ICommand)command);

            handler.Verify(x => x.Execute(command));
        }
Esempio n. 6
0
        public void when_executing_sync_command_then_invokes_sync_handler_with_result()
        {
            var handler = new Mock <ICommandHandler <CommandWithResult, Result> >();
            var command = new CommandWithResult();
            var bus     = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                            x.GetExtensions <ICommandHandler <CommandWithResult, Result> >() == new[] { handler.Object }));

            bus.Execute(command);

            handler.Verify(x => x.Execute(command));
        }
Esempio n. 7
0
        public async void when_executing_async_command_then_invokes_async_handler()
        {
            var handler = new Mock <IAsyncCommandHandler <AsyncCommand> >();
            var command = new AsyncCommand();

            handler.Setup(x => x.ExecuteAsync(command, CancellationToken.None)).Returns(Task.FromResult(true));
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                        x.GetExtensions <IAsyncCommandHandler <AsyncCommand> >() == new[] { handler.Object }));

            await bus.ExecuteAsync(command, CancellationToken.None);

            handler.Verify(x => x.ExecuteAsync(command, CancellationToken.None));
        }
Esempio n. 8
0
        public void when_executing_sync_command_with_result_then_invokes_sync_handler_with_result()
        {
            var handler  = new Mock <ICommandHandler <CommandWithResult, Result> >();
            var command  = new CommandWithResult();
            var expected = new Result();

            handler.Setup(x => x.Execute(command)).Returns(expected);
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>(x =>
                                                                        x.GetExtensions <ICommandHandler <CommandWithResult, Result> >() == new[] { handler.Object }));

            var result = bus.Execute(command);

            Assert.Same(expected, result);
        }
Esempio n. 9
0
        public void when_can_execute_requested_and_no_handler_registered_then_returns_false()
        {
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>());

            Assert.False(bus.CanExecute(new Command()));
        }
Esempio n. 10
0
        public void when_can_handle_requested_for_null_command_then_throws()
        {
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>());

            Assert.Throws <ArgumentNullException> (() => bus.CanHandle((Command)null));
        }
Esempio n. 11
0
        public void when_can_handle_requested_for_non_registered_handler_then_returns_false()
        {
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>());

            Assert.False(bus.CanHandle <Command> ());
        }
Esempio n. 12
0
        public async void when_executing_async_command_with_result_without_handler_then_throws()
        {
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>());

            await Assert.ThrowsAsync <NotSupportedException> (() => bus.ExecuteAsync <Result> (new AsyncCommandWithResult(), CancellationToken.None));
        }
Esempio n. 13
0
        public void when_executing_command_with_result_without_handler_then_throws()
        {
            var bus = new CommandBusComponent(Mock.Of <IComponentModel>());

            Assert.Throws <NotSupportedException> (() => bus.Execute <Result> (new CommandWithResult()));
        }