public async Task WhenCommandWithResultIsExecutedThenReturnsResultFromHandler()
        {
            var command = new CommandWithResult(Guid.NewGuid());

            var result = await _commandBus.ExecuteAsync <CommandWithResult, object>(command);

            Assert.Equal(command.Result, result.Result);
        }
示例#2
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 CommandBus(handler.Object);

            bus.Execute(command);

            handler.Verify(x => x.Execute(command));
        }
示例#3
0
        public void Send_result()
        {
            var command = new CommandWithResult();

            var mediator = new Mediator(DependencyResolver.Current);

            var response = mediator.Request(command);

            Assert.That(response.Data, Is.EqualTo("foo"));
        }
示例#4
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));
        }
示例#5
0
        public void Send_result()
        {
            var command = new CommandWithResult();

            var mediator = TestScope.Resolve <IMediator>();

            var response = mediator.Request(command);

            Assert.That(response.Data, Is.EqualTo("foo"),
                        response.Exception == null ? string.Empty : response.Exception.ToString());
        }
示例#6
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 CommandBus(handler.Object);

            var result = bus.Execute(command);

            Assert.Same(expected, result);
        }
        public void Execute_ShouldExecuteARealCommandHandler_WithResult()
        {
            var command = new CommandWithResult();
            this.factoryMock.Setup(
                x =>
                x.Get<IDbContextDatabaseCommandHandler>(
                    typeof(IDbContextDatabaseCommandHandler<CommandWithResult>)))
                .Returns(new CommandWithResultHandler());

            using (var context = this.CreateContext())
            {
                context.Start();

                var result = context.Execute(command);

                Assert.That(result, Is.AtLeast(DateTime.Now.AddYears(-1)));
            }
        }
        public void Send_result()
        {
            var command = new CommandWithResult();

            var mediator = TestScope.Resolve<IMediator>();

            var response = mediator.Request(command);

            Assert.That(response.Data, Is.EqualTo("foo"),
                response.Exception == null ? string.Empty : response.Exception.ToString());
        }
示例#9
0
        public void Send_result()
        {
            var command = new CommandWithResult();

            var mediator = new Mediator(DependencyResolver.Current);

            var response = mediator.Request(command);

            Assert.That(response.Data, Is.EqualTo("foo"));
        }
示例#10
0
        public void Send_result()
        {
            var command = new CommandWithResult();

            var mediator = new Mediator();

            var response = mediator.Send(command);

            Assert.That(response.Data, Is.EqualTo("foo"));
        }
        public void Execute_ShouldThrowException_WhenNoCommandHandlerFound()
        {
            var commandNoResult = new CommandNoResult();
            var commandWithResult = new CommandWithResult();

            using (var context = this.CreateContext())
            {
                context.Start();
                Assert.That(
                    () => context.Execute(commandNoResult),
                    Throws.Exception.TypeOf<HexagonException>().With.Message.ContainsSubstring("appropriate handler"));
                Assert.That(
                    () => context.Execute(commandWithResult),
                    Throws.Exception.TypeOf<HexagonException>().With.Message.ContainsSubstring("appropriate handler"));
            }
        }
        public void Execute_ShouldSelectCommandHandler_AndInvokeHandle_WithResult()
        {
            var command = new CommandWithResult();
            var expectedResult = new DateTime();
            var commandHandlerMock = new Mock<IDbContextDatabaseCommandHandler<CommandWithResult>>();
            commandHandlerMock.Setup(x => x.Handle(command, It.IsNotNull<DbContext>()))
                              .Returns(expectedResult)
                              .Verifiable();
            this.factoryMock.Setup(x => x.Get<IDbContextDatabaseCommandHandler>(typeof(IDbContextDatabaseCommandHandler<CommandWithResult>)))
                            .Returns(commandHandlerMock.Object)
                            .Verifiable();

            using (var context = this.CreateContext())
            {
                context.Start();
                var result = context.Execute(command);
                Assert.That(result, Is.EqualTo(expectedResult));
                commandHandlerMock.Verify();
                this.factoryMock.Verify();
            }
        }