public void SuccessTest()
        {
            var service = new TransactionService();

            var from = new Account(new decimal(1000.50), "Jonas Dixon");
            var to   = new Account(500, "Owen Moss");

            var transaction_1 = new BankTransaction(1, from, to, 250);
            var transaction_2 = new BankTransaction(2, from, to, 250);
            var transaction_3 = new BankTransaction(3, from, to, 250);
            var transaction_4 = new BankTransaction(4, from, to, 250);

            service.AddTransaction(transaction_1);
            service.AddTransaction(transaction_2);
            service.AddTransaction(transaction_3);
            service.AddTransaction(transaction_4);

            if (service.HasTransactionsForExecuting)
            {
                service.ExecuteTransactions();
            }

            Assert.AreEqual(new decimal(0.50), from.Balance);
            Assert.AreEqual(1500, to.Balance);
        }
        public void NotEnoughtMoneyTest()
        {
            var service = new TransactionService();

            var from = new Account(new decimal(1000.50), "Jonas Dixon");
            var to   = new Account(500, "Owen Moss");

            var transaction_1 = new BankTransaction(1, from, to, 250);
            var transaction_2 = new BankTransaction(2, from, to, 1250);

            service.AddTransaction(transaction_1);
            service.AddTransaction(transaction_2);

            if (service.HasTransactionsForExecuting)
            {
                service.ExecuteTransactions();
            }

            Assert.AreEqual(new decimal(750.50), from.Balance);
            Assert.AreEqual(750, to.Balance);

            Assert.IsTrue(service.HasTransactionsForExecuting);

            if (service.HasTransactionsForExecuting)
            {
                service.ExecuteTransactions();
            }

            Assert.AreEqual(new decimal(750.50), from.Balance);
            Assert.AreEqual(750, to.Balance);
        }
예제 #3
0
        public async Task <ResponseModel> LogIn([FromBody] LogIn request)
        {
            if (!ModelState.IsValid)
            {
                return(Response(400, null, INVALID_PARAMETER));
            }
            var user = await userService.GetUserByEmail(request.Email);

            // check user is exist
            if (user == null)
            {
                return(Response(400, null, "Email not found."));
            }
            // check password is valid
            if (!HashUtility.PasswordIsValid(request.Password.Trim().ToLower(), user))
            {
                return(Response(400, null, "Password is invalid."));
            }
            // add transaction for login type
            await transactionService.AddTransaction(new Transaction()
            {
                UserId = user.Id, Type = TransactionType.SIGNIN
            });

            // valid login
            return(Response(200, new ResponseData()
            {
                data = new { id = user.Id }, statusMessage = "Login success."
            }));
        }
        public void RollbackTest()
        {
            var service = new TransactionService();

            var from = new Account(new decimal(1000.50), "Jonas Dixon");
            var to   = new Account(500, "Owen Moss");

            var transaction_1 = new BankTransaction(1, from, to, 200);
            var transaction_2 = new BankTransaction(2, from, to, 300);
            var transaction_3 = new BankTransaction(2, from, to, 400);

            service.AddTransaction(transaction_1);
            service.AddTransaction(transaction_2);
            service.AddTransaction(transaction_3);

            if (service.HasTransactionsForExecuting)
            {
                service.ExecuteTransactions();
            }

            Assert.AreEqual(new decimal(100.50), from.Balance);
            Assert.AreEqual(1400, to.Balance);
            Assert.IsFalse(service.HasTransactionsForExecuting);

            service.RollbackTransaction(2);

            Assert.AreEqual(new decimal(400.50), from.Balance);
            Assert.AreEqual(1100, to.Balance);
        }
예제 #5
0
        public void Create_Transaction()
        {
            // Act
            transactionService.AddTransaction(transactionDto);

            // Assert
            unitOfWorkMock.Verify(uow => uow.TransactionHistory.Create(It.IsAny <TransactionHistory>()), Times.Once);
        }
예제 #6
0
        static void addTransactionWithClient()
        {
            // Hay que depurar esta función, no funciona bien cuando se pasa el identificador del cliente,
            // está creando un nuevo cliente aunque le pasemos el identificador de uno ya existente

            Paymill.ApiKey = Properties.Settings.Default.ApiKey;
            Paymill.ApiUrl = Properties.Settings.Default.ApiUrl;
            TransactionService transactionService = Paymill.GetService <TransactionService>();

            Transaction transaction = new Transaction();

            transaction.Amount      = 8000;
            transaction.Currency    = "EUR";
            transaction.Description = "Transacción con cliente";
            transaction.Payment     = new Payment()
            {
                Id = "pay_c08f1f94754b93f46ac3"
            };
            transaction.Client = new Client()
            {
                Id = "client_ad591663d69051d306a8"
            };

            Transaction newTransaction = transactionService.AddTransaction(transaction);

            Console.WriteLine("TransactionID:" + newTransaction.Id);
            Console.Read();
        }
예제 #7
0
        public ActionResult AddTransaction(double amount, string description, int vendorId, int cofferId, int accountId)
        {
            Business.Models.TransactionModel model = new Business.Models.TransactionModel {
                Amount = amount, Description = description, VendorId = vendorId, CofferId = cofferId, AccountId = accountId
            };

            transactionService.AddTransaction(model);
            transactionService.ApplySpendingToCoffer(model.CofferId, model.Amount);
            accountService.UpdateAccountBalance(model.AccountId, model.Amount);

            return(null);
        }
예제 #8
0
        public ActionResult Create(Transaction transaction)
        {
            if (ModelState.IsValid)
            {
                _transactionService.AddTransaction(transaction);
                return(RedirectToAction("Index"));
            }

            ViewBag.EmployeeId = new SelectList(_applicationDbContext.Employees, "Id", "Name", transaction.EmployeeId);
            ViewBag.ItemId     = new SelectList(_applicationDbContext.Items, "Id", "ProductName", transaction.ItemId);
            return(View(transaction));
        }
예제 #9
0
        /// <summary>
        /// Add a new transaction between two users.
        /// </summary>
        /// <param name="payload">JSON payload containing the two users and an amount</param>
        /// <returns>The summary for both users after the transaction is completed</returns>
        /// <exception cref="ArgumentException">Thrown when the payload is empty</exception>
        private IEnumerable <UserSummaryResponse> AddTransaction(string payload)
        {
            if (string.IsNullOrWhiteSpace(payload))
            {
                throw new ArgumentException("Empty payload");
            }

            var request = JsonHelper.Deserialize <AddTransactionRequest>(payload);
            var result  = _transactionService.AddTransaction(request.Lender, request.Borrower, request.Amount);

            return(new[] { result.Lender, result.Borrower }
                   .OrderBy(x => x.User)
                   .Select(ToUserSummaryResponse));
        }
예제 #10
0
        public IActionResult Create(TransactionDTO transactionDTO)
        {
            int transactionId;

            if (ModelState.IsValid)
            {
                _transactionService.AddTransaction(transactionDTO, out transactionId);
                return(RedirectToAction("Create", "File", new { transactionId = transactionId }));
            }
            ViewData["PaymentTypeId"]         = new SelectList(_paymentTypeService.GetPaymentTypes(), "Id", "Name", transactionDTO.PaymentTypeId);
            ViewData["TransactionCategoryId"] = new SelectList(_transactionCategoryService.GetTransactionCategories(), "Id", "Name", transactionDTO.TransactionCategoryId);

            return(View(transactionDTO));
            // return RedirectToAction("Create", "Transaction");
        }
예제 #11
0
        public RestApi(string database)
        {
            _transactionService = new TransactionService();

            var data = JsonHelper.Deserialize <IEnumerable <UserSummaryResponse> >(database);

            foreach (var item in data)
            {
                _transactionService.AddUser(item.Name);
                foreach (var(borrower, amount) in item.OwedBy)
                {
                    _transactionService.AddTransaction(item.Name, borrower, amount);
                }
            }
        }
        public void AddTransaction_Transaction_SuccessResponseWithTransaction()
        {
            // Arrange
            var transaction = new Transaction
            {
                Sender    = "4c9395c5-07d9-42c2-9fe9-19478b312acf",
                Recipient = "75f05331-a972-4fa5-b095-0672a8f2c537",
                Amount    = 100,
                Fee       = 2
            };

            // Act
            var result = _transactionService.AddTransaction(transaction) as SuccessResponse <Transaction>;

            // Assert
            _miningQueueMock.Verify(p => p.EnqueueTask(It.IsAny <Func <CancellationToken, Task> >()), Times.Never);

            Assert.NotNull(result);
            Assert.NotNull(result.Message);
            Assert.NotNull(result.Result);
            Assert.NotNull(result.Result.Id);
            Assert.Equal(transaction, result.Result);
            Assert.Equal("The transaction has been added to pending list", result.Message);
        }
예제 #13
0
        static void addTransaction()
        {
            Paymill.ApiKey = Properties.Settings.Default.ApiKey;
            Paymill.ApiUrl = Properties.Settings.Default.ApiUrl;
            TransactionService transactionService = Paymill.GetService <TransactionService>();

            Transaction transaction = new Transaction();

            transaction.Token       = "098f6bcd4621d373cade4e832627b4f6";
            transaction.Amount      = 3500;
            transaction.Currency    = "EUR";
            transaction.Description = "Prueba desde API c#";

            Transaction newTransaction = transactionService.AddTransaction(transaction);

            Console.WriteLine("TransactionID:" + newTransaction.Id);
            Console.Read();
        }
예제 #14
0
        public void addTransactionTest()
        {
            Transaction transaction = new Transaction
            {
                Deposit    = 123,
                Withdrawal = 0,
                Reference  = "account deposit",
                Date       = DateTime.Now
            };

            var trans = _transactionService.AddTransaction(transaction);

            Assert.IsInstanceOf(typeof(Transaction), trans);
        }
예제 #15
0
        static void addTransactionWithPayment()
        {
            Paymill.ApiKey = Properties.Settings.Default.ApiKey;
            Paymill.ApiUrl = Properties.Settings.Default.ApiUrl;
            TransactionService transactionService = Paymill.GetService <TransactionService>();

            Transaction transaction = new Transaction();

            transaction.Amount      = 3500;
            transaction.Currency    = "EUR";
            transaction.Description = "Prueba desde API c#";
            transaction.Payment     = new Payment()
            {
                Id = "pay_81ec02206e9b9c587513"
            };

            Transaction newTransaction = transactionService.AddTransaction(transaction);

            Console.WriteLine("TransactionID:" + newTransaction.Id);
            Console.Read();
        }
예제 #16
0
 public ActionResult <TransactionModel> Post(Transaction transactionIn)
 {
     _transactionService.AddTransaction(transactionIn);
     return(CreatedAtRoute("GetTransaction", new { id = transactionIn.Id.ToString() }, transactionIn));
 }
예제 #17
0
        public IActionResult ImportFile(IFormFile file)
        {
            PageResultModel mod      = new PageResultModel();
            string          strError = "";

            string fileName = file.FileName;

            List <TransactionModel> trnRead = new List <TransactionModel>();

            try
            {
                //Check Valid File
                ImportFileType fileType;
                fileType = this.CheckFileType(fileName);
                if (fileType == ImportFileType.Invalid)
                {
                    strError = "Invalid file format. (allow only csv, xml)";
                }
                else if (file.Length > this.LimitFileSize)
                {
                    strError = "File is larger than 1 mb.";
                }
                else
                {
                    //Valid file Save to Temp for check later
                    fileName = base.SaveToTemp(this.env.ContentRootPath, file);

                    string fileContent = this.ReadFileToString(file);

                    switch (fileType)
                    {
                    case ImportFileType.CSV:
                        trnRead = new CSVReader().GetTransaction(fileContent, out strError);
                        break;

                    case ImportFileType.XML:
                        trnRead = new XMLReader().GetTransaction(fileContent, out strError);
                        break;
                    }
                }



                if (strError.Length == 0)
                {
                    string logID = new MasterService().AddImportLog(fileName, "", "1", "System");

                    svcTrn.AddTransaction(logID, trnRead);

                    mod.statusCode    = "200";
                    mod.statusMessage = "Success";
                }
                else
                {
                    if (fileType == ImportFileType.Invalid)
                    {
                        mod.statusCode    = "500";
                        mod.statusMessage = "Unknown format";
                    }
                    else
                    {
                        mod.statusCode    = "400";
                        mod.statusMessage = "Bad Request";
                    }

                    new MasterService().AddImportLog(fileName, strError, "0", "System");
                }
            }
            catch (Exception ex)
            {
                mod.statusCode    = "500";
                mod.statusMessage = "Internal Server Error";
                new MasterService().AddImportLog(fileName, ex.Message, "0", "System");
            }


            return(View("~/Views/Home/Index.cshtml", mod));
        }