Example #1
0
        public async void AddNewTransaction()
        {
            try
            {
                IsWalletPanelEnabled = false;
                DBTransaction tr = new DBTransaction(Guid.NewGuid(), 0m, "UAH", DateTime.Now, "default", Guid.NewGuid(), _currentWallet.Guid);
                await _serviceTransaction.AddTransactionAsync(tr);

                Transactions.Add(new TransactionDetailsViewModel(tr, _serviceTransaction, _serviceWallet, _currentWallet, DeleteCurrentTransaction));

                _currentWallet.AddTransaction(_currentUser.Guid, tr);
                await _serviceWallet.UpdateWallet(_currentWallet.Guid.ToString(), _currentWallet.Name, _currentWallet.Balance, _currentWallet.Currency, _currentWallet.Owner, _currentWallet.Description, _currentWallet.Transactions);

                RaisePropertyChanged(nameof(Transactions));
                RaisePropertyChanged(nameof(CurrentWallet));
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Transaction add was failed: {ex.Message}");
                return;
            }
            finally
            {
                IsWalletPanelEnabled = true;
            }
            MessageBox.Show($"Transaction was added successfully!");
        }
Example #2
0
        public async void AjouterTransactionAvecPaiement()
        {
            //1ère étape : configuration des mocks pour qu'ils retournes les bons objets
            Pompe pompe = new Pompe {
                Id = 1
            };

            _mockPompeRepository.Setup(x => x.GetByIdWithRéservoirAsync(pompe.Id)).ReturnsAsync(pompe);
            Transaction transaction = new Transaction {
                Id = 1
            };

            transaction.Pompe        = pompe;
            transaction.PrixUnitaire = 1.0M;
            transaction.Volume       = 50.0M;
            _mockTransactionRepository.Setup(x => x.GetByIdWithPaiementsAsync(transaction.Id)).ReturnsAsync(transaction);

            //2ème étape : appeler le service
            TransactionService service = new TransactionService(_mockTransactionRepository.Object, null);
            await service.AddTransactionAsync(transaction);

            Paiement paiement = new PaiementEspèce(50, transaction);
            await service.AddPaiementAsync(transaction.Id, paiement);

            //3ème étape: vérifier les appels aux repositories
            _mockTransactionRepository.Verify(x => x.AddAsync(transaction), Times.Once);
            _mockTransactionRepository.Verify(x => x.GetByIdWithPaiementsAsync(1), Times.Once);
            _mockTransactionRepository.Verify(x => x.UpdateAsync(transaction), Times.Once);
            _mockTransactionRepository.VerifyNoOtherCalls();

            //4éme étape: vérifier les valeurs finales
            Assert.Single(transaction.Paiements);
            Assert.Equal(50.0M, transaction.MontantTotal());
            Assert.Equal(true, transaction.EstPayée());
        }
        public async Task AddTransactionTypeAsync_Returns_New_TransactionType()
        {
            //Arrange
            var service = new TransactionService(_myRestaurantContext);

            //Act
            var result = await service.AddTransactionAsync(new Transaction
            {
                TransactionTypeId = 10,
                PaymentTypeId     = 1,
                Date        = DateTime.Now.AddDays(-2),
                Description = "Interest from Deposit",
                Amount      = 456.5m,
                Cashflow    = Cashflow.Income,
                CreatedAt   = DateTime.Now
            });

            //Assert
            result.Should().BeAssignableTo <Transaction>();
            result.TransactionTypeId.Should().Be(10);
            result.TransactionType.Type.Should().Be("Extra Income");
            result.PaymentTypeId.Should().Be(1);
            result.PaymentType.Name.Should().Be("Cash");
            result.Cashflow.Should().Be(Cashflow.Income);

            //Act
            var transactionTypes = await service.GetTransactionsAsync();

            //Assert
            transactionTypes.Should().HaveCount(3);
        }
Example #4
0
        public async void AddTransactionAsync()
        {
            // arrange
            var serviceProvider = ServiceCreator.CreateServiceCollection();
            var transactionRepo = serviceProvider.GetService <ITransactionRepository>();
            var securityRepo    = serviceProvider.GetService <ISecurityRepository>();
            var portfolioRepo   = serviceProvider.GetService <IPortfolioRepository>();

            TransactionService transactionService = new TransactionService(transactionRepo, securityRepo, portfolioRepo);

            var sqlExecutor = new SqlExecutor();

            var portfolio = new Portfolio()
            {
                PortfolioName = Guid.NewGuid().ToString().Substring(1, 6)
            };

            // insert portfolio
            string sql = $"INSERT INTO Portfolio (PortfolioName) VALUES ({portfolio.PortfolioName})";

            portfolio.Id = (int)sqlExecutor.ExecuteScalar(sql);

            var transaction = new Transaction()
            {
                Action      = "Buy",
                Amount      = 200,
                Date        = DateTime.UtcNow,
                Description = "test",
                Fees        = 0,
                PortfolioId = portfolio.Id,
                Price       = 20,
                Quantity    = 10,
                Symbol      = "HD"
            };

            // act
            var result = await transactionService.AddTransactionAsync(transaction, portfolio.Id);

            // assert
            Assert.True(result);
        }