コード例 #1
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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()));
        }
コード例 #2
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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));
        }
コード例 #3
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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);
        }
コード例 #4
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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());
        }
コード例 #5
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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));
        }
コード例 #6
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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));
        }
コード例 #7
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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));
        }
コード例 #8
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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);
        }
コード例 #9
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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()));
        }
コード例 #10
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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));
        }
コード例 #11
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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> ());
        }
コード例 #12
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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));
        }
コード例 #13
0
ファイル: CommandBusComponentSpec.cs プロジェクト: kzu/Merq
        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()));
        }