public async Task Execute(CloseAccountInput closeAccountInput)
        {
            IAccount account;

            try
            {
                account = await _accountRepository.Get(closeAccountInput.AccountId);
            }
            catch (AccountNotFoundException ex)
            {
                _outputPort.NotFound(ex.Message);
                return;
            }

            if (account.IsClosingAllowed())
            {
                await _accountRepository.Delete(account);
            }

            BuildOutput(account);
        }
Example #2
0
        /// <summary>
        ///     Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(CloseAccountInput input)
        {
            if (input is null)
            {
                this._closeAccountOutputPort
                .WriteError(Messages.InputIsNull);
                return;
            }

            IAccount account = await this._accountRepository
                               .GetAccount(input.AccountId)
                               .ConfigureAwait(false);

            if (account is null)
            {
                this._closeAccountOutputPort
                .NotFound(Messages.AccountDoesNotExist);
                return;
            }

            if (account.IsClosingAllowed())
            {
                await this._accountRepository
                .Delete(account)
                .ConfigureAwait(false);
            }
            else
            {
                this._closeAccountOutputPort
                .WriteError(Messages.AccountHasFunds);
                return;
            }

            var closeAccountOutput = new CloseAccountOutput(account);

            this._closeAccountOutputPort
            .Standard(closeAccountOutput);
        }
        public async Task NewAccount_Should_Allows_Closing2()
        {
            var getAccountPresenter   = new GetAccountDetailsPresenter();
            var closeAccountPresenter = new CloseAccountPresenter();
            var withdrawPresenter     = new WithdrawPresenter();

            var getAccountUseCase = new Application.UseCases.GetAccountDetails(
                _fixture.UserService,
                getAccountPresenter,
                _fixture.AccountRepository);

            var withdrawUseCase = new Application.UseCases.Withdraw(
                _fixture.UserService,
                _fixture.EntityFactory,
                withdrawPresenter,
                _fixture.AccountRepository,
                _fixture.UnitOfWork);

            var sut = new Application.UseCases.CloseAccount(
                _fixture.UserService,
                closeAccountPresenter,
                _fixture.AccountRepository);

            await getAccountUseCase.Execute(new GetAccountDetailsInput(
                                                _fixture.Context.DefaultAccountId));

            var getAccountDetailtOutput = getAccountPresenter.GetAccountDetails.First();

            await withdrawUseCase.Execute(new Application.Boundaries.Withdraw.WithdrawInput(
                                              _fixture.Context.DefaultAccountId,
                                              new PositiveMoney(getAccountDetailtOutput.CurrentBalance.ToDecimal())));

            var input = new CloseAccountInput(
                _fixture.Context.DefaultAccountId);
            await sut.Execute(input);

            Assert.Equal(input.AccountId, closeAccountPresenter.ClosedAccounts.First().AccountId);
        }
Example #4
0
        /// <summary>
        /// Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(CloseAccountInput input)
        {
            IAccount account;

            try
            {
                account = await this.accountRepository.GetAccount(input.AccountId)
                          .ConfigureAwait(false);
            }
            catch (AccountNotFoundException ex)
            {
                this.outputPort.NotFound(ex.Message);
                return;
            }

            if (account.IsClosingAllowed())
            {
                await this.accountRepository.Delete(account)
                .ConfigureAwait(false);
            }

            this.BuildOutput(account);
        }
Example #5
0
        public void GivenValidData_InputCreated()
        {
            CloseAccountInput actual = new CloseAccountInput(Guid.NewGuid());

            Assert.NotNull(actual);
        }