Beispiel #1
0
        public void UpdateClientAccountTest()
        {
            using (var context = new CarRentalDbContext(this.dbContextOptions))
            {
                var service = new ClientAccountService(context);
                ClientAccountModificationParams parameters = new ClientAccountModificationParams
                {
                    ClientId = 1,
                    Email    = "*****@*****.**",
                    FullName = "Update Client",
                    Phone    = "+12345",
                };

                var clientAccountModel = service.Update(parameters);

                Assert.AreEqual(parameters.Email, clientAccountModel.Email);
                Assert.AreEqual(parameters.Phone, clientAccountModel.Phone);
                Assert.AreEqual(parameters.FullName, clientAccountModel.FullName);
                Assert.AreEqual(parameters.ClientId, clientAccountModel.ClientId);

                try
                {
                    service.Update(null);
                    Assert.Fail();
                }
                catch (InvalidParameterException)
                {
                }
                catch
                {
                    Assert.Fail();
                }

                try
                {
                    service.Update(new ClientAccountModificationParams()
                    {
                        ClientId = 1000,
                        Email    = "*****@*****.**",
                        FullName = "Update Client",
                        Phone    = "+12345",
                    });
                    Assert.Fail();
                }
                catch (NotFoundException)
                {
                }
                catch
                {
                    Assert.Fail();
                }
            }
        }
Beispiel #2
0
        public PurchaseDTO Pay(int clientId, int purchaseId)
        {
            ClientService.CheckCredentials(clientId);
            Purchase purchase = PurchaseService.FindEntity(purchaseId);

            if (purchase.PayingTime != null)
            {
                throw new AppException("Already payed", 400);
            }
            decimal       amount = purchase.Amount;
            ClientAccount source = ClientService.GetAccount(clientId);

            if (amount > source.Balance)
            {
                throw new AppException("Not enough money", 400);
            }
            TraderAccount target = TraderService.GetAccount(purchase.CommercialLink.TraderId);

            PaymentMonitor.Remove(purchaseId);
            source.Balance     -= amount;
            target.Balance     += amount;
            purchase.PayingTime = DateTime.Now;
            ClientAccountService.Update(source);
            TraderAccountService.Update(target);
            purchase = PurchaseService.Update(purchase);
            return(PurchaseService.EntityToDTO(purchase));
        }