Пример #1
0
        public async Task <OperationStatusInfo> UpdateAccount(object updatedAccount)
        {
            return(await Task.Run(() =>
            {
                OperationStatusInfo operationStatusInfo = new OperationStatusInfo(operationStatus: OperationStatus.Done);

                string attachedObjectText = updatedAccount.ToString();
                Account newAccount = JsonConvert.DeserializeObject <Account>(attachedObjectText);
                EditAccountRequest editAccountRequest = new EditAccountRequest(newAccount.Id, newAccount.LastName, newAccount.FirstName, newAccount.SecondName, newAccount.Photo);

                try
                {
                    EditAccountResponse editAccountResponse = hubController.UseCaseFactory.CreateEditAccountUseCase().Execute(editAccountRequest);
                    AccountDTO accountDTO = hubController.TransformAccount(editAccountResponse.Account);
                    operationStatusInfo.AttachedObject = accountDTO;
                    operationStatusInfo.AttachedInfo = "Account is updated!";
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    operationStatusInfo.OperationStatus = OperationStatus.Cancelled;
                    operationStatusInfo.AttachedInfo = ex.Message;
                }

                return operationStatusInfo;
            }));
        }
Пример #2
0
        public void EditAccountUseCaseEqualTest()
        {
            EditAccountRequest editAccountRequest = new EditAccountRequest(id, lastName, firstName, secondName, photo);

            IUnitOfWorkFactory unitOfWorkFactory = new UnitOfWorkFactory();
            IUnitOfWork        unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();

            unitOfWork.GetAccountsFromDatabase();
            IActivityFactory    activityFactory     = new ActivityFactory(unitOfWork, new ValidationRuleFactory());
            IUseCaseFactory     useCaseFactory      = new UseCaseFactory(activityFactory);
            EditAccountResponse editAccountResponse = useCaseFactory.CreateEditAccountUseCase().Execute(editAccountRequest);

            Assert.AreEqual(editAccountResponse.Account.LastName, lastName);
            Assert.AreEqual(editAccountResponse.Account.FirstName, firstName);
            Assert.AreEqual(editAccountResponse.Account.SecondName, secondName);
        }
Пример #3
0
        public void EditAccountUseCaseNotEqualTest()
        {
            Exception exception = null;

            try
            {
                EditAccountRequest editAccountRequest = new EditAccountRequest(10, lastName, firstName, secondName, photo);

                IUnitOfWorkFactory unitOfWorkFactory = new UnitOfWorkFactory();
                IUnitOfWork        unitOfWork        = unitOfWorkFactory.CreateUnitOfWork();
                unitOfWork.GetAccountsFromDatabase();
                IActivityFactory    activityFactory     = new ActivityFactory(unitOfWork, new ValidationRuleFactory());
                IUseCaseFactory     useCaseFactory      = new UseCaseFactory(activityFactory);
                EditAccountResponse editAccountResponse = useCaseFactory.CreateEditAccountUseCase().Execute(editAccountRequest);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.AreEqual(exception.Message, "The account is not updated and not found!");
        }
Пример #4
0
        private void EditAccountResponseHandler(EditAccountResponse response)
        {
            if (response.Result == false) return;

            // Change name of the requested account
            _tradingService.ChangeAccountNameAsync(response.AccountId, response.NewAccountName);
        }