public async Task ShouldCloseTheAccount()
        {
            ICommandHandler <ValidateAccountCommand> fakeCommandHandler = A.Fake <ICommandHandler <ValidateAccountCommand> >();

            A.CallTo(() => fakeCommandHandler.Handle(A <ValidateAccountCommand> .Ignored)).Invokes(args =>
            {
                ValidateAccountCommand command = args.Arguments[0] as ValidateAccountCommand;
                bus.Publish(new AccountClosedEvent(command.AggregateID, command.OriginalVersion, command.CorrelationID, command.AggregateID));
            });
            bus.Subscribe(fakeCommandHandler);

            await sut.Execute(3);

            sut.Response.Should().Be(AccountOpenerResponse.Closed);
        }
Пример #2
0
        public Task <AsyncTaskResult <IApplicationMessage> > HandleAsync(ValidateAccountCommand command)
        {
            var applicationMessage = default(ApplicationMessage);

            //此处应该会调用外部接口验证账号是否合法,这里仅仅简单通过账号是否以INVALID字符串开头来判断是否合法;根据账号的合法性,返回不同的应用层消息
            if (command.AggregateRootId.StartsWith("INVALID"))
            {
                applicationMessage = new AccountValidateFailedMessage(command.AggregateRootId, command.TransactionId, "账户不合法.");
            }
            else
            {
                applicationMessage = new AccountValidatePassedMessage(command.AggregateRootId, command.TransactionId);
            }

            return(Task.FromResult(new AsyncTaskResult <IApplicationMessage>(AsyncTaskStatus.Success, applicationMessage)));
        }
        public Task HandleAsync(ICommandContext context, ValidateAccountCommand command)
        {
            var applicationMessage = default(ApplicationMessage);

            //此处应该会调用外部接口验证账号是否合法,这里仅仅简单通过账号是否以INVALID字符串开头来判断是否合法;根据账号的合法性,返回不同的应用层消息
            if (command.AggregateRootId.StartsWith("INVALID"))
            {
                applicationMessage = new AccountValidateFailedMessage(command.AggregateRootId, command.TransactionId, command.TransactionType, command.PreparationType, "账户不合法.");
            }
            else
            {
                applicationMessage = new AccountValidatePassedMessage(command.AggregateRootId, command.TransactionId, command.TransactionType, command.PreparationType, command.Amount);
            }

            context.SetApplicationMessage(applicationMessage);
            return(Task.CompletedTask);
        }