public Transaction(TransactionDto dto)
 {
     _dto = dto;
 }
Exemplo n.º 2
0
        public void TestTransaction()
        {
            Rendu.Clear();

            addToOc(ActionsEnum.Travail.ToString(), ServiceEnum.Transaction.ToString());

            #region Nouvelle Categorie, Nouveau Account

            var newCategory = new CategoryDto();
            newCategory.Balance = 7.0;
            newCategory.Color = "AA";
            newCategory.Name = "MyCategory";

            var newAccount = new AccountDto();
            newAccount.Balance = 7.0;
            newAccount.BankName = "AA";
            newAccount.Name = "MyAccount";

            #endregion

            #region Nettoyage Base

            var Categories = CategoryService.GetAllCategories(false, false);

            addToOc(ActionsEnum.GetList.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Category.ToString(), ObjectType.itemCount.ToString(), Categories.Value.Count));


            var Accounts = AccountService.GetAllAccounts(false, false);

            addToOc(ActionsEnum.GetList.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Account.ToString(), ObjectType.itemCount.ToString(), Accounts.Value.Count));



            if (Categories.Value.Count > 0)
            {
                foreach (var dto in Categories.Value)
                {
                    CategoryService.DeleteCategorieById(dto.Id);
                    addToOc(ActionsEnum.Delete.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Category.ToString(), ObjectType.itemId.ToString(), dto.Id));
                }

                Categories = CategoryService.GetAllCategories(false, false);

                addToOc(ActionsEnum.GetList.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Category.ToString(), ObjectType.itemCount.ToString(), Categories.Value.Count));
            }

            if (Accounts.Value.Count > 0)
            {
                foreach (var dto in Accounts.Value)
                {
                    AccountService.DeleteAccountById(dto.Id);
                    addToOc(ActionsEnum.Delete.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Account.ToString(), ObjectType.itemId.ToString(), dto.Id));
                }

                Accounts = AccountService.GetAllAccounts(false, false);

                addToOc(ActionsEnum.GetList.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Account.ToString(), ObjectType.itemCount.ToString(), Accounts.Value.Count));
            }

            #endregion

            #region Ajout Category, Account

            var addedCategory = CategoryService.CreateCategory(newCategory);

            addToOc(ActionsEnum.Insert.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Category.ToString(), ObjectType.itemId.ToString(), addedCategory.Value.Id));


            var addedAccount = AccountService.CreateAccount(newAccount);

            addToOc(ActionsEnum.Insert.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Account.ToString(), ObjectType.itemId.ToString(), addedAccount.Value.Id));

            #endregion


            #region Ajout 2 transactions, same account, 1 with the category

            var newTransaction = new TransactionDto();
            newTransaction.Name = "First Transaction !";
            newTransaction.Balance = 40.0;
            newTransaction.Account = addedAccount.Value;
            newTransaction.Category = addedCategory.Value;

            var newTransaction2 = new TransactionDto();
            newTransaction2.Name = "Second Transaction !";
            newTransaction2.Balance = 40.0;
            newTransaction2.Account = addedAccount.Value;

            var addedtransaction = TransactionService.CreateTransaction(newTransaction);

            addToOc(ActionsEnum.Insert.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Transaction.ToString(), ObjectType.itemName.ToString(), addedtransaction.Value.Name));

            var addedtransaction2 = TransactionService.CreateTransaction(newTransaction);

            addToOc(ActionsEnum.Insert.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Transaction.ToString(), ObjectType.itemName.ToString(), addedtransaction2.Value.Name));

            #endregion

            #region get des listes par account et par category

            var listebyAccount = TransactionService.GetTransactionsByAccountId(addedAccount.Value.Id, false, false);

            addToOc(ActionsEnum.GetList.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Transaction.ToString(), ObjectType.itemCount.ToString(), listebyAccount.Value.Count));


           var listebyCategory = TransactionService.GetTransactionsByCategoryId(addedCategory.Value.Id, false, false);

           addToOc(ActionsEnum.GetList.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Transaction.ToString(), ObjectType.itemCount.ToString(), listebyCategory.Value.Count));

            #endregion

           var gettedTrans = TransactionService.GetTransactionById(addedtransaction.Value.Id, false, false).Value;

           addToOc(ActionsEnum.Get.ToString(), string.Format(TEMPLATEMessagedifferService, ServiceEnum.Transaction.ToString(), ObjectType.itemName.ToString(), gettedTrans.Name));


           gettedTrans.Name = "MODIFIED";

           var updatedCategory = TransactionService.UpdateTransaction(gettedTrans);

           addToOc(ActionsEnum.Update.ToString(), string.Format(TEMPLATEMessageOnUpdate, ServiceEnum.Transaction.ToString(), ObjectType.itemName.ToString(), updatedCategory.Value.Name, addedtransaction.Value.Name));

        }