public void Customer_Should_Be_Registered_With_1_Account()
        {
            EntityFactory entityFactory = new EntityFactory();

            // Arrange
            ICustomer sut = entityFactory.NewCustomer(
                new SSN("198608179922"),
                new Name("Ivan Paulovich"));

            IAccount account = entityFactory.NewAccount(sut.Id);

            // Act
            sut.Assign(account.Id);

            // Assert
            Assert.Single(sut.Accounts.GetAccountIds());
        }
Exemple #2
0
        /// <summary>
        ///     Executes the Use Case.
        /// </summary>
        /// <param name="input">Input Message.</param>
        /// <returns>Task.</returns>
        public async Task Execute(RegisterInput input)
        {
            if (input is null)
            {
                this._registerOutputPort
                .WriteError(Messages.InputIsNull);
                return;
            }

            IUser user = this._userService
                         .GetUser();

            if (await this.VerifyCustomerAlreadyRegistered(user)
                .ConfigureAwait(false))
            {
                return;
            }

            ICustomer customer = await this._customerService
                                 .CreateCustomer(input.SSN, user.Name)
                                 .ConfigureAwait(false);

            IAccount account = await this._accountService
                               .OpenCheckingAccount(customer.Id, input.InitialAmount)
                               .ConfigureAwait(false);

            await this._securityService
            .CreateUserCredentials(user, customer.Id)
            .ConfigureAwait(false);

            customer.Assign(account.Id);

            await this._unitOfWork.Save()
            .ConfigureAwait(false);

            this.BuildOutput(user, customer, new List <IAccount> {
                account
            });
        }