Ejemplo n.º 1
0
        public void PublishAsync_WhenCalledWithUnsupportedCommandType_ThrowsIntranetCommandBusException()
        {
            ICommandBus sut = CreateSut(new List <ICommandHandler>(0));

            Mock <ICommand>             commandMock = new Mock <ICommand>();
            IntranetCommandBusException result      = Assert.ThrowsAsync <IntranetCommandBusException>(async() => await sut.PublishAsync <ICommand, object>(commandMock.Object));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.NoCommandHandlerSupportingCommandWithResultType));
        }
Ejemplo n.º 2
0
        public void PublishAsync_WhenSupportingCommandHandlerThrowsException_ThrowsIntranetCommandBusExceptionWithCorrectInnerException()
        {
            Exception exception = _fixture.Create <Exception>();

            Mock <ICommandHandler <TestCommand, object> > commandHandlerMock = CreateCommandHandlerMockWithResult <TestCommand, object>(_fixture.Create <object>(), exception);
            ICommandBus sut = CreateSut(CreateCommandHandlerMockCollection(commandHandlerMock.Object));

            IntranetCommandBusException result = Assert.ThrowsAsync <IntranetCommandBusException>(async() => await sut.PublishAsync <TestCommand, object>(new TestCommand()));

            Assert.That(result.InnerException, Is.EqualTo(exception));
        }
Ejemplo n.º 3
0
        public void PublishAsync_WhenSupportingCommandHandlerThrowsException_ThrowsIntranetCommandBusExceptionWithCorrectErrorCode()
        {
            Exception exception = _fixture.Create <Exception>();

            Mock <ICommandHandler <TestCommand> > commandHandlerMock = CreateCommandHandlerMockWithoutResult <TestCommand>(exception);
            ICommandBus sut = CreateSut(CreateCommandHandlerMockCollection(commandHandlerMock.Object));

            IntranetCommandBusException result = Assert.ThrowsAsync <IntranetCommandBusException>(async() => await sut.PublishAsync(new TestCommand()));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ErrorWhilePublishingCommandWithoutResultType));
        }
Ejemplo n.º 4
0
        public void PublishAsync_WhenSupportingCommandHandlerThrowsAggregateExceptionWhereInnerExceptionIsNotIntranetExceptionBase_ThrowsIntranetCommandBusExceptionWithCorrectErrorCode()
        {
            AggregateException aggregateException = new AggregateException(_fixture.Create <Exception>());

            Mock <ICommandHandler <TestCommand, object> > commandHandlerMock = CreateCommandHandlerMockWithResult <TestCommand, object>(_fixture.Create <object>(), aggregateException);
            ICommandBus sut = CreateSut(CreateCommandHandlerMockCollection(commandHandlerMock.Object));

            IntranetCommandBusException result = Assert.ThrowsAsync <IntranetCommandBusException>(async() => await sut.PublishAsync <TestCommand, object>(new TestCommand()));

            Assert.That(result.ErrorCode, Is.EqualTo(ErrorCode.ErrorWhilePublishingCommandWithResultType));
        }
Ejemplo n.º 5
0
        public void PublishAsync_WhenSupportingCommandHandlerThrowsAggregateExceptionWhereInnerExceptionIsNotIntranetExceptionBase_ThrowsIntranetCommandBusExceptionWithCorrectInnerException()
        {
            Exception          innerException     = _fixture.Create <Exception>();
            AggregateException aggregateException = new AggregateException(innerException);

            Mock <ICommandHandler <TestCommand> > commandHandlerMock = CreateCommandHandlerMockWithoutResult <TestCommand>(aggregateException);
            ICommandBus sut = CreateSut(CreateCommandHandlerMockCollection(commandHandlerMock.Object));

            IntranetCommandBusException result = Assert.ThrowsAsync <IntranetCommandBusException>(async() => await sut.PublishAsync(new TestCommand()));

            Assert.That(result.InnerException, Is.EqualTo(innerException));
        }