Пример #1
0
        public async Task should_NOT_trigger_event_upon_failure()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();
            var actual    = false;

            container.CreateScope().Returns(scope);
            scope.ResolveAll <ICommandHandler <TestCommand> >()
            .Returns(new[]
            {
                Substitute.For <ICommandHandler <TestCommand> >(),
                Substitute.For <ICommandHandler <TestCommand> >(),
            });

            var sut = new IocCommandBus(container);

            sut.CommandInvoked += (sender, args) => actual = true;
            try
            {
                sut.ExecuteAsync(new TestCommand());
            }
            catch {}

            actual.Should().BeFalse();
        }
Пример #2
0
        public ICommandBus CreateCommandBus(IContainer container)
        {
            var iocBus = new IocCommandBus(container);

            iocBus.CommandInvoked += OnCommandInvoked;
            return(iocBus);
        }
Пример #3
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="IocBusBuilder" /> class.
 /// </summary>
 /// <param name="container">The container.</param>
 public IocBusBuilder(IContainer container)
 {
     if (container == null) throw new ArgumentNullException("container");
     _container = container;
     CommandBus = new IocCommandBus(_container);
     RequestBus = new IocRequestReplyBus(container);
     EventBus = new IocEventBus(container);
     QueryBus = new IocQueryBus(container);
 }
        public void must_have_one_handler_to_be_able_to_execute_command()
        {
            var container = Substitute.For<IContainer>();
            var scope = Substitute.For<IContainerScope>();
            container.CreateScope().Returns(scope);
            scope.ResolveAll<ICommandHandler<TestCommand>>()
                .Returns(new ICommandHandler<TestCommand>[0]);

            var sut = new IocCommandBus(container);
            Action x = () => sut.ExecuteAsync(new TestCommand()).Wait();

            x.ShouldThrow<CqsHandlerMissingException>();
        }
Пример #5
0
        public void must_have_one_handler_to_be_able_to_execute_command()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();

            container.CreateScope().Returns(scope);
            scope.ResolveAll <ICommandHandler <TestCommand> >()
            .Returns(new ICommandHandler <TestCommand> [0]);

            var    sut = new IocCommandBus(container);
            Action x   = () => sut.ExecuteAsync(new TestCommand()).Wait();

            x.Should().Throw <CqsHandlerMissingException>();
        }
Пример #6
0
        public async Task handler_is_being_invoked()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();
            var handler   = Substitute.For <ICommandHandler <TestCommand> >();
            var command   = new TestCommand();

            container.CreateScope().Returns(scope);
            scope.ResolveAll <ICommandHandler <TestCommand> >().Returns(new[] { handler });

            var sut = new IocCommandBus(container);
            await sut.ExecuteAsync(command);

            handler.Received().ExecuteAsync(command);
        }
        public async Task should_dispose_scope_wWhen_done()
        {
            var container = Substitute.For<IContainer>();
            var scope = Substitute.For<IContainerScope>();
            container.CreateScope().Returns(scope);
            scope.ResolveAll<ICommandHandler<TestCommand>>()
                            .Returns(new[]
                {
                    Substitute.For<ICommandHandler<TestCommand>>(),
                });

            var sut = new IocCommandBus(container);
            await sut.ExecuteAsync(new TestCommand());

            scope.Received().Dispose();
        }
public void may_only_have_one_command_handler_to_avoid_ambiguity()
{
    var container = Substitute.For<IContainer>();
    var scope = Substitute.For<IContainerScope>();
    container.CreateScope().Returns(scope);
    scope.ResolveAll<ICommandHandler<TestCommand>>()
        .Returns(new[]
        {
            Substitute.For<ICommandHandler<TestCommand>>(),
            Substitute.For<ICommandHandler<TestCommand>>()
        });

    var sut = new IocCommandBus(container);
    Action x = () => sut.ExecuteAsync(new TestCommand()).Wait();

    x.ShouldThrow<OnlyOneHandlerAllowedException>();
}
Пример #9
0
        public async Task should_dispose_scope_wWhen_done()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();

            container.CreateScope().Returns(scope);
            scope.ResolveAll <ICommandHandler <TestCommand> >()
            .Returns(new[]
            {
                Substitute.For <ICommandHandler <TestCommand> >(),
            });

            var sut = new IocCommandBus(container);
            await sut.ExecuteAsync(new TestCommand());

            scope.Received().Dispose();
        }
Пример #10
0
        public void may_only_have_one_command_handler_to_avoid_ambiguity()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();

            container.CreateScope().Returns(scope);
            scope.ResolveAll <ICommandHandler <TestCommand> >()
            .Returns(new[]
            {
                Substitute.For <ICommandHandler <TestCommand> >(),
                Substitute.For <ICommandHandler <TestCommand> >()
            });

            var    sut = new IocCommandBus(container);
            Action x   = () => sut.ExecuteAsync(new TestCommand()).Wait();

            x.Should().Throw <OnlyOneHandlerAllowedException>();
        }
Пример #11
0
        public async Task should_trigger_event_upon_successful_completion()
        {
            var container = Substitute.For <IContainer>();
            var scope     = Substitute.For <IContainerScope>();
            var actual    = false;

            container.CreateScope().Returns(scope);
            scope.ResolveAll <ICommandHandler <TestCommand> >()
            .Returns(new[]
            {
                Substitute.For <ICommandHandler <TestCommand> >(),
            });

            var sut = new IocCommandBus(container);

            sut.CommandInvoked += (sender, args) => actual = true;
            await sut.ExecuteAsync(new TestCommand());

            actual.Should().BeTrue();
        }
        public async Task should_trigger_event_upon_successful_completion()
        {
            var container = Substitute.For<IContainer>();
            var scope = Substitute.For<IContainerScope>();
            var actual = false;
            container.CreateScope().Returns(scope);
            scope.ResolveAll<ICommandHandler<TestCommand>>()
                            .Returns(new[]
                {
                    Substitute.For<ICommandHandler<TestCommand>>(),
                });

            var sut = new IocCommandBus(container);
            sut.CommandInvoked += (sender, args) => actual = true;
            await sut.ExecuteAsync(new TestCommand());

            actual.Should().BeTrue();
        }
        public async Task handler_is_being_invoked()
        {
            var container = Substitute.For<IContainer>();
            var scope = Substitute.For<IContainerScope>();
            var handler = Substitute.For<ICommandHandler<TestCommand>>();
            var command = new TestCommand();
            container.CreateScope().Returns(scope);
            scope.ResolveAll<ICommandHandler<TestCommand>>().Returns(new[]{handler});

            var sut = new IocCommandBus(container);
            await sut.ExecuteAsync(command);

            handler.Received().ExecuteAsync(command);
        }
        public async Task should_NOT_trigger_event_upon_failure()
        {
            var container = Substitute.For<IContainer>();
            var scope = Substitute.For<IContainerScope>();
            var actual = false;
            container.CreateScope().Returns(scope);
            scope.ResolveAll<ICommandHandler<TestCommand>>()
                            .Returns(new[]
                {
                    Substitute.For<ICommandHandler<TestCommand>>(),
                    Substitute.For<ICommandHandler<TestCommand>>(),
                });

            var sut = new IocCommandBus(container);
            sut.CommandInvoked += (sender, args) => actual = true;
            try
            {
                sut.ExecuteAsync(new TestCommand());
            }
            catch{}

            actual.Should().BeFalse();
        }