Exemplo n.º 1
0
        public IActionResult CreateCustomer([Required] string firstName, [Required] string lastName)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var initialCustomerInfo = new InitialCustomerInfo
            {
                FirstName = firstName,
                LastName  = lastName
            };

            try
            {
                var customerId = _customerService.CreateCustomerWithOneAccount(initialCustomerInfo);

                var dto = new CustomerIdDto {
                    Id = customerId.Id
                };

                return(Ok(dto));
            }
            catch (Exception e)
            {
                return(Conflict(e));
            }
        }
Exemplo n.º 2
0
        public void CreateCustomer_WithValidInfo_Succeed()
        {
            var customerService = new CustomerService(_store, _accountService);

            var initialCustomerInfo = new InitialCustomerInfo
            {
                FirstName = "FirstName1",
                LastName  = "lastName"
            };

            // Creating the customer
            var customerId = customerService.CreateCustomerWithOneAccount(initialCustomerInfo);

            Assert.NotNull(customerId);
            Assert.NotNull(customerId.Id);
            Assert.AreNotEqual(Guid.Empty, customerId);

            // Info is available for the customer
            var customerInfo = customerService.GetCustomerInfoFromId(customerId);

            Assert.NotNull(customerInfo);
            Assert.AreEqual(customerId, customerInfo.CustomerId);
            Assert.AreEqual(initialCustomerInfo.FirstName, customerInfo.FirstName);
            Assert.AreEqual(initialCustomerInfo.LastName, customerInfo.LastName);
            Assert.NotNull(customerInfo.MasterAccountId);
            Assert.AreNotEqual(Guid.Empty, customerInfo.MasterAccountId);

            // The customer has an account
            var account = _accountService.GetAccountFromId(customerInfo.MasterAccountId);

            Assert.NotNull(account);
            Assert.AreEqual(0, account.CurrentBalance);
            Assert.AreEqual(0, account.InitialBalance);
            Assert.IsEmpty(account.OperationHistory);
        }
Exemplo n.º 3
0
        public CustomerId CreateCustomerWithOneAccount(InitialCustomerInfo customerFiles)
        {
            var previouslyExistingId = GetCustomerIdFromName(customerFiles.FirstName, customerFiles.LastName);

            if (previouslyExistingId != null)
            {
                throw new ArgumentException("Customer already exists");
            }

            var customerId = new CustomerId(Guid.NewGuid());

            var account = _accountService.CreateAccount(0);

            var customerInfo = new CustomerInfo()
            {
                CustomerId      = customerId,
                FirstName       = customerFiles.FirstName,
                LastName        = customerFiles.LastName,
                MasterAccountId = account.AccountId
            };

            _store.CreateCustomer(customerInfo);

            return(customerId);
        }