コード例 #1
0
        public void ShouldUpdateCategoryTransaction()
        {
            // Arrange
            var faker   = new Faker();
            var csvPath = faker.Random.String2(2);

            _transactionServices.LoadTransactions(csvPath);
            var updatedTransaction = new WalletManagerDTO.Transaction
            {
                Compte        = "Compte1",
                OperationDate = new DateTime(2020, 03, 31),
                Label         = "Label1",
                Reference     = "ref1",
                Amount        = 10,
                Category      = new WalletManagerDTO.Category {
                    Name = "Courses"
                }
            };

            // Act
            _transactionServices.UpdateTransaction(updatedTransaction);
            var transaction = _transactionServices.GetTransaction(updatedTransaction.Reference);

            // Assert
            Assert.Equal(updatedTransaction.Category, transaction.Category);
        }
コード例 #2
0
        public void ShouldThrownExceptionWhenUpdateCategoryTransaction()
        {
            // Arrange
            var updatedTransaction = new WalletManagerDTO.Transaction
            {
                Reference = "doesntExist",
                Category  = new WalletManagerDTO.Category {
                    Name = "Courses"
                }
            };

            // Act
            Action updateTransactionAction = () => _transactionServices.UpdateTransaction(updatedTransaction);

            // Assert
            Assert.Throws <WalletManagerDTO.Exceptions.TransactionServiceException>(updateTransactionAction);
        }
コード例 #3
0
        public void UpdateTransaction(WalletManagerDTO.Transaction updatedTransaction)
        {
            WalletManagerDTO.Transaction findedTransaction;
            try
            {
                findedTransaction = _transactions.FirstOrDefault(t => t.Reference.Equals(updatedTransaction.Reference));
            }
            catch (Exception ex)
            {
                throw new WalletManagerDTO.Exceptions.TransactionServiceException($"Impossible to update this transaction : {updatedTransaction} due to {ex.Message}");
            }

            if (findedTransaction == null)
            {
                throw new WalletManagerDTO.Exceptions.TransactionServiceException($"Impossible to update transaction with this reference : {updatedTransaction.Reference}");
            }

            findedTransaction.Category = updatedTransaction.Category;
        }