public void domain_exception_publisher_throw_exception_test()
        {
            var aggregateId = ObjectId.GenerateNewStringId();
            var command     = new CreateTestAggregateCommand
            {
                AggregateRootId = aggregateId,
                Title           = "Sample Note"
            };

            _commandService.ExecuteAsync(command).Wait();

            var command1 = new AggregateThrowExceptionCommand
            {
                AggregateRootId   = aggregateId,
                IsDomainException = true
            };

            ((MockDomainExceptionPublisher)_domainExceptionPublisher).SetExpectFailedCount(FailedType.UnKnownException, 5);
            var commandResult = _commandService.ExecuteAsync(command1).Result;

            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
            ((MockDomainExceptionPublisher)_domainExceptionPublisher).Reset();

            ((MockDomainExceptionPublisher)_domainExceptionPublisher).SetExpectFailedCount(FailedType.IOException, 5);
            commandResult = _commandService.ExecuteAsync(command1).Result;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
            ((MockDomainExceptionPublisher)_domainExceptionPublisher).Reset();
        }
        public void aggregate_throw_exception_command_test()
        {
            var aggregateId = ObjectId.GenerateNewStringId();
            var command     = new CreateTestAggregateCommand
            {
                AggregateRootId = aggregateId,
                Title           = "Sample Note"
            };

            _commandService.ExecuteAsync(command).Wait();

            var command1 = new AggregateThrowExceptionCommand
            {
                AggregateRootId   = aggregateId,
                IsDomainException = false
            };
            var commandResult = _commandService.ExecuteAsync(command1).Result;

            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);

            var command2 = new AggregateThrowExceptionCommand
            {
                AggregateRootId   = aggregateId,
                IsDomainException = true
            };

            commandResult = _commandService.ExecuteAsync(command2).Result;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
        }
        public void publishable_exception_publisher_throw_exception_test()
        {
            var aggregateId = ObjectId.GenerateNewStringId();
            var command = new CreateTestAggregateCommand
            {
                AggregateRootId = aggregateId,
                Title = "Sample Note"
            };

            _commandService.ExecuteAsync(command).Wait();

            var command1 = new AggregateThrowExceptionCommand
            {
                AggregateRootId = aggregateId,
                PublishableException = true
            };
            ((MockPublishableExceptionPublisher)_publishableExceptionPublisher).SetExpectFailedCount(FailedType.UnKnownException, 5);
            var asyncResult = _commandService.ExecuteAsync(command1).Result;
            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status);
            var commandResult = asyncResult.Data;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
            ((MockPublishableExceptionPublisher)_publishableExceptionPublisher).Reset();

            ((MockPublishableExceptionPublisher)_publishableExceptionPublisher).SetExpectFailedCount(FailedType.IOException, 5);
            asyncResult = _commandService.ExecuteAsync(command1).Result;
            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status);
            commandResult = asyncResult.Data;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
            ((MockPublishableExceptionPublisher)_publishableExceptionPublisher).Reset();

            ((MockPublishableExceptionPublisher)_publishableExceptionPublisher).SetExpectFailedCount(FailedType.TaskIOException, 5);
            asyncResult = _commandService.ExecuteAsync(command1).Result;
            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status);
            commandResult = asyncResult.Data;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
            ((MockPublishableExceptionPublisher)_publishableExceptionPublisher).Reset();
        }
        public void aggregate_throw_exception_command_test()
        {
            var aggregateId = ObjectId.GenerateNewStringId();
            var command     = new CreateTestAggregateCommand
            {
                AggregateRootId = aggregateId,
                Title           = "Sample Note"
            };

            _commandService.ExecuteAsync(command).Wait();

            var command1 = new AggregateThrowExceptionCommand
            {
                AggregateRootId      = aggregateId,
                PublishableException = false
            };
            var asyncResult = _commandService.ExecuteAsync(command1).Result;

            Assert.NotNull(asyncResult);
            Assert.Equal(AsyncTaskStatus.Success, asyncResult.Status);
            var commandResult = asyncResult.Data;

            Assert.NotNull(commandResult);
            Assert.Equal(CommandStatus.Failed, commandResult.Status);

            var command2 = new AggregateThrowExceptionCommand
            {
                AggregateRootId      = aggregateId,
                PublishableException = true
            };

            asyncResult = _commandService.ExecuteAsync(command2).Result;
            Assert.NotNull(asyncResult);
            Assert.Equal(AsyncTaskStatus.Success, asyncResult.Status);
            commandResult = asyncResult.Data;
            Assert.NotNull(commandResult);
            Assert.Equal(CommandStatus.Failed, commandResult.Status);
        }
Пример #5
0
        public async Task HandleAsync(ICommandContext context, AggregateThrowExceptionCommand command)
        {
            var testAggregate = await context.GetAsync <TestAggregate>(command.AggregateRootId);

            testAggregate.ThrowException(command.PublishableException);
        }
Пример #6
0
        public void aggregate_throw_exception_command_test()
        {
            var aggregateId = ObjectId.GenerateNewStringId();
            var command = new CreateTestAggregateCommand
            {
                AggregateRootId = aggregateId,
                Title = "Sample Note"
            };

            _commandService.ExecuteAsync(command).Wait();

            var command1 = new AggregateThrowExceptionCommand
            {
                AggregateRootId = aggregateId,
                PublishableException = false
            };
            var asyncResult = _commandService.ExecuteAsync(command1).Result;
            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status);
            var commandResult = asyncResult.Data;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);

            var command2 = new AggregateThrowExceptionCommand
            {
                AggregateRootId = aggregateId,
                PublishableException = true
            };
            asyncResult = _commandService.ExecuteAsync(command2).Result;
            Assert.IsNotNull(asyncResult);
            Assert.AreEqual(AsyncTaskStatus.Success, asyncResult.Status);
            commandResult = asyncResult.Data;
            Assert.IsNotNull(commandResult);
            Assert.AreEqual(CommandStatus.Failed, commandResult.Status);
        }
 public void Handle(ICommandContext context, AggregateThrowExceptionCommand command)
 {
     context.Get <TestAggregate>(command.AggregateRootId).ThrowException(command.PublishableException);
 }